Class: City

Inherits:
Object
  • Object
show all
Defined in:
lib/r43/city.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCity

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_idObject

Returns the value of attribute city_id.



13
14
15
# File 'lib/r43/city.rb', line 13

def city_id
  @city_id
end

#countryObject

Returns the value of attribute country.



13
14
15
# File 'lib/r43/city.rb', line 13

def country
  @country
end

#goalsObject

Returns the value of attribute goals.



13
14
15
# File 'lib/r43/city.rb', line 13

def goals
  @goals
end

Returns the value of attribute link.



13
14
15
# File 'lib/r43/city.rb', line 13

def link
  @link
end

#nameObject

Returns the value of attribute name.



13
14
15
# File 'lib/r43/city.rb', line 13

def name
  @name
end

#num_peopleObject

Returns the value of attribute num_people.



13
14
15
# File 'lib/r43/city.rb', line 13

def num_people
  @num_people
end

#regionObject

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_iObject



26
27
28
# File 'lib/r43/city.rb', line 26

def to_i()
  @city_id
end