Sha256: e313e43adeab88c90844e3b3a959b44d252ab43e12cdb2b7bb3b602f3140e795

Contents?: true

Size: 1.35 KB

Versions: 33

Compression:

Stored size: 1.35 KB

Contents

# frozen_string_literal: true

require 'timezone/error'

module Timezone
  module Lookup
    # @abstract Subclass and override {#lookup} to implement
    #   a custom Lookup class.
    class Basic
      attr_reader :config

      # @param config [#protocol, #url, #request_handler] a configuration
      #   object
      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

      # Returns an instance of the request handler.
      #
      # @return [#get] an instance of a request handler
      def client
        config.request_handler.new(config)
      end

      # Returns a timezone name for a given lat, long pair.
      #
      # @param lat [Double] latitude coordinate
      # @param long [Double] longitude coordinate
      # @return [String] the timezone name
      # @return [nil] if the lat, long pair does not resolve to an
      #   actual timezone
      # @raise [Timezone::Error::Base] if an error occurred while
      #   while performing the lookup
      def lookup(_lat, _long)
        raise NoMethodError, 'lookup is not implemented'
      end
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

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