class Flickrie::Location

Public Class Methods

new(hash) click to toggle source
# File lib/flickrie/objects/location.rb, line 51
def initialize(hash)
  raise ArgumentError if hash.nil?
  @hash = hash
end

Public Instance Methods

[](key) click to toggle source
# File lib/flickrie/objects/location.rb, line 43
def [](key) @hash[key] end
accuracy() click to toggle source

@return [String]

# File lib/flickrie/objects/location.rb, line 13
def accuracy()  @hash['accuracy']  end
context() click to toggle source

@return [Fixnum]

# File lib/flickrie/objects/location.rb, line 15
  def context()   Integer(@hash['context']) rescue nil end

  # Returns a struct with attributes `#name`, `#place_id` and `#woeid`
  #
  # @return [Struct]
  def neighbourhood() new_area('neighbourhood') end
  # Returns a struct with attributes `#name`, `#place_id` and `#woeid`
  #
  # @return [Struct]
  def locality()      new_area('locality')      end
  # Returns a struct with attributes `#name`, `#place_id` and `#woeid`
  #
  # @return [Struct]
  def county()        new_area('county')        end
  # Returns a struct with attributes `#name`, `#place_id` and `#woeid`
  #
  # @return [Struct]
  def region()        new_area('region')        end
  # Returns a struct with attributes `#name`, `#place_id` and `#woeid`
  #
  # @return [Struct]
  def country()       new_area('country')       end

  # @return [String]
  def place_id() @hash['place_id'] end
  # @return [String]
  def woeid()    @hash['woeid']    end

  def [](key) @hash[key] end
  # Returns the raw hash from the response. Useful if something isn't available by methods.
  #
  # @return [Hash]
  def hash() @hash end

  private

  def initialize(hash)
    raise ArgumentError if hash.nil?
    @hash = hash
  end

  def new_area(area_name)
    if @hash[area_name]
      area_class = Class.new(Struct.new(:name, :place_id, :woeid)) do
        def to_s
          name
        end
      end
      info = @hash[area_name]
      area_class.new(info['_content'], info['place_id'], info['woeid'])
    end
  end
end
country() click to toggle source

Returns a struct with attributes ‘#name`, `#place_id` and `#woeid`

@return [Struct]

# File lib/flickrie/objects/location.rb, line 36
def country()       new_area('country')       end
county() click to toggle source

Returns a struct with attributes ‘#name`, `#place_id` and `#woeid`

@return [Struct]

# File lib/flickrie/objects/location.rb, line 28
def county()        new_area('county')        end
hash() click to toggle source

Returns the raw hash from the response. Useful if something isn’t available by methods.

@return [Hash]

# File lib/flickrie/objects/location.rb, line 47
def hash() @hash end
latitude() click to toggle source

@return [Fixnum]

# File lib/flickrie/objects/location.rb, line 9
def latitude()  @hash['latitude']  end
locality() click to toggle source

Returns a struct with attributes ‘#name`, `#place_id` and `#woeid`

@return [Struct]

# File lib/flickrie/objects/location.rb, line 24
def locality()      new_area('locality')      end
longitude() click to toggle source

@return [Fixnum]

# File lib/flickrie/objects/location.rb, line 11
def longitude() @hash['longitude'] end
neighbourhood() click to toggle source

Returns a struct with attributes ‘#name`, `#place_id` and `#woeid`

@return [Struct]

# File lib/flickrie/objects/location.rb, line 20
def neighbourhood() new_area('neighbourhood') end
new_area(area_name) click to toggle source
# File lib/flickrie/objects/location.rb, line 56
def new_area(area_name)
  if @hash[area_name]
    area_class = Class.new(Struct.new(:name, :place_id, :woeid)) do
      def to_s
        name
      end
    end
    info = @hash[area_name]
    area_class.new(info['_content'], info['place_id'], info['woeid'])
  end
end
place_id() click to toggle source

@return [String]

# File lib/flickrie/objects/location.rb, line 39
def place_id() @hash['place_id'] end
region() click to toggle source

Returns a struct with attributes ‘#name`, `#place_id` and `#woeid`

@return [Struct]

# File lib/flickrie/objects/location.rb, line 32
def region()        new_area('region')        end
to_s() click to toggle source
# File lib/flickrie/objects/location.rb, line 59
def to_s
  name
end
woeid() click to toggle source

@return [String]

# File lib/flickrie/objects/location.rb, line 41
def woeid()    @hash['woeid']    end