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
# File 'lib/woody/decorators/brief.rb', line 28

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_identifierObject



34
35
36
# File 'lib/woody/decorators/brief.rb', line 34

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

#briefing_section(section_name) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/woody/decorators/brief.rb', line 38

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



63
64
65
# File 'lib/woody/decorators/brief.rb', line 63

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

#creator_seatsObject



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

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

#draft?Boolean

Returns:

  • (Boolean)


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

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)


81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/woody/decorators/brief.rb', line 81

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



94
95
96
# File 'lib/woody/decorators/brief.rb', line 94

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

#exist?Boolean

Returns:

  • (Boolean)


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

def exist?
  !@model.nil?
end

#expense_reward_poolObject



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

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

#formatted_end_dateObject



107
108
109
# File 'lib/woody/decorators/brief.rb', line 107

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

#formatted_payment_dateObject



111
112
113
# File 'lib/woody/decorators/brief.rb', line 111

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

#image_exists?Boolean

Returns:

  • (Boolean)


115
116
117
# File 'lib/woody/decorators/brief.rb', line 115

def image_exists?
  @model.image_hash
end

#image_urlObject



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

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



126
127
128
129
130
131
132
133
134
135
136
# File 'lib/woody/decorators/brief.rb', line 126

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



138
139
140
141
142
143
144
# File 'lib/woody/decorators/brief.rb', line 138

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

#insights_summary(yml_config) ⇒ Object



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

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

#parsed_end_date(submission = nil) ⇒ Object



154
155
156
157
158
159
160
161
162
163
# File 'lib/woody/decorators/brief.rb', line 154

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)


165
166
167
# File 'lib/woody/decorators/brief.rb', line 165

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

#status(submission = nil) ⇒ Object



169
170
171
172
173
174
175
176
177
178
# File 'lib/woody/decorators/brief.rb', line 169

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



180
181
182
183
184
185
186
187
188
# File 'lib/woody/decorators/brief.rb', line 180

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



190
191
192
# File 'lib/woody/decorators/brief.rb', line 190

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

#time_rewardObject



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

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

#time_reward_poolObject



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

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

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



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

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

#total_reward_poolObject



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

def total_reward_pool
  time_reward_pool + bonus_reward_pool
end

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

Returns:

  • (Boolean)


213
214
215
216
217
218
219
220
221
# File 'lib/woody/decorators/brief.rb', line 213

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



223
224
225
226
227
228
229
# File 'lib/woody/decorators/brief.rb', line 223

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