Class: Timezone::Lookup::Basic Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/timezone/lookup/basic.rb

Overview

This class is abstract.

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Basic

Returns a new instance of Basic.

Parameters:

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

    a configuration object



14
15
16
17
18
19
20
21
22
23
24
25
26
# 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

#configObject (readonly)

Returns the value of attribute config.



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

def config
  @config
end

Instance Method Details

#client#get

Returns an instance of the request handler.

Returns:

  • (#get)

    an instance of a request handler



31
32
33
# 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:



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

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