Class: Craigslist::API::Area
- Inherits:
-
Object
- Object
- Craigslist::API::Area
- Defined in:
- lib/craigslist/api/area.rb
Overview
A craigslist area (a city or region), as published by the public reference service.
Defined Under Namespace
Classes: SubArea
Instance Attribute Summary collapse
-
#abbreviation ⇒ Object
readonly
Returns the value of attribute abbreviation.
-
#country ⇒ Object
readonly
Returns the value of attribute country.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#hostname ⇒ Object
readonly
Returns the value of attribute hostname.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#latitude ⇒ Object
readonly
Returns the value of attribute latitude.
-
#longitude ⇒ Object
readonly
Returns the value of attribute longitude.
-
#region ⇒ Object
readonly
Returns the value of attribute region.
-
#short_description ⇒ Object
readonly
Returns the value of attribute short_description.
-
#subareas ⇒ Object
readonly
Returns the value of attribute subareas.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(abbreviation:, description: nil, short_description: nil, hostname: nil, country: nil, region: nil, latitude: nil, longitude: nil, id: nil, subareas: []) ⇒ Area
constructor
A new instance of Area.
- #inspect ⇒ Object
- #subarea(abbreviation) ⇒ SubArea?
-
#subareas? ⇒ Boolean
Whether a subarea must be supplied when posting here.
- #to_s ⇒ Object
Constructor Details
#initialize(abbreviation:, description: nil, short_description: nil, hostname: nil, country: nil, region: nil, latitude: nil, longitude: nil, id: nil, subareas: []) ⇒ Area
Returns a new instance of Area.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/craigslist/api/area.rb', line 44 def initialize(abbreviation:, description: nil, short_description: nil, hostname: nil, country: nil, region: nil, latitude: nil, longitude: nil, id: nil, subareas: []) @abbreviation = abbreviation @description = description @short_description = short_description @hostname = hostname @country = country @region = region @latitude = latitude @longitude = longitude @id = id @subareas = .freeze freeze end |
Instance Attribute Details
#abbreviation ⇒ Object (readonly)
Returns the value of attribute abbreviation.
41 42 43 |
# File 'lib/craigslist/api/area.rb', line 41 def abbreviation @abbreviation end |
#country ⇒ Object (readonly)
Returns the value of attribute country.
41 42 43 |
# File 'lib/craigslist/api/area.rb', line 41 def country @country end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
41 42 43 |
# File 'lib/craigslist/api/area.rb', line 41 def description @description end |
#hostname ⇒ Object (readonly)
Returns the value of attribute hostname.
41 42 43 |
# File 'lib/craigslist/api/area.rb', line 41 def hostname @hostname end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
41 42 43 |
# File 'lib/craigslist/api/area.rb', line 41 def id @id end |
#latitude ⇒ Object (readonly)
Returns the value of attribute latitude.
41 42 43 |
# File 'lib/craigslist/api/area.rb', line 41 def latitude @latitude end |
#longitude ⇒ Object (readonly)
Returns the value of attribute longitude.
41 42 43 |
# File 'lib/craigslist/api/area.rb', line 41 def longitude @longitude end |
#region ⇒ Object (readonly)
Returns the value of attribute region.
41 42 43 |
# File 'lib/craigslist/api/area.rb', line 41 def region @region end |
#short_description ⇒ Object (readonly)
Returns the value of attribute short_description.
41 42 43 |
# File 'lib/craigslist/api/area.rb', line 41 def short_description @short_description end |
#subareas ⇒ Object (readonly)
Returns the value of attribute subareas.
41 42 43 |
# File 'lib/craigslist/api/area.rb', line 41 def @subareas end |
Class Method Details
.from(hash) ⇒ Area
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/craigslist/api/area.rb', line 62 def self.from(hash) new( abbreviation: hash["Abbreviation"], description: hash["Description"], short_description: hash["ShortDescription"], hostname: hash["Hostname"], country: hash["Country"], region: hash["Region"], latitude: hash["Latitude"], longitude: hash["Longitude"], id: hash["AreaID"], subareas: Array(hash["SubAreas"]).map { |sub| SubArea.from(sub) } ) end |
Instance Method Details
#inspect ⇒ Object
92 93 94 95 |
# File 'lib/craigslist/api/area.rb', line 92 def inspect "#<#{self.class.name} #{abbreviation.inspect} #{description.inspect} " \ "subareas=#{.size}>" end |
#subarea(abbreviation) ⇒ SubArea?
84 85 86 |
# File 'lib/craigslist/api/area.rb', line 84 def (abbreviation) .find { |sub| sub.abbreviation == abbreviation.to_s } end |
#subareas? ⇒ Boolean
Returns whether a subarea must be supplied when posting here.
78 79 80 |
# File 'lib/craigslist/api/area.rb', line 78 def !.empty? end |
#to_s ⇒ Object
88 89 90 |
# File 'lib/craigslist/api/area.rb', line 88 def to_s abbreviation.to_s end |