Sha256: 9884c49b172979b071f0a12650b38c21f7c728bfaf00e12b412cd3fe19cef774

Contents?: true

Size: 850 Bytes

Versions: 16

Compression:

Stored size: 850 Bytes

Contents

module Ahoy
  module Deckhands
    class LocationDeckhand
      def initialize(ip)
        @ip = ip
      end

      def country
        location.try(:country).presence
      end

      def region
        location.try(:state).presence
      end

      def postal_code
        location.try(:postal_code).presence
      end

      def city
        location.try(:city).presence
      end

      def latitude
        location.try(:latitude).presence
      end

      def longitude
        location.try(:longitude).presence
      end

      protected

      def location
        unless @checked
          @location =
            begin
              Geocoder.search(@ip).first
            rescue => e
              $stderr.puts e.message
              nil
            end
          @checked = true
        end
        @location
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
ahoy_matey-1.6.1 lib/ahoy/deckhands/location_deckhand.rb
ahoy_matey-1.6.0 lib/ahoy/deckhands/location_deckhand.rb
ahoy_matey-1.5.5 lib/ahoy/deckhands/location_deckhand.rb
ahoy_matey-1.5.4 lib/ahoy/deckhands/location_deckhand.rb
ahoy_matey-1.5.3 lib/ahoy/deckhands/location_deckhand.rb
ahoy_matey-1.5.2 lib/ahoy/deckhands/location_deckhand.rb
ahoy_matey-1.5.1 lib/ahoy/deckhands/location_deckhand.rb
ahoy_matey-1.5.0 lib/ahoy/deckhands/location_deckhand.rb
ahoy_matey-1.4.2 lib/ahoy/deckhands/location_deckhand.rb
ahoy_matey-1.4.1 lib/ahoy/deckhands/location_deckhand.rb
ahoy_matey-1.4.0 lib/ahoy/deckhands/location_deckhand.rb
ahoy_matey-1.3.1 lib/ahoy/deckhands/location_deckhand.rb
ahoy_matey-1.3.0 lib/ahoy/deckhands/location_deckhand.rb
ahoy_matey-1.2.2 lib/ahoy/deckhands/location_deckhand.rb
ahoy_matey-1.2.1 lib/ahoy/deckhands/location_deckhand.rb
ahoy_matey-1.2.0 lib/ahoy/deckhands/location_deckhand.rb