Sha256: 304a02cad40e5831e1dee3cbb36b18667667ba7f3795c1de0619435f5e3cb161

Contents?: true

Size: 1.33 KB

Versions: 5

Compression:

Stored size: 1.33 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"]
        # 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 = location_hash['metro_area']
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
songkickr-0.3.1 lib/songkickr/location.rb
songkickr-0.3.0 lib/songkickr/location.rb
songkickr-0.2.2 lib/songkickr/location.rb
songkickr-0.2.1 lib/songkickr/location.rb
songkickr-0.2.0 lib/songkickr/location.rb