Class: Woody::Decorators::Brief

Inherits:
Base
  • Object
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

#bonus_reward_poolObject



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

def bonus_reward_pool
  r = @model.rewards
  r ? r.bonus_payment_pool : 0
end

#brandObject



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

def brand
  @brand ||= Woody::Decorators::Brand.new(
    @model.brands.first, @config
  )
end

#brand_statusObject



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/woody/decorators/brief.rb', line 28

def brand_status
  case @model.category
  when 'brand'
    return 'In Development' if @model.status == 'draft' || @model.end_date.nil?
    return 'Live' if is_live?
    purchased_videos > 0 ? 'Complete' : 'Video Review'
  when 'vidsy', 'squad'
    return 'In Development' if @model.status == 'draft'
    return 'Live'
  end
end

#brand_status_identifierObject



40
41
42
# File 'lib/woody/decorators/brief.rb', line 40

def brand_status_identifier
  brand_status.downcase.gsub(' ', '-')
end

#briefing_section(section_name) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/woody/decorators/brief.rb', line 44

def briefing_section(section_name)
  question_id = case section_name
    when 'snapshot'
      33
    when 'admin'
      34
    when 'summary'
      35
    when 'method'
      36
    when 'inspo_content'
      37
    when 'delivery'
      38
    when 'extra'
      39
  end

  answer = @model.briefing_answers.find do |answer|
    answer.question.id == question_id
  end

  answer.nil? ? '' : answer.value
end

#concept_questionsObject



69
70
71
# File 'lib/woody/decorators/brief.rb', line 69

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

#creator_seatsObject



73
74
75
76
# File 'lib/woody/decorators/brief.rb', line 73

def creator_seats
  r = @model.rewards
  r ? r.creator_seats : 0
end

#draft?Boolean

Returns:

  • (Boolean)


78
79
80
81
82
83
84
85
# File 'lib/woody/decorators/brief.rb', line 78

def draft?
  case @model.category
  when 'brand'
    @model.status == 'draft' || @model.end_date.nil?
  when 'squad', 'vidsy'
    @model.status == 'draft'
  end
end

#ended?(submission = nil) ⇒ Boolean

Returns:

  • (Boolean)


87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/woody/decorators/brief.rb', line 87

def ended?(submission = nil)
  case @model.category
  when 'brand'
    @model.status == 'published' &&
      parsed_end_date < DateTime.now
  when 'vidsy'
    @model.status == 'published' &&
      parsed_end_date(submission) < DateTime.now
  when 'squad'
    false
  end
end

#essentials_questionsObject



100
101
102
# File 'lib/woody/decorators/brief.rb', line 100

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

#exist?Boolean

Returns:

  • (Boolean)


109
110
111
# File 'lib/woody/decorators/brief.rb', line 109

def exist?
  !@model.nil?
end

#expense_reward_poolObject



104
105
106
107
# File 'lib/woody/decorators/brief.rb', line 104

def expense_reward_pool
  r = @model.rewards
  r ? r.expense_payment_pool : 0
end

#formatted_end_dateObject



113
114
115
# File 'lib/woody/decorators/brief.rb', line 113

def formatted_end_date
  DateTime.parse(@model.end_date).strftime(DATE_FORMAT)
end

#formatted_payment_dateObject



117
118
119
# File 'lib/woody/decorators/brief.rb', line 117

def formatted_payment_date
  DateTime.parse(@model.payment_date).strftime(DATE_FORMAT)
end

#image_exists?Boolean

Returns:

  • (Boolean)


121
122
123
# File 'lib/woody/decorators/brief.rb', line 121

def image_exists?
  @model.image_hash
end

#image_urlObject



125
126
127
128
129
130
# File 'lib/woody/decorators/brief.rb', line 125

def image_url
  format(
    '%s/%s/brands/campaign_image/%s_%s',
    @config.app["s3_domain"], @config.app["public_s3_bucket"], @model.short_hash, @model.image_hash
  )
end

#insights_post(yml_config, post_id) ⇒ Object



