Class: Woody::Decorators::Challenge

Inherits:
Base
  • Object
show all
Defined in:
lib/woody/decorators/challenge.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize, #method_missing

Constructor Details

This class inherits a constructor from Woody::Decorators::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Woody::Decorators::Base

Instance Method Details

#brand_nameObject



10
11
12
# File 'lib/woody/decorators/challenge.rb', line 10

def brand_name
  brand.name
end

#concept_questionsObject



14
15
16
# File 'lib/woody/decorators/challenge.rb', line 14

def concept_questions
  questions.fetch("concept") { {} }
end

#draft?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/woody/decorators/challenge.rb', line 18

def draft?
  status == "Draft"
end

#ended?Boolean

Returns:

  • (Boolean)


22
23
24
25
# File 'lib/woody/decorators/challenge.rb', line 22

def ended?
  @model.status == "published" &&
    DateTime.parse(@model.end_date) < DateTime.now
end

#essentials_questionsObject



27
28
29
# File 'lib/woody/decorators/challenge.rb', line 27

def essentials_questions
  questions.fetch("essentials") { {} }
end

#exist?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/woody/decorators/challenge.rb', line 31

def exist?
  !@model.nil?
end

#public?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/woody/decorators/challenge.rb', line 51

def public?
  @model.type == "public"
end

#reward_totalObject



35
36
37
38
39
# File 'lib/woody/decorators/challenge.rb', line 35

def reward_total
  @model.rewards.inject(0) do |total, reward|
    total + (reward.quantity * reward.amount)
  end
end

#statusObject



41
42
43
44
45
# File 'lib/woody/decorators/challenge.rb', line 41

def status
  return "Draft" if @model.status == "draft"
  return "Live" if DateTime.parse(@model.end_date) > DateTime.now
  purchased_videos > 0 ? "Complete" : "Video Review"
end

#time_leftObject



47
48
49
# File 'lib/woody/decorators/challenge.rb', line 47

def time_left
  Time.diff(DateTime.now, @model.end_date, "%d %H")[:diff]
end