Class: Goal

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

Overview

Implements a goal object from 43 things. Currently only meant to be constructed by an R43::Request object

require 'r43'
connect = R43::Request.new(<api_key>)
goal = get_goal_by_id(<goal_id>)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGoal

Returns a new instance of Goal.



18
19
20
21
# File 'lib/r43/goal.rb', line 18

def initialize()
  # just to initialize the object, we'll always feed the attributes in
  # some other way
end

Instance Attribute Details

#goal_idObject

Returns the value of attribute goal_id.



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

def goal_id
  @goal_id
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

Returns the value of attribute link.



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

def link
  @link
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#num_registered_peopleObject

Returns the value of attribute num_registered_people.



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

def num_registered_people
  @num_registered_people
end

#num_say_not_worth_itObject

Returns the value of attribute num_say_not_worth_it.



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

def num_say_not_worth_it
  @num_say_not_worth_it
end

#num_say_worth_itObject

Returns the value of attribute num_say_worth_it.



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

def num_say_worth_it
  @num_say_worth_it
end

#num_unregistered_peopleObject

Returns the value of attribute num_unregistered_people.



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

def num_unregistered_people
  @num_unregistered_people
end

#percentage_worth_itObject

Returns the value of attribute percentage_worth_it.



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

def percentage_worth_it
  @percentage_worth_it
end

Returns the value of attribute progress_link.



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

def progress_link
  @progress_link
end

#tagsObject

Returns the value of attribute tags.



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

def tags
  @tags
end

Returns the value of attribute team_link.



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

def team_link
  @team_link
end

Class Method Details

.from_xml(xml) ⇒ Object

Builds a Goal object from an xml object. Normally, this is called by the get_goal_by_id or get_goal_by_name methods of an R43::Request object.



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/goal.rb', line 38

def Goal.from_xml(xml)
  goal = Goal.new()

  goal.goal_id= xml.attributes["goal_id"].to_i
  goal.name=  xml.elements["name"].text
  goal.link= xml.elements["link"].attributes["href"]

  if xml.elements["num_registered_people"] then
    goal.num_registered_people= 
      xml.elements["num_registered_people"].text.to_i
  end

  if xml.elements["num_unregistered_people"] then
    goal.num_unregistered_people= 
      xml.elements["num_unregistered_people"].text.to_i
  end

  if xml.elements["worth_it_data"] then
    goal.num_say_worth_it= 
      xml.elements["worth_it_data"].elements["num_say_worth_it"].text.to_i
    goal.num_say_not_worth_it= 
      xml.elements["worth_it_data"].elements["num_say_not_worth_it"].text.to_i
    goal.percentage_worth_it= 
      xml.elements["worth_it_data"].elements["percentage_worth_it"].text.to_i
  end
  goal.id= Id.from_xml(xml.elements["id"])

  tags = []
  xml.elements.each("tags/tag") do |tag_element| 
    tags.push(Tag.from_xml(tag_element))
  end
  goal.tags= tags

  goal
end

Instance Method Details

#initialize_copy(goal) ⇒ Object



23
24
25
26
27
# File 'lib/r43/goal.rb', line 23

def initialize_copy(goal)
  @tags= goal.tags.collect{|tag| tag.clone}
  @id = goal.id.clone if goal.id
  self
end

#to_iObject



29
30
31
# File 'lib/r43/goal.rb', line 29

def to_i()
  @goal_id
end