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

#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?Boolean

Returns:

  • (Boolean)


31
32
33
34
# File 'lib/woody/decorators/brief.rb', line 31

def ended?
  @model.status == 'published' &&
    DateTime.parse(@model.end_date) < DateTime.now
end

#essentials_questionsObject



36
37
38
# File 'lib/woody/decorators/brief.rb', line 36

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

#exist?Boolean

Returns:

  • (Boolean)


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

def exist?
  !@model.nil?
end

#formatted_end_dateObject



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

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

#image_exists?Boolean

Returns:

  • (Boolean)


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

def image_exists?
  @model.image_hash
end

#image_urlObject



52
53
54
55
56
57
# File 'lib/woody/decorators/brief.rb', line 52

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, object_id) ⇒ Object



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

def insights_post(yml_config, object_id)
  post = @model.insights('posts').find do |p|
    p['object_id'] == object_id
  end

  return nil unless post

  {
    post: Insights::Hydrator.hydrate(yml_config, post)
  }
end

#insights_posts_list(yml_config) ⇒ Object



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

def insights_posts_list(yml_config)
  {
    posts: Insights::Hydrator.hydrate_array(
      yml_config, @model.insights('posts')
    )
  }
end

#insights_summary(yml_config) ⇒ Object



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

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

#public?Boolean

Returns:

  • (Boolean)


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

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

#reward_totalObject



59
60
61
62
63
64
65
# File 'lib/woody/decorators/brief.rb', line 59

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



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

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



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

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

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



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

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