Class: IActionable::Objects::Progress

Inherits:
IActionableObject show all
Defined in:
lib/iactionable/objects/progress.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from IActionableObject

timestamp_regexp, timestamp_to_seconds

Constructor Details

#initialize(key_values = {}) ⇒ Progress

Returns a new instance of Progress.



11
12
13
14
15
16
17
# File 'lib/iactionable/objects/progress.rb', line 11

def initialize(key_values={})
  super(key_values)
  # convert the miliseconds within the date string to seconds (per ruby)
  # "/Date(1275706032317-0600)/" => "1275706032-0600"
  @original_condition_met_date = @condition_met_date
  @condition_met_date = IActionableObject.timestamp_to_seconds(@condition_met_date) unless @condition_met_date.blank?
end

Instance Attribute Details

#completeObject (readonly)

Returns the value of attribute complete.



9
10
11
# File 'lib/iactionable/objects/progress.rb', line 9

def complete
  @complete
end

#condition_met_dateObject

Returns the value of attribute condition_met_date.



5
6
7
# File 'lib/iactionable/objects/progress.rb', line 5

def condition_met_date
  @condition_met_date
end

#current_valueObject

Returns the value of attribute current_value.



7
8
9
# File 'lib/iactionable/objects/progress.rb', line 7

def current_value
  @current_value
end

#descriptionObject

Returns the value of attribute description.



4
5
6
# File 'lib/iactionable/objects/progress.rb', line 4

def description
  @description
end

#original_condition_met_dateObject

Returns the value of attribute original_condition_met_date.



6
7
8
# File 'lib/iactionable/objects/progress.rb', line 6

def original_condition_met_date
  @original_condition_met_date
end

#required_valueObject

Returns the value of attribute required_value.



8
9
10
# File 'lib/iactionable/objects/progress.rb', line 8

def required_value
  @required_value
end

Instance Method Details

#complete?Boolean

Returns:

  • (Boolean)


19
20
21
22
23
# File 'lib/iactionable/objects/progress.rb', line 19

def complete?
  Integer(@current_value) >= Integer(@required_value)
rescue TypeError => e
  false
end

#percent_completeObject



25
26
27
28
29
# File 'lib/iactionable/objects/progress.rb', line 25

def percent_complete
  Integer(Float(@current_value) / Integer(@required_value) * 100)
rescue TypeError => e
  0
end

#to_hashObject



36
37
38
39
40
41
42
43
# File 'lib/iactionable/objects/progress.rb', line 36

def to_hash
  {
    "Description" => @description,
    "CurrentValue" => @current_value,
    "RequiredValue" => @required_value,
    "ConditionMetDate" => @original_condition_met_date
  }
end