Class: Person
- Inherits:
-
Object
- Object
- Person
- Defined in:
- lib/r43/person.rb
Overview
Implements a person object from 43 things. Currently only meant to be constructed by a R43::Request object:
require 'r43'
connect = R43::Request.new(<api_key>)
person = connect.get_person('<username>')
Instance Attribute Summary collapse
-
#city ⇒ Object
Returns the value of attribute city.
-
#completed_goals ⇒ Object
Returns the value of attribute completed_goals.
-
#flickr_username ⇒ Object
Returns the value of attribute flickr_username.
-
#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_open_goals ⇒ Object
Returns the value of attribute num_open_goals.
-
#profile_image_url ⇒ Object
Returns the value of attribute profile_image_url.
-
#url ⇒ Object
Returns the value of attribute url.
-
#username ⇒ Object
Returns the value of attribute username.
Class Method Summary collapse
-
.from_xml(xml) ⇒ Object
Builds a Person object from an xml object.
Instance Method Summary collapse
-
#initialize ⇒ Person
constructor
A new instance of Person.
- #initialize_copy(person) ⇒ Object
Constructor Details
#initialize ⇒ Person
Returns a new instance of Person.
18 19 20 21 |
# File 'lib/r43/person.rb', line 18 def initialize() # just to create the object, we'll always feed the attributes in # some other way end |
Instance Attribute Details
#city ⇒ Object
Returns the value of attribute city.
14 15 16 |
# File 'lib/r43/person.rb', line 14 def city @city end |
#completed_goals ⇒ Object
Returns the value of attribute completed_goals.
14 15 16 |
# File 'lib/r43/person.rb', line 14 def completed_goals @completed_goals end |
#flickr_username ⇒ Object
Returns the value of attribute flickr_username.
14 15 16 |
# File 'lib/r43/person.rb', line 14 def flickr_username @flickr_username end |
#goals ⇒ Object
Returns the value of attribute goals.
14 15 16 |
# File 'lib/r43/person.rb', line 14 def goals @goals end |
#link ⇒ Object
Returns the value of attribute link.
14 15 16 |
# File 'lib/r43/person.rb', line 14 def link @link end |
#name ⇒ Object
Returns the value of attribute name.
14 15 16 |
# File 'lib/r43/person.rb', line 14 def name @name end |
#num_open_goals ⇒ Object
Returns the value of attribute num_open_goals.
14 15 16 |
# File 'lib/r43/person.rb', line 14 def num_open_goals @num_open_goals end |
#profile_image_url ⇒ Object
Returns the value of attribute profile_image_url.
14 15 16 |
# File 'lib/r43/person.rb', line 14 def profile_image_url @profile_image_url end |
#url ⇒ Object
Returns the value of attribute url.
14 15 16 |
# File 'lib/r43/person.rb', line 14 def url @url end |
#username ⇒ Object
Returns the value of attribute username.
14 15 16 |
# File 'lib/r43/person.rb', line 14 def username @username end |
Class Method Details
.from_xml(xml) ⇒ Object
Builds a Person object from an xml object. Normally, this is called by the get_person method of an R43::Request object.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/r43/person.rb', line 34 def Person.from_xml(xml) person = Person.new person.username= xml.elements["username"].text person.name= xml.elements["name"].text person.url= xml.elements["url"].text person.num_open_goals= xml.elements["num_open_goals"].text.to_i person.link= xml.elements["link"].attributes["href"] person.flickr_username=xml.elements["flickr_username"].text if xml.elements["flickr_username"] if xml.elements["profile_image_url"] then person.profile_image_url= xml.elements["profile_image_url"].text else person.profile_image_url= "none" end if xml.elements["city"] then xml.elements.each("city") do |element| person.city = City.from_xml(element) end end person.goals = Array.new xml.elements.each("open_goals/goal") do |goal_element| goal = Goal.from_xml(goal_element) person.goals.push(goal) end person.completed_goals = Array.new xml.elements.each("completed_goals/goal") do |goal_element| goal = Goal.from_xml(goal_element) person.completed_goals.push(goal) end person end |
Instance Method Details
#initialize_copy(person) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/r43/person.rb', line 23 def initialize_copy(person) @city = person.city.clone if person.city @goals = person.goals.collect{|goal| goal.clone} @completed_goals = person.completed_goals.collect{|goal| goal.clone} self end |