Class: Woody::Decorators::Brief
- Inherits:
-
Base
- Object
- Base
- Woody::Decorators::Brief
show all
- Defined in:
- lib/woody/decorators/brief.rb
Instance Method Summary
collapse
Methods inherited from Base
#method_missing
Constructor Details
#initialize(model, config) ⇒ Brief
Returns a new instance of Brief.
10
11
12
13
|
# File 'lib/woody/decorators/brief.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/brief.rb', line 15
def brand_name
brand.name
end
|
#concept_questions ⇒ Object
19
20
21
|
# File 'lib/woody/decorators/brief.rb', line 19
def concept_questions
questions.fetch('concept') { {} }
end
|
#draft? ⇒ Boolean
23
24
25
|
# File 'lib/woody/decorators/brief.rb', line 23
def draft?
status == 'Draft'
end
|
#ended? ⇒ Boolean
27
28
29
30
|
# File 'lib/woody/decorators/brief.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/brief.rb', line 32
def essentials_questions
questions.fetch('essentials') { {} }
end
|
#exist? ⇒ Boolean
36
37
38
|
# File 'lib/woody/decorators/brief.rb', line 36
def exist?
!@model.nil?
end
|
#image_exists? ⇒ Boolean
40
41
42
|
# File 'lib/woody/decorators/brief.rb', line 40
def image_exists?
@model.image_exists
end
|
#image_url ⇒ Object
44
45
46
47
48
49
|
# File 'lib/woody/decorators/brief.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
74
75
76
|
# File 'lib/woody/decorators/brief.rb', line 74
def public?
@model.type == 'public'
end
|
#reward_total ⇒ Object
51
52
53
54
55
56
57
|
# File 'lib/woody/decorators/brief.rb', line 51
def reward_total
return 'SWAG 😎' if @model.rewards.empty?
t = @model.rewards.inject(0) do |total, reward|
total + (reward.quantity * reward.amount)
end
format('£%d', t)
end
|
#status ⇒ Object
59
60
61
62
63
|
# File 'lib/woody/decorators/brief.rb', line 59
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
65
66
67
|
# File 'lib/woody/decorators/brief.rb', line 65
def time_left
Time.diff(DateTime.now, @model.end_date, '%d %H')[:diff]
end
|
#title(truncate: false) ⇒ Object
69
70
71
72
|
# File 'lib/woody/decorators/brief.rb', line 69
def title(truncate: false)
return @model.title unless @model.title.size >= 15 && truncate
truncate(@model.title, 12)
end
|