Class: CloudSpokes::Model::Challenge

Inherits:
BaseApi
  • Object
show all
Defined in:
app/models/cloud_spokes/model/challenge.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Challenge

Cleanup up the __r convention – may want to delete this



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/models/cloud_spokes/model/challenge.rb', line 21

def initialize(params={})
  # there has GOT to be some better way to clean this up ...
  params['categories'] = params.delete('challenge_categories__r') if params['challenge_categories__r']
  params['participants'] = params.delete('challenge_participants__r') if params['challenge_participants__r']
  params['community'] = params.delete('community__r') if params['community__r']
  params['terms_of_service'] = params.delete('terms_of_service__r') if params['terms_of_service__r']
  params['challenge_comments'] = params.delete('challenge_comments__r') if params['challenge_comments__r']
  params['challenge_reviewers'] = params.delete('challenge_reviewers__r') if params['challenge_reviewers__r']
  params['challenge_comment_notifiers'] = params.delete('challenge_comment_notifiers__r') if params['challenge_comment_notifiers__r']
  params['challenge_prizes'] = params.delete('challenge_prizes__r') if params['challenge_prizes__r']
  params['assets'] = params.delete('assets__r') if params['assets__r']

  # these fields need extra cleaning as they should only output arrays of strings
  # they also have an awful lot of duplication that can benefit with a bit of refactoring
  params['challenge_reviewers'] = params['challenge_reviewers'].map do |entry|
    entry['member__r']['name']
  end if params['challenge_reviewers']

  params['challenge_comment_notifiers'] = params['challenge_comment_notifiers'].map do |entry|
    entry['member__r']['name']
  end if params['challenge_comment_notifiers']

  params['challenge_prizes'] = params['challenge_prizes'].records.map do |entry|
    { place: entry['place'].to_s, prize: entry['prize'].to_s, points: entry['points'] || '', value: entry['value'] || '' }
  end if params['challenge_prizes']

  # params['assets'] = params['assets'].map do |entry|
  #   entry['filename']
  # end if params['assets']

  super(params)
end

Instance Attribute Details

#additional_infoObject

Returns the value of attribute additional_info.



3
4
5
# File 'app/models/cloud_spokes/model/challenge.rb', line 3

def additional_info
  @additional_info
end

#assetsObject

Returns the value of attribute assets.



3
4
5
# File 'app/models/cloud_spokes/model/challenge.rb', line 3

def assets
  @assets
end

#attributesObject

Returns the value of attribute attributes.



3
4
5
# File 'app/models/cloud_spokes/model/challenge.rb', line 3

def attributes
  @attributes
end

#categoriesObject

TODO: blow up the categories into something useful



92
93
94
# File 'app/models/cloud_spokes/model/challenge.rb', line 92

def categories
  @categories
end

#challenge_comment_notifiersObject

Returns the value of attribute challenge_comment_notifiers.



3
4
5
# File 'app/models/cloud_spokes/model/challenge.rb', line 3

def challenge_comment_notifiers
  @challenge_comment_notifiers
end

#challenge_idObject

Returns the value of attribute challenge_id.



3
4
5
# File 'app/models/cloud_spokes/model/challenge.rb', line 3

def challenge_id
  @challenge_id
end

#challenge_reviewersObject

Returns the value of attribute challenge_reviewers.



3
4
5
# File 'app/models/cloud_spokes/model/challenge.rb', line 3

def challenge_reviewers
  @challenge_reviewers
end

#challenge_typeObject

Returns the value of attribute challenge_type.



3
4
5
# File 'app/models/cloud_spokes/model/challenge.rb', line 3

def challenge_type
  @challenge_type
end

#communityObject

Returns the value of attribute community.



3
4
5
# File 'app/models/cloud_spokes/model/challenge.rb', line 3

def community
  @community
end

#descriptionObject

Returns the value of attribute description.



3
4
5
# File 'app/models/cloud_spokes/model/challenge.rb', line 3

def description
  @description
end

#discussion_boardObject

Returns the value of attribute discussion_board.



3
4
5
# File 'app/models/cloud_spokes/model/challenge.rb', line 3

def discussion_board
  @discussion_board
end

#end_dateObject

Return an object instead of a string



87
88
89
# File 'app/models/cloud_spokes/model/challenge.rb', line 87

def end_date
  @end_date
end

#idObject

Returns the value of attribute id.



3
4
5
# File 'app/models/cloud_spokes/model/challenge.rb', line 3

def id
  @id
end

#is_openObject

Returns the value of attribute is_open.



3
4
5
# File 'app/models/cloud_spokes/model/challenge.rb', line 3

def is_open
  @is_open
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'app/models/cloud_spokes/model/challenge.rb', line 3

def name
  @name
end

#post_reg_infoObject

Returns the value of attribute post_reg_info.



3
4
5
# File 'app/models/cloud_spokes/model/challenge.rb', line 3

def post_reg_info
  @post_reg_info
end

#prize_typeObject

Returns the value of attribute prize_type.



3
4
5
# File 'app/models/cloud_spokes/model/challenge.rb', line 3

def prize_type
  @prize_type
end

#registered_membersObject

Returns the value of attribute registered_members.



3
4
5
# File 'app/models/cloud_spokes/model/challenge.rb', line 3

def registered_members
  @registered_members
end

#release_to_open_sourceObject

Returns the value of attribute release_to_open_source.



3
4
5
# File 'app/models/cloud_spokes/model/challenge.rb', line 3

def release_to_open_source
  @release_to_open_source
end

#requirementsObject

Returns the value of attribute requirements.



3
4
5
# File 'app/models/cloud_spokes/model/challenge.rb', line 3

def requirements
  @requirements
end

#start_dateObject

Return an object instead of a string



82
83
84
# File 'app/models/cloud_spokes/model/challenge.rb', line 82

def start_date
  @start_date
end

#statusObject

Returns the value of attribute status.



3
4
5
# File 'app/models/cloud_spokes/model/challenge.rb', line 3

def status
  @status
end

#submission_detailsObject

Returns the value of attribute submission_details.



3
4
5
# File 'app/models/cloud_spokes/model/challenge.rb', line 3

def submission_details
  @submission_details
end

#top_prizeObject

Returns the value of attribute top_prize.



3
4
5
# File 'app/models/cloud_spokes/model/challenge.rb', line 3

def top_prize
  @top_prize
end

#total_prize_moneyObject

Returns the value of attribute total_prize_money.



3
4
5
# File 'app/models/cloud_spokes/model/challenge.rb', line 3

def total_prize_money
  @total_prize_money
end

#usage_detailsObject

Returns the value of attribute usage_details.



3
4
5
# File 'app/models/cloud_spokes/model/challenge.rb', line 3

def usage_details
  @usage_details
end

#winner_announcedObject

Returns the value of attribute winner_announced.



3
4
5
# File 'app/models/cloud_spokes/model/challenge.rb', line 3

def winner_announced
  @winner_announced
end

Class Method Details

.allObject



72
73
74
# File 'app/models/cloud_spokes/model/challenge.rb', line 72

def self.all
  closed + open
end

.api_endpointObject



54
55
56
# File 'app/models/cloud_spokes/model/challenge.rb', line 54

def self.api_endpoint
  CloudSpokes::APP_CONFIG[:cs_api][:challenges]
end

.closedObject

Returns all the closed challenges



64
65
66
# File 'app/models/cloud_spokes/model/challenge.rb', line 64

def self.closed
  request(:get, 'closed', {}).map {|challenge| CloudSpokes::Model::Challenge.new challenge}
end

.openObject



68
69
70
# File 'app/models/cloud_spokes/model/challenge.rb', line 68

def self.open
  request(:get, '', {}).map {|challenge| CloudSpokes::Model::Challenge.new challenge}
end

.recentObject

Returns all the recent challenges



77
78
79
# File 'app/models/cloud_spokes/model/challenge.rb', line 77

def self.recent
  request(:get, 'recent', {}).map {|challenge| CloudSpokes::Model::Challenge.new challenge}
end

Instance Method Details

#category_namesObject



96
97
98
# File 'app/models/cloud_spokes/model/challenge.rb', line 96

def category_names
  categories.records.map(&:display_name)
end

#community_nameObject



104
105
106
# File 'app/models/cloud_spokes/model/challenge.rb', line 104

def community_name
  community.try(:name)
end

#open?Boolean

Returns:

  • (Boolean)


108
109
110
# File 'app/models/cloud_spokes/model/challenge.rb', line 108

def open?
  @is_open == "true"
end

#release_to_open_source?Boolean

Returns:

  • (Boolean)


112
113
114
# File 'app/models/cloud_spokes/model/challenge.rb', line 112

def release_to_open_source?
  !!@release_to_open_source
end

#to_paramObject

Used for resourceful routes (instead of id)



59
60
61
# File 'app/models/cloud_spokes/model/challenge.rb', line 59

def to_param
  challenge_id
end