Class: Toodledo::Goal
- Inherits:
-
Object
- Object
- Toodledo::Goal
- Defined in:
- lib/toodledo/goal.rb
Overview
A read only representation of a Goal.
Constant Summary collapse
- LIFE_LEVEL =
0
- MEDIUM_LEVEL =
1
- SHORT_LEVEL =
2
- LEVEL_ARRAY =
[ LIFE_LEVEL, MEDIUM_LEVEL, SHORT_LEVEL ]
- NO_GOAL =
Goal.new(0, 0, 0, "No goal")
Instance Attribute Summary collapse
-
#contributes_id ⇒ Object
readonly
Returns the value of attribute contributes_id.
-
#level ⇒ Object
readonly
Returns the value of attribute level.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
-
.parse(session, el) ⇒ Object
Parses a goal from an XML element.
- .valid?(input) ⇒ Boolean
Instance Method Summary collapse
- #contributes ⇒ Object
- #contributes=(parent_goal) ⇒ Object
-
#initialize(id, level, contributes_id, name) ⇒ Goal
constructor
A new instance of Goal.
- #server_id ⇒ Object
- #to_xml ⇒ Object
Constructor Details
#initialize(id, level, contributes_id, name) ⇒ Goal
Returns a new instance of Goal.
25 26 27 28 29 30 31 |
# File 'lib/toodledo/goal.rb', line 25 def initialize(id, level, contributes_id, name) @id = id @level = level @contributes_id = contributes_id @contributes = nil @name = name end |
Instance Attribute Details
#contributes_id ⇒ Object (readonly)
Returns the value of attribute contributes_id.
35 36 37 |
# File 'lib/toodledo/goal.rb', line 35 def contributes_id @contributes_id end |
#level ⇒ Object (readonly)
Returns the value of attribute level.
35 36 37 |
# File 'lib/toodledo/goal.rb', line 35 def level @level end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
35 36 37 |
# File 'lib/toodledo/goal.rb', line 35 def name @name end |
Class Method Details
.parse(session, el) ⇒ Object
Parses a goal from an XML element.
53 54 55 56 57 58 59 60 |
# File 'lib/toodledo/goal.rb', line 53 def self.parse(session, el) id = el.attributes['id'] level = el.attributes['level'].to_i contributes_id = el.attributes['contributes'] name = el.text goal = Goal.new(id, level, contributes_id, name) return goal end |
.valid?(input) ⇒ Boolean
16 17 18 19 20 21 22 23 |
# File 'lib/toodledo/goal.rb', line 16 def self.valid?(input) for level in LEVEL_ARRAY if (level == input) return true end end return false end |
Instance Method Details
#contributes ⇒ Object
37 38 39 40 41 42 |
# File 'lib/toodledo/goal.rb', line 37 def contributes if (@contributes == nil) return NO_GOAL end return @contributes end |
#contributes=(parent_goal) ⇒ Object
44 45 46 |
# File 'lib/toodledo/goal.rb', line 44 def contributes=(parent_goal) @contributes = parent_goal end |
#server_id ⇒ Object
48 49 50 |
# File 'lib/toodledo/goal.rb', line 48 def server_id return @id end |
#to_xml ⇒ Object
62 63 64 |
# File 'lib/toodledo/goal.rb', line 62 def to_xml() return "<goal id=\"#{@id}\" level=\"#{@level}\" contributes=\"#{@contributes_id}\" name=\"#{@name}\">" end |