Class: Woody::Decorators::Challenge
- Inherits:
-
Base
- Object
- Base
- Woody::Decorators::Challenge
show all
- Defined in:
- lib/woody/decorators/challenge.rb
Instance Method Summary
collapse
Methods inherited from Base
#method_missing
Constructor Details
#initialize(model, config) ⇒ Challenge
Returns a new instance of Challenge.
10
11
12
13
|
# File 'lib/woody/decorators/challenge.rb', line 10
def initialize(model, config)
@config = config
super(model)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Woody::Decorators::Base
Instance Method Details
#brand_name ⇒ Object
15
16
17
|
# File 'lib/woody/decorators/challenge.rb', line 15
def brand_name
brand.name
end
|
#concept_questions ⇒ Object
19
20
21
|
# File 'lib/woody/decorators/challenge.rb', line 19
def concept_questions
questions.fetch('concept') { {} }
end
|
#draft? ⇒ Boolean
23
24
25
|
# File 'lib/woody/decorators/challenge.rb', line 23
def draft?
status == 'Draft'
end
|
#ended? ⇒ Boolean
27
28
29
30
|
# File 'lib/woody/decorators/challenge.rb', line 27
def ended?
@model.status == 'published' &&
DateTime.parse(@model.end_date) < DateTime.now
end
|
#essentials_questions ⇒ Object
32
33
34
|
# File 'lib/woody/decorators/challenge.rb', line 32
def essentials_questions
questions.fetch('essentials') { {} }
end
|
#exist? ⇒ Boolean
36
37
38
|
# File 'lib/woody/decorators/challenge.rb', line 36
def exist?
!@model.nil?
end
|
#image_exists? ⇒ Boolean
40
41
42
|
# File 'lib/woody/decorators/challenge.rb', line 40
def image_exists?
@model.image_exists
end
|
#image_url ⇒ Object
44
45
46
47
48
49
|
# File 'lib/woody/decorators/challenge.rb', line 44
def image_url
format(
'%s/%s/brands/campaign_image/%s',
@config.s3_domain, @config.public_s3_bucket, @model.short_hash
)
end
|
#public? ⇒ Boolean
72
73
74
|
# File 'lib/woody/decorators/challenge.rb', line 72
def public?
@model.type == 'public'
end
|
#reward_total ⇒ Object
51
52
53
54
55
|
# File 'lib/woody/decorators/challenge.rb', line 51
def reward_total
@model.rewards.inject(0) do |total, reward|
total + (reward.quantity * reward.amount)
end
end
|
#status ⇒ Object
57
58
59
60
61
|
# File 'lib/woody/decorators/challenge.rb', line 57
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_left ⇒ Object
63
64
65
|
# File 'lib/woody/decorators/challenge.rb', line 63
def time_left
Time.diff(DateTime.now, @model.end_date, '%d %H')[:diff]
end
|
#title(truncate: false) ⇒ Object
67
68
69
70
|
# File 'lib/woody/decorators/challenge.rb', line 67
def title(truncate: false)
return @model.title unless @model.title.size >= 15 && truncate
truncate(@model.title, 12)
end
|