123456789_123456789_123456789_123456789_123456789_

Class: Timezone::Lookup::Test

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Basic
Instance Chain:
self, Basic
Inherits: Timezone::Lookup::Basic
Defined in: lib/timezone/lookup/test.rb

Class Method Summary

Basic - Inherited

Instance Attribute Summary

Basic - Inherited

Instance Method Summary

Basic - Inherited

#client

Returns an instance of the request handler.

#lookup

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

Constructor Details

.new(_config) ⇒ Test

[ GitHub ]

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

def initialize(_config)
  @stubs = {}
  @default_stub = nil
end

Instance Method Details

#default(timezone)

[ GitHub ]

  
# File 'lib/timezone/lookup/test.rb', line 23

def default(timezone)
  @default_stub = timezone
end

#key(lat, long) (private)

[ GitHub ]

  
# File 'lib/timezone/lookup/test.rb', line 35

def key(lat, long)
  "#{lat},#{long}"
end

#lookup(lat, long)

[ GitHub ]

  
# File 'lib/timezone/lookup/test.rb', line 27

def lookup(lat, long)
  @stubs.fetch(key(lat, long)) do
    @default_stub || raise(::Timezone::Error::Test, 'missing stub')
  end
end

#stub(lat, long, timezone)

[ GitHub ]

  
# File 'lib/timezone/lookup/test.rb', line 15

def stub(lat, long, timezone)
  @stubs[key(lat, long)] = timezone
end

#unstub(lat, long)

[ GitHub ]

  
# File 'lib/timezone/lookup/test.rb', line 19

def unstub(lat, long)
  @stubs.delete(key(lat, long))
end