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.



13
14
15
16
# File 'lib/woody/decorators/brief.rb', line 13

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



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

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

#concept_questionsObject



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

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

#draft?Boolean

Returns:

  • (Boolean)


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

def draft?
  status == 'Draft'
end

#ended?Boolean

Returns:

  • (Boolean)


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

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

#essentials_questionsObject



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

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

#exist?Boolean

Returns:

  • (Boolean)


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

def exist?
  !@model.nil?
end

#formatted_end_dateObject



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

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

#image_exists?Boolean

Returns:

  • (Boolean)


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

def image_exists?
  @model.image_exists
end

#image_urlObject



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

def image_url
  format(
    '%s/%s/brands/campaign_image/%s',
    @config.s3_domain, @config.public_s3_bucket, @model.short_hash
  )
end

#insights_postsObject



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

def insights_posts
  @model.insights('posts').map do |post|
    Insights::Post.new(post)
  end
end

#insights_summary(cards) ⇒ Object



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

def insights_summary(cards)
  Insights::Summary.new(
    @model.insights('summary'), cards
  )
end

#public?Boolean

Returns:

  • (Boolean)


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

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

#reward_totalObject



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

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



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

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



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

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

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



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

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