Class: City
- Inherits:
-
Object
- Object
- City
- Defined in:
- lib/r43/city.rb
Instance Attribute Summary collapse
-
#city_id ⇒ Object
Returns the value of attribute city_id.
-
#country ⇒ Object
Returns the value of attribute country.
-
#goals ⇒ Object
Returns the value of attribute goals.
-
#link ⇒ Object
Returns the value of attribute link.
-
#name ⇒ Object
Returns the value of attribute name.
-
#num_people ⇒ Object
Returns the value of attribute num_people.
-
#region ⇒ Object
Returns the value of attribute region.
Class Method Summary collapse
-
.from_xml(xml) ⇒ Object
Builds a City object from 43 things.
Instance Method Summary collapse
-
#initialize ⇒ City
constructor
A new instance of City.
- #initialize_copy(city) ⇒ Object
- #to_i ⇒ Object
Constructor Details
#initialize ⇒ City
Returns a new instance of City.
16 17 18 19 |
# File 'lib/r43/city.rb', line 16 def initialize() # just to initialize the object, we'll always feed the attributes # in some other way end |
Instance Attribute Details
#city_id ⇒ Object
Returns the value of attribute city_id.
13 14 15 |
# File 'lib/r43/city.rb', line 13 def city_id @city_id end |
#country ⇒ Object
Returns the value of attribute country.
13 14 15 |
# File 'lib/r43/city.rb', line 13 def country @country end |
#goals ⇒ Object
Returns the value of attribute goals.
13 14 15 |
# File 'lib/r43/city.rb', line 13 def goals @goals end |
#link ⇒ Object
Returns the value of attribute link.
13 14 15 |
# File 'lib/r43/city.rb', line 13 def link @link end |
#name ⇒ Object
Returns the value of attribute name.
13 14 15 |
# File 'lib/r43/city.rb', line 13 def name @name end |
#num_people ⇒ Object
Returns the value of attribute num_people.
13 14 15 |
# File 'lib/r43/city.rb', line 13 def num_people @num_people end |
#region ⇒ Object
Returns the value of attribute region.
13 14 15 |
# File 'lib/r43/city.rb', line 13 def region @region end |
Class Method Details
.from_xml(xml) ⇒ Object
Builds a City object from 43 things. Currently only meant to constructed by an R43::Request object.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/r43/city.rb', line 34 def City.from_xml(xml) city = City.new() city.name= xml.elements["name"].text city.region= xml.elements["region"].text city.country= xml.elements["country"].text city.num_people= xml.elements["num_people"].text.to_i city.link= xml.elements["link"].attributes["href"] city.city_id= xml.attributes["city_id"].to_i city.goals = Array.new xml.elements.each("goal") do |goal_element| goal = Goal.from_xml(goal_element) city.goals.push(goal) end city end |
Instance Method Details
#initialize_copy(city) ⇒ Object
21 22 23 24 |
# File 'lib/r43/city.rb', line 21 def initialize_copy(city) @goals= city.goals.collect{|goal| goal.clone} self end |
#to_i ⇒ Object
26 27 28 |
# File 'lib/r43/city.rb', line 26 def to_i() @city_id end |