Sha256: 9775a2f13c8484bc01bbc3177027cb5d146ffd844185f2d17802c4e8ac09cb41

Contents?: true

Size: 1.41 KB

Versions: 7

Compression:

Stored size: 1.41 KB

Contents

module Songkickr
  # A class to represent the hash of a Location.
  #
  #   {
  #     "city":{
  #       "displayName":"London",
  #       "country":{
  #         "displayName":"UK"},
  #         "lng":-0.128,
  #         "lat":51.5078
  #       },
  #       "metroArea":{
  #         "uri":"http://www.songkick.com/metro_areas/24426-uk-london",
  #         "displayName":"London",
  #         "country":{  "displayName":"UK" },
  #         "id":24426,
  #         "lng":-0.128,
  #         "lat":51.5078
  #       }
  #     }
  #   }
  #
  # http://www.songkick.com/developer/location-search
  class Location
    attr_accessor :city, :lat, :lng, :metro_area

    # Takes a location hash. Handles the different city hashes from Event and Location
    def initialize(location_hash)
      if location_hash["city"].is_a?(String) # location in Event
        @city = location_hash["city"]
        @lat  = location_hash["lat"]
        @lng  = location_hash["lng"]
      elsif location_hash["city"].is_a?(Hash) # stand-alone Location
        city_hash = location_hash["city"]
        @city = city_hash["displayName"] if city_hash && city_hash["displayName"]
        # some locations have a null lng, lat in city hash, but have non-null in metroArea hash
        @lat  = city_hash["lat"]
        @lng  = city_hash["lng"]
      end

      @metro_area = MetroArea.new location_hash['metroArea'] if location_hash.include? 'metroArea'
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
songkickr-0.5.5 lib/songkickr/location.rb
songkickr-0.5.4 lib/songkickr/location.rb
songkickr-0.5.3 lib/songkickr/location.rb
songkickr-0.5.2 lib/songkickr/location.rb
songkickr-0.5.0 lib/songkickr/location.rb
songkickr-0.4.1 lib/songkickr/location.rb
songkickr-0.4.0 lib/songkickr/location.rb