Class: CloudSpokes::Model::Challenge
- Inherits:
-
BaseApi
- Object
- BaseApi
- CloudSpokes::Model::Challenge
- Defined in:
- app/models/cloud_spokes/model/challenge.rb
Instance Attribute Summary collapse
-
#additional_info ⇒ Object
Returns the value of attribute additional_info.
-
#assets ⇒ Object
Returns the value of attribute assets.
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#categories ⇒ Object
TODO: blow up the categories into something useful.
-
#challenge_comment_notifiers ⇒ Object
Returns the value of attribute challenge_comment_notifiers.
-
#challenge_id ⇒ Object
Returns the value of attribute challenge_id.
-
#challenge_reviewers ⇒ Object
Returns the value of attribute challenge_reviewers.
-
#challenge_type ⇒ Object
Returns the value of attribute challenge_type.
-
#community ⇒ Object
Returns the value of attribute community.
-
#description ⇒ Object
Returns the value of attribute description.
-
#discussion_board ⇒ Object
Returns the value of attribute discussion_board.
-
#end_date ⇒ Object
Return an object instead of a string.
-
#id ⇒ Object
Returns the value of attribute id.
-
#is_open ⇒ Object
Returns the value of attribute is_open.
-
#name ⇒ Object
Returns the value of attribute name.
-
#post_reg_info ⇒ Object
Returns the value of attribute post_reg_info.
-
#prize_type ⇒ Object
Returns the value of attribute prize_type.
-
#registered_members ⇒ Object
Returns the value of attribute registered_members.
-
#release_to_open_source ⇒ Object
Returns the value of attribute release_to_open_source.
-
#requirements ⇒ Object
Returns the value of attribute requirements.
-
#start_date ⇒ Object
Return an object instead of a string.
-
#status ⇒ Object
Returns the value of attribute status.
-
#submission_details ⇒ Object
Returns the value of attribute submission_details.
-
#top_prize ⇒ Object
Returns the value of attribute top_prize.
-
#total_prize_money ⇒ Object
Returns the value of attribute total_prize_money.
-
#usage_details ⇒ Object
Returns the value of attribute usage_details.
-
#winner_announced ⇒ Object
Returns the value of attribute winner_announced.
Class Method Summary collapse
- .all ⇒ Object
- .api_endpoint ⇒ Object
-
.closed ⇒ Object
Returns all the closed challenges.
- .open ⇒ Object
-
.recent ⇒ Object
Returns all the recent challenges.
Instance Method Summary collapse
- #category_names ⇒ Object
- #community_name ⇒ Object
-
#initialize(params = {}) ⇒ Challenge
constructor
Cleanup up the __r convention – may want to delete this.
- #open? ⇒ Boolean
- #release_to_open_source? ⇒ Boolean
-
#to_param ⇒ Object
Used for resourceful routes (instead of id).
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_info ⇒ Object
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 |
#assets ⇒ Object
Returns the value of attribute assets.
3 4 5 |
# File 'app/models/cloud_spokes/model/challenge.rb', line 3 def assets @assets end |
#attributes ⇒ Object
Returns the value of attribute attributes.
3 4 5 |
# File 'app/models/cloud_spokes/model/challenge.rb', line 3 def attributes @attributes end |
#categories ⇒ Object
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_notifiers ⇒ Object
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_id ⇒ Object
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_reviewers ⇒ Object
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_type ⇒ Object
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 |
#community ⇒ Object
Returns the value of attribute community.
3 4 5 |
# File 'app/models/cloud_spokes/model/challenge.rb', line 3 def community @community end |
#description ⇒ Object
Returns the value of attribute description.
3 4 5 |
# File 'app/models/cloud_spokes/model/challenge.rb', line 3 def description @description end |
#discussion_board ⇒ Object
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_date ⇒ Object
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 |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'app/models/cloud_spokes/model/challenge.rb', line 3 def id @id end |
#is_open ⇒ Object
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 |
#name ⇒ Object
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_info ⇒ Object
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_type ⇒ Object
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_members ⇒ Object
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_source ⇒ Object
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 |
#requirements ⇒ Object
Returns the value of attribute requirements.
3 4 5 |
# File 'app/models/cloud_spokes/model/challenge.rb', line 3 def requirements @requirements end |
#start_date ⇒ Object
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 |
#status ⇒ Object
Returns the value of attribute status.
3 4 5 |
# File 'app/models/cloud_spokes/model/challenge.rb', line 3 def status @status end |
#submission_details ⇒ Object
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_prize ⇒ Object
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_money ⇒ Object
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_details ⇒ Object
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_announced ⇒ Object
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
.all ⇒ Object
72 73 74 |
# File 'app/models/cloud_spokes/model/challenge.rb', line 72 def self.all closed + open end |
.api_endpoint ⇒ Object
54 55 56 |
# File 'app/models/cloud_spokes/model/challenge.rb', line 54 def self.api_endpoint CloudSpokes::APP_CONFIG[:cs_api][:challenges] end |
.closed ⇒ Object
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 |
.open ⇒ Object
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 |
.recent ⇒ Object
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_names ⇒ Object
96 97 98 |
# File 'app/models/cloud_spokes/model/challenge.rb', line 96 def category_names categories.records.map(&:display_name) end |
#community_name ⇒ Object
104 105 106 |
# File 'app/models/cloud_spokes/model/challenge.rb', line 104 def community_name community.try(:name) end |
#open? ⇒ 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
112 113 114 |
# File 'app/models/cloud_spokes/model/challenge.rb', line 112 def release_to_open_source? !!@release_to_open_source end |
#to_param ⇒ Object
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 |