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



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_identifierObject



88
89
90
# File 'lib/woody/decorators/brief.rb', line 88

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

#concept_questionsObject



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

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

#draft?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/woody/decorators/brief.rb', line 27

def draft?
  status == 'Draft'
end

#ended?(submission = nil) ⇒ Boolean

Returns:

  • (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_questionsObject



45
46
47
# File 'lib/woody/decorators/brief.rb', line 45

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

#exist?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/woody/decorators/brief.rb', line 49

def exist?
  !@model.nil?
end

#formatted_end_dateObject



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

Returns:

  • (Boolean)


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

def image_exists?
  @model.image_hash
end

#image_urlObject



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

Returns:

  • (Boolean)


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

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

#reward_totalObject



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('&pound;%d', t)
end

#statusObject



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_leftObject



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