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.
13
14
15
16
|
# File 'lib/woody/decorators/brief.rb', line 13
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 ⇒ Object
18
19
20
21
22
|
# File 'lib/woody/decorators/brief.rb', line 18
def brand
@brand ||= Woody::Decorators::Brand.new(
@model.brands.first, @config
)
end
|
#concept_questions ⇒ Object
24
25
26
|
# File 'lib/woody/decorators/brief.rb', line 24
def concept_questions
questions.fetch('concept') { {} }
end
|
#draft? ⇒ Boolean
28
29
30
|
# File 'lib/woody/decorators/brief.rb', line 28
def draft?
status == 'Draft'
end
|
#ended? ⇒ Boolean
32
33
34
35
|
# File 'lib/woody/decorators/brief.rb', line 32
def ended?
@model.status == 'published' &&
DateTime.parse(@model.end_date) < DateTime.now
end
|
#essentials_questions ⇒ Object
37
38
39
|
# File 'lib/woody/decorators/brief.rb', line 37
def essentials_questions
questions.fetch('essentials') { {} }
end
|
#exist? ⇒ Boolean
41
42
43
|
# File 'lib/woody/decorators/brief.rb', line 41
def exist?
!@model.nil?
end
|
45
46
47
|
# File 'lib/woody/decorators/brief.rb', line 45
def formatted_end_date
DateTime.parse(@model.end_date).strftime(DATE_FORMAT)
end
|
#image_exists? ⇒ Boolean
49
50
51
|
# File 'lib/woody/decorators/brief.rb', line 49
def image_exists?
@model.image_exists
end
|
#image_url ⇒ Object
53
54
55
56
57
58
|
# File 'lib/woody/decorators/brief.rb', line 53
def image_url
format(
'%s/%s/brands/campaign_image/%s',
@config.s3_domain, @config.public_s3_bucket, @model.short_hash
)
end
|
#insights_posts ⇒ Object
87
88
89
90
91
|
# File 'lib/woody/decorators/brief.rb', line 87
def insights_posts
@model.insights('posts').map do |post|
Insights::Post.new(post)
end
end
|
#insights_summary(cards) ⇒ Object
93
94
95
96
97
|
# File 'lib/woody/decorators/brief.rb', line 93
def insights_summary(cards)
Insights::Summary.new(
@model.insights('summary'), cards
)
end
|
#public? ⇒ Boolean
83
84
85
|
# File 'lib/woody/decorators/brief.rb', line 83
def public?
@model.type == 'public'
end
|
#reward_total ⇒ Object
60
61
62
63
64
65
66
|
# File 'lib/woody/decorators/brief.rb', line 60
def reward_total
t = @model.rewards.inject(0) do |total, reward|
total + (reward.quantity * reward.amount)
end
return 'SWAG 😎' if t == 0
format('£%d', t)
end
|
#status ⇒ Object
68
69
70
71
72
|
# File 'lib/woody/decorators/brief.rb', line 68
def status
return 'Draft' if @model.status == 'draft' || @model.end_date.nil?
return 'Live' if DateTime.parse(@model.end_date) > DateTime.now
purchased_videos > 0 ? 'Complete' : 'Video Review'
end
|
#time_left ⇒ Object
74
75
76
|
# File 'lib/woody/decorators/brief.rb', line 74
def time_left
Time.diff(DateTime.now, @model.end_date, '%d %H')[:diff]
end
|
#title(truncate: false, size: 15) ⇒ Object
78
79
80
81
|
# File 'lib/woody/decorators/brief.rb', line 78
def title(truncate: false, size: 15)
return @model.title unless @model.title.size >= size && truncate
truncate(@model.title, (size - 3))
end
|