132
133
134
135
136
137
138
139
140
141
142
# File 'lib/woody/decorators/brief.rb', line 132

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



144
145
146
147
148
149
150
# File 'lib/woody/decorators/brief.rb', line 144

def insights_posts_list(yml_config)
  {
    posts: Insights::Hydrator.hydrate_array(
      yml_config, sorted_posts
    )
  }
end

#insights_summary(yml_config) ⇒ Object



152
153
154
155
156
157
158
# File 'lib/woody/decorators/brief.rb', line 152

def insights_summary(yml_config)
  {
    summary: Insights::Hydrator.hydrate(
      yml_config, @model.insights('summary')
    )
  }
end

#parsed_end_date(submission = nil) ⇒ Object



160
161
162
163
164
165
166
167
168
169
# File 'lib/woody/decorators/brief.rb', line 160

def parsed_end_date(submission = nil)
  case @model.category
  when 'brand'
    DateTime.parse(@model.end_date)
  when 'vidsy'
    DateTime.parse(submission.created_at).advance(hours: @model.duration)
  when 'squad'
    nil
  end
end

#public?Boolean

Returns:

  • (Boolean)


171
172
173
# File 'lib/woody/decorators/brief.rb', line 171

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

#status(submission = nil) ⇒ Object



175
176
177
178
179
180
181
182
183
184
# File 'lib/woody/decorators/brief.rb', line 175

def status(submission = nil)
  case @model.category
  when 'brand'
    brand_category_status
  when 'vidsy'
    vidsy_category_status(submission)
  when 'squad'
    squad_category_status(submission)
  end
end

#time_left(submission = nil) ⇒ Object



186
187
188
189
190
191
192
193
194
# File 'lib/woody/decorators/brief.rb', line 186

def time_left(submission = nil)
  case @model.category
  when 'brand'
    Time.diff(DateTime.now, @model.end_date, '%d %H')[:diff]
  when 'vidsy'
    end_date = DateTime.parse(submission.created_at).advance(hours: @model.duration)
    Time.diff(DateTime.now, end_date, '%d %H')[:diff]
  end
end

#time_remaining(submission = nil) ⇒ Object



196
197
198
# File 'lib/woody/decorators/brief.rb', line 196

def time_remaining(submission = nil)
  format('%s remaining', time_left(submission))
end

#time_rewardObject



200
201
202
203
# File 'lib/woody/decorators/brief.rb', line 200

def time_reward
  r = @model.rewards
  r ? r.time_payment : 0
end

#time_reward_poolObject



205
206
207
208
# File 'lib/woody/decorators/brief.rb', line 205

def time_reward_pool
  r = @model.rewards
  r ? (r.time_payment * r.creator_seats) : 0
end

#title(truncate: false, size: 15) ⇒ Object



210
211
212
213
# File 'lib/woody/decorators/brief.rb', line 210

def title(truncate: false, size: 15)
  return @model.title unless @model.title.size >= size && truncate
  truncate(@model.title, (size - 3))
end

#total_reward_poolObject



215
216
217
# File 'lib/woody/decorators/brief.rb', line 215

def total_reward_pool
  time_reward_pool + bonus_reward_pool
end

#video_has_partner_asset?(video_id, partner = nil) ⇒ Boolean

Returns:

  • (Boolean)


219
220
221
222
223
224
225
226
227
# File 'lib/woody/decorators/brief.rb', line 219

def video_has_partner_asset?(video_id, partner = nil)
  video_partner_assets.each do |vpa|
    if vpa.video_id == video_id
      return vpa if partner.nil? || vpa.partner_name == partner
    end
  end

  nil
end

#video_partner_assets(partner = nil) ⇒ Object



229
230
231
232
233
234
235
# File 'lib/woody/decorators/brief.rb', line 229

def video_partner_assets(partner = nil)
  return fetch_video_partner_assets if partner.nil?

  return fetch_video_partner_assets.select do |vpa|
    vpa.partner_name === partner
  end
end