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

#brandObject



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_statusObject



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

def brand_status
  return 'In Development' if @model.status == 'draft' || @model.end_date.nil?
  return 'Live' if is_live?
  'Complete'
end

#brand_status_identifierObject



29
30
31
# File 'lib/woody/decorators/brief.rb', line 29

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

#briefing_section(section_name) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/woody/decorators/brief.rb', line 33

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



58
59
60
# File 'lib/woody/decorators/brief.rb', line 58

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

#creator_seatsObject



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

def creator_seats
  @model.number_of_creators
end

#draft?Boolean

Returns:

  • (Boolean)


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

def draft?
  @model.status == 'draft' || @model.end_date.nil?
end

#ended?(submission = nil) ⇒ Boolean

Returns:

  • (Boolean)


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

def ended?(submission = nil)
  @model.status == 'published' && parsed_end_date < DateTime.now
end

#essentials_questionsObject



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

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

#exist?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/woody/decorators/brief.rb', line 78

def exist?
  !@model.nil?
end

#formatted_end_dateObject



82
83
84
# File 'lib/woody/decorators/brief.rb', line 82

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

#formatted_payment_dateObject



86
87
88
# File 'lib/woody/decorators/brief.rb', line 86

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

#image_exists?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/woody/decorators/brief.rb', line 90

def image_exists?
  @model.image_hash
end

#image_urlObject



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

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

#parsed_end_date(submission = nil) ⇒ Object



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

def parsed_end_date(submission = nil)
  DateTime.parse(@model.end_date)
end

#public?Boolean

Returns:

  • (Boolean)


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

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

#status(submission = nil) ⇒ Object



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

def status(submission = nil)
  return 'Draft' if draft?
  return time_remaining if DateTime.parse(@model.end_date) > DateTime.now
  'Complete'
end

#time_left(submission = nil) ⇒ Object



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

def time_left(submission = nil)
  Time.diff(DateTime.now, @model.end_date, '%d %H')[:diff]
end

#time_remaining(submission = nil) ⇒ Object



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

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

#time_rewardObject



123
124
125
# File 'lib/woody/decorators/brief.rb', line 123

def time_reward
  @model.time_payment_per_creator
end

#time_reward_poolObject



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

def time_reward_pool
  time_reward == nil || creator_seats == nil ? 0 : time_reward * creator_seats
end

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



131
132
133
134
# File 'lib/woody/decorators/brief.rb', line 131

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

#total_reward_poolObject



136
137
138
# File 'lib/woody/decorators/brief.rb', line 136

def total_reward_pool
  time_reward_pool
end

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

Returns:

  • (Boolean)


140
141
142
143
144
145
146
147
148
# File 'lib/woody/decorators/brief.rb', line 140

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



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

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