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



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/timezone/lookup/basic.rb', line 12

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 = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



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

def config
  @config
end

Instance Method Details

#client#get

Returns an instance of the request handler.

Returns:

  • (#get)

    an instance of a request handler



27
28
29
30
31
32
33
34
35
# File 'lib/timezone/lookup/basic.rb', line 27

def client
  # TODO: Remove http_client once on 1.0.0
  @client ||=
    if !config.request_handler.nil?
      config.request_handler.new(config)
    else
      config.http_client.new(config.protocol, config.url)
    end
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:



46
47
48
# File 'lib/timezone/lookup/basic.rb', line 46

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