Sha256: 6470a828c947f063969a0cc93ae4df86b86682b4533a237db7d2431d4b584ac2

Contents?: true

Size: 628 Bytes

Versions: 5

Compression:

Stored size: 628 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 city
        location.try(:city).presence
      end

      protected

      def location
        if !@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

5 entries across 5 versions & 1 rubygems

Version Path
ahoy_matey-1.1.1 lib/ahoy/deckhands/location_deckhand.rb
ahoy_matey-1.1.0 lib/ahoy/deckhands/location_deckhand.rb
ahoy_matey-1.0.2 lib/ahoy/deckhands/location_deckhand.rb
ahoy_matey-1.0.1 lib/ahoy/deckhands/location_deckhand.rb
ahoy_matey-1.0.0 lib/ahoy/deckhands/location_deckhand.rb