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.
12
13
14
15
|
# File 'lib/woody/decorators/brief.rb', line 12
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
17
18
19
20
21
|
# File 'lib/woody/decorators/brief.rb', line 17
def brand
@brand ||= Woody::Decorators::Brand.new(
@model.brands.first, @config
)
end
|
#brand_status ⇒ Object
82
83
84
85
86
|
# File 'lib/woody/decorators/brief.rb', line 82
def brand_status
return 'In Development' if @model.status == 'draft' || @model.end_date.nil?
return 'Live' if is_live?
purchased_videos > 0 ? 'Complete' : 'Video Review'
end
|
#brand_status_identifier ⇒ Object
88
89
90
|
# File 'lib/woody/decorators/brief.rb', line 88
def brand_status_identifier
brand_status.downcase.gsub(' ', '-')
end
|
#concept_questions ⇒ Object
23
24
25
|
# File 'lib/woody/decorators/brief.rb', line 23
def concept_questions
questions.fetch('concept') { {} }
end
|
#draft? ⇒ Boolean
27
28
29
|
# File 'lib/woody/decorators/brief.rb', line 27
def draft?
status == 'Draft'
end
|
#ended?(submission = nil) ⇒ Boolean
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/woody/decorators/brief.rb', line 31
def ended?(submission = nil)
case @model.category
when 'brand'
@model.status == 'published' &&
DateTime.parse(@model.end_date) < DateTime.now
when 'vidsy'
end_date = DateTime.parse(submission.created_at).advance(hours: @model.duration)
@model.status == 'published' &&
end_date < DateTime.now
when 'squad'
false
end
end
|
#essentials_questions ⇒ Object
45
46
47
|
# File 'lib/woody/decorators/brief.rb', line 45
def essentials_questions
questions.fetch('essentials') { {} }
end
|
#exist? ⇒ Boolean
49
50
51
|
# File 'lib/woody/decorators/brief.rb', line 49
def exist?
!@model.nil?
end
|
53
54
55
|
# File 'lib/woody/decorators/brief.rb', line 53
def formatted_end_date
DateTime.parse(@model.end_date).strftime(DATE_FORMAT)
end
|
#image_exists? ⇒ Boolean
57
58
59
|
# File 'lib/woody/decorators/brief.rb', line 57
def image_exists?
@model.image_hash
end
|
#image_url ⇒ Object
61
62
63
64
65
66
|
# File 'lib/woody/decorators/brief.rb', line 61
def image_url
format(
'%s/%s/brands/campaign_image/%s_%s',
@config.s3_domain, @config.public_s3_bucket, @model.short_hash, @model.image_hash
)
end
|
#insights_post(yml_config, post_id) ⇒ Object
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/woody/decorators/brief.rb', line 105
def insights_post(yml_config, post_id)
post = @model.insights('posts').find do |p|
p['post_id'] == post_id
end
return nil unless post
{
post: Insights::Hydrator.hydrate(yml_config, post)
}
end
|
#insights_posts_list(yml_config) ⇒ Object
117
118
119
120
121
122
123
|
# File 'lib/woody/decorators/brief.rb', line 117
def insights_posts_list(yml_config)
{
posts: Insights::Hydrator.hydrate_array(
yml_config, sorted_posts
)
}
end
|
#insights_summary(yml_config) ⇒ Object
125
126
127
128
129
130
131
|
# File 'lib/woody/decorators/brief.rb', line 125
def insights_summary(yml_config)
{
summary: Insights::Hydrator.hydrate(
yml_config, @model.insights('summary')
)
}
end
|
#public? ⇒ Boolean
101
102
103
|
# File 'lib/woody/decorators/brief.rb', line 101
def public?
@model.type == 'public'
end
|
#reward_total ⇒ Object
68
69
70
71
72
73
74
|
# File 'lib/woody/decorators/brief.rb', line 68
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
76
77
78
79
80
|
# File 'lib/woody/decorators/brief.rb', line 76
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
92
93
94
|
# File 'lib/woody/decorators/brief.rb', line 92
def time_left
Time.diff(DateTime.now, @model.end_date, '%d %H')[:diff]
end
|
#title(truncate: false, size: 15) ⇒ Object
96
97
98
99
|
# File 'lib/woody/decorators/brief.rb', line 96
def title(truncate: false, size: 15)
return @model.title unless @model.title.size >= size && truncate
truncate(@model.title, (size - 3))
end
|