Class: Woody::Decorators::Challenge

Inherits:
Base
  • Object
show all
Defined in:
lib/woody/decorators/challenge.rb

Instance Method Summary collapse

Methods inherited from Base

#method_missing

Constructor Details

#initialize(model, config) ⇒ Challenge

Returns a new instance of Challenge.



10
11
12
13
# File 'lib/woody/decorators/challenge.rb', line 10

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_nameObject



15
16
17
# File 'lib/woody/decorators/challenge.rb', line 15

def brand_name
  brand.name
end

#concept_questionsObject



19
20
21
# File 'lib/woody/decorators/challenge.rb', line 19

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

#draft?Boolean

Returns:

  • (Boolean)


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

def draft?
  status == "Draft"
end

#ended?Boolean

Returns:

  • (Boolean)


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

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

#essentials_questionsObject



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

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

#exist?Boolean

Returns:

  • (Boolean)


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

def exist?
  !@model.nil?
end

#image_exists?Boolean

Returns:

  • (Boolean)


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

def image_exists?
  @model.image_exists
end

#image_urlObject



44
45
46
47
48
49
50
51
# File 'lib/woody/decorators/challenge.rb', line 44

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

#public?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/woody/decorators/challenge.rb', line 69

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

#reward_totalObject



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

def reward_total
  @model.rewards.inject(0) do |total, reward|
    total + (reward.quantity * reward.amount)
  end
end

#statusObject



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

def status
  return "Draft" if @model.status == "draft"
  return "Live" if DateTime.parse(@model.end_date) > DateTime.now
  purchased_videos > 0 ? "Complete" : "Video Review"
end

#time_leftObject



65
66
67
# File 'lib/woody/decorators/challenge.rb', line 65

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