Module: IActionable::Objects::Awardable::InstanceMethods

Defined in:
lib/iactionable/objects/awardable.rb

Instance Method Summary collapse

Instance Method Details

#awardable_hashObject



41
42
43
44
45
46
# File 'lib/iactionable/objects/awardable.rb', line 41

def awardable_hash
  {
    "AwardDate" => @original_award_date,
    "Progress" => @progress.map{|prog| prog.to_hash}
  }
end

#awarded_onObject



36
37
38
39
# File 'lib/iactionable/objects/awardable.rb', line 36

def awarded_on
  # bug in ruby 1.9.2 where Time.strptime does not support seconds-since-epoch format, but DateTime.strptime does, so we'll use that for now
  DateTime.strptime(@award_date, "%s%z") unless @award_date.blank?
end

#complete?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/iactionable/objects/awardable.rb', line 26

def complete?
  @progress.any? && @progress.all?
end

#initialize_awardable(key_values = {}) ⇒ Object



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

def initialize_awardable(key_values={})
  @progress = extract_many_as(key_values, "Progress", IActionable::Objects::Progress)
  # convert the miliseconds within the date string to seconds (per ruby)
  # "/Date(1275706032317-0600)/" => "1275706032-0600"
  @original_award_date = @award_date = key_values.delete("AwardDate")
  @award_date = IActionableObject.timestamp_to_seconds(@award_date) unless @award_date.blank?
end

#percent_completeObject



30
31
32
33
34
# File 'lib/iactionable/objects/awardable.rb', line 30

def percent_complete
  Integer(Float(@progress.select{|p| p.complete?}.size) / @progress.size * 100)
rescue TypeError => e
  0
end