Sha256: 141b9bdcac217b6815517798dc506691d955fb79030c57cadae57133c7519b8c

Contents?: true

Size: 776 Bytes

Versions: 29

Compression:

Stored size: 776 Bytes

Contents

# frozen_string_literal: true

require 'timezone/lookup/basic'
require 'timezone/error'

module Timezone
  module Lookup
    # @!visibility private
    class Test < ::Timezone::Lookup::Basic
      def initialize(_config)
        @stubs = {}
        @default_stub = nil
      end

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

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

      def default(timezone)
        @default_stub = timezone
      end

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

      private

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

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
timezone-1.3.28 lib/timezone/lookup/test.rb
timezone-1.3.27 lib/timezone/lookup/test.rb
timezone-1.3.26 lib/timezone/lookup/test.rb
timezone-1.3.25 lib/timezone/lookup/test.rb
timezone-1.3.24 lib/timezone/lookup/test.rb
timezone-1.3.23 lib/timezone/lookup/test.rb
timezone-1.3.22 lib/timezone/lookup/test.rb
timezone-1.3.21 lib/timezone/lookup/test.rb
timezone-1.3.20 lib/timezone/lookup/test.rb
timezone-1.3.19 lib/timezone/lookup/test.rb
timezone-1.3.18 lib/timezone/lookup/test.rb
timezone-1.3.17 lib/timezone/lookup/test.rb
timezone-1.3.16 lib/timezone/lookup/test.rb
timezone-1.3.15 lib/timezone/lookup/test.rb
timezone-1.3.14 lib/timezone/lookup/test.rb
timezone-1.3.13 lib/timezone/lookup/test.rb
timezone-1.3.12 lib/timezone/lookup/test.rb
timezone-1.3.11 lib/timezone/lookup/test.rb
timezone-1.3.10 lib/timezone/lookup/test.rb
timezone-1.3.9 lib/timezone/lookup/test.rb