Class: OutsideIn::Location

Inherits:
Base
  • Object
show all
Defined in:
lib/outside_in/location.rb

Overview

Location model class.

Locations have the following attributes:

  • category (Category)

  • city

  • display_name

  • lat (Float)

  • lng (Float)

  • state

  • state_abbrev

  • url

  • url_name

  • uuid (SimpleUUID::UUID)

Location finders accept query parameter options as described by #parameterize_url. They return data structures as described by #query_result.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

api_attr, api_attrs, #initialize

Constructor Details

This class inherits a constructor from OutsideIn::Base

Class Method Details

.named(name, inputs) ⇒ Hash<Symbol, Object>

Returns the locations matching name. See the API docs for specifics regarding matching rules.

Parameters:

  • name (String)

    the name to match

  • inputs (Hash<String, Object>)

    the data inputs

Returns:

  • (Hash<Symbol, Object>)

    the query result

Since:

  • 1.0



35
36
37
# File 'lib/outside_in/location.rb', line 35

def self.named(name, inputs)
  query_result(OutsideIn::Resource::LocationFinder.new("/locations/named/#{URI.escape(name)}").GET(inputs))
end

.query_result(data) ⇒ Hash<Symbol, Object>

Returns a hash encapsulating the data returned from a successful finder query.

The hash contains the following data:

  • :total - the total number of matching locations (may be greater than the number of returned stories)

  • :locations - the array of best matching OutsideIn::Location as per the specified or implied limit

Parameters:

  • data (Hash<String, Object>)

    the raw query result

Returns:

  • (Hash<Symbol, Object>)

Since:

  • 1.0



57
58
59
# File 'lib/outside_in/location.rb', line 57

def self.query_result(data)
  {:total => data['total'], :locations => data['locations'].map {|l| new(l)}}
end

Instance Method Details

#to_sString

Returns the location’s display name and uuid.

Returns:

  • (String)

Since:

  • 1.0



43
44
45
# File 'lib/outside_in/location.rb', line 43

def to_s
  "#{display_name} (#{uuid.to_guid})"
end