123456789_123456789_123456789_123456789_123456789_

Class: Timezone::Lookup::Basic Abstract

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Inherits: Object
Defined in: lib/timezone/lookup/basic.rb

Overview

This class is abstract.

Subclass and override #lookup to implement a custom ::Timezone::Lookup class.

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(config) ⇒ Basic

Parameters:

  • config (#protocol, #url, #request_handler)

    a configuration object

[ GitHub ]

  
# File 'lib/timezone/lookup/basic.rb', line 14

def initialize(config)
  if config.protocol.nil?
    raise(::Timezone::Error::InvalidConfig, 'missing protocol')
  end

  if config.url.nil?
    raise(::Timezone::Error::InvalidConfig, 'missing url')
  end

  config.uri ||= URI.parse("#{config.protocol}://#{config.url}")

  @config = config
end

Instance Attribute Details

#config (readonly)

[ GitHub ]

  
# File 'lib/timezone/lookup/basic.rb', line 10

attr_reader :config

Instance Method Details

#client ⇒ #get

Returns an instance of the request handler.

Returns:

  • (#get)

    an instance of a request handler

[ GitHub ]

  
# File 'lib/timezone/lookup/basic.rb', line 31

def client
  config.request_handler.new(config)
end

#lookup(_lat, _long) ⇒ String?

Returns a timezone name for a given lat, long pair.

Parameters:

  • lat (Double)

    latitude coordinate

  • long (Double)

    longitude coordinate

Returns:

  • (String)

    the timezone name

  • (nil)

    if the lat, long pair does not resolve to an actual timezone

Raises:

[ GitHub ]

  
# File 'lib/timezone/lookup/basic.rb', line 44

def lookup(_lat, _long)
  raise NoMethodError, 'lookup is not implemented'
end