Class: Woody::Decorators::Brief
- Inherits:
-
Base
- Object
- Base
- Woody::Decorators::Brief
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.
11
12
13
14
|
# File 'lib/woody/decorators/brief.rb', line 11
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
#brand ⇒ Object
16
17
18
19
20
|
# File 'lib/woody/decorators/brief.rb', line 16
def brand
@brand ||= Woody::Decorators::Brand.new(
@model.brands.first, @config
)
end
|
#concept_questions ⇒ Object
22
23
24
|
# File 'lib/woody/decorators/brief.rb', line 22
def concept_questions
questions.fetch('concept') { {} }
end
|
#draft? ⇒ Boolean
26
27
28
|
# File 'lib/woody/decorators/brief.rb', line 26
def draft?
status == 'Draft'
end
|
#ended? ⇒ Boolean
30
31
32
33
|
# File 'lib/woody/decorators/brief.rb', line 30
def ended?
@model.status == 'published' &&
DateTime.parse(@model.end_date) < DateTime.now
end
|
#essentials_questions ⇒ Object
35
36
37
|
# File 'lib/woody/decorators/brief.rb', line 35
def essentials_questions
questions.fetch('essentials') { {} }
end
|
#exist? ⇒ Boolean
39
40
41
|
# File 'lib/woody/decorators/brief.rb', line 39
def exist?
!@model.nil?
end
|
#image_exists? ⇒ Boolean
43
44
45
|
# File 'lib/woody/decorators/brief.rb', line 43
def image_exists?
@model.image_exists
end
|
#image_url ⇒ Object
47
48
49
50
51
52
|
# File 'lib/woody/decorators/brief.rb', line 47
def image_url
format(
'%s/%s/brands/campaign_image/%s',
@config.s3_domain, @config.public_s3_bucket, @model.short_hash
)
end
|
#public? ⇒ Boolean
77
78
79
|
# File 'lib/woody/decorators/brief.rb', line 77
def public?
@model.type == 'public'
end
|
#reward_total ⇒ Object
54
55
56
57
58
59
60
|
# File 'lib/woody/decorators/brief.rb', line 54
def reward_total
t = @model.rewards.inject(0) do |total, reward|
total + (reward.quantity * reward.amount)
end
return 'SWAG 😎' if t == 0
format('£%d', t)
end
|
#status ⇒ Object
62
63
64
65
66
|
# File 'lib/woody/decorators/brief.rb', line 62
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_left ⇒ Object
68
69
70
|
# File 'lib/woody/decorators/brief.rb', line 68
def time_left
Time.diff(DateTime.now, @model.end_date, '%d %H')[:diff]
end
|
#title(truncate: false, size: 15) ⇒ Object
72
73
74
75
|
# File 'lib/woody/decorators/brief.rb', line 72
def title(truncate: false, size: 15)
return @model.title unless @model.title.size >= size && truncate
truncate(@model.title, (size - 3))
end
|