Class: Toodledo::Goal

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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_idObject (readonly)

Returns the value of attribute contributes_id.



35
36
37
# File 'lib/toodledo/goal.rb', line 35

def contributes_id
  @contributes_id
end

#levelObject (readonly)

Returns the value of attribute level.



35
36
37
# File 'lib/toodledo/goal.rb', line 35

def level
  @level
end

#nameObject (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

Returns:

  • (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

#contributesObject



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_idObject



48
49
50
# File 'lib/toodledo/goal.rb', line 48

def server_id
  return @id
end

#to_xmlObject



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