Class: Badgeville::Reward
- Inherits:
-
Object
- Object
- Badgeville::Reward
- Includes:
- Helpers
- Defined in:
- lib/badgeville/reward.rb
Instance Attribute Summary collapse
-
#active ⇒ Object
Returns the value of attribute active.
-
#definition_id ⇒ Object
Returns the value of attribute definition_id.
-
#earned_at ⇒ Object
Returns the value of attribute earned_at.
-
#hint ⇒ Object
Returns the value of attribute hint.
-
#id ⇒ Object
Returns the value of attribute id.
- #image_url(format = :original) ⇒ Object
-
#message ⇒ Object
Returns the value of attribute message.
-
#name ⇒ Object
Returns the value of attribute name.
-
#tags ⇒ Object
Returns the value of attribute tags.
-
#threshold ⇒ Object
Returns the value of attribute threshold.
-
#verb ⇒ Object
Returns the value of attribute verb.
Instance Method Summary collapse
-
#grayscale_url ⇒ Object
DEPRECATED: Please use
image_url('grayscale')
instead. -
#initialize(json = nil) ⇒ Reward
constructor
example: { “name”: “A Way with Words”, “active_start_at”: null, “image_file_name”: “9fQ2IU6-0.ftbs4fsoogp3c8fr.png”, “data”: { “verb”: “commented”, “threshold”: 2 }, “created_at”: “2011-08-18T22:55:03-07:00”, “image_url”: “s3.amazonaws.com/badgeville-production-reward-definitions/images/original.png?1313733302”, “components”: “["command":"count","comparator":{"$gte":2,"config":{},"where":"verb":"commented","player_id":"%player_id"}]”, “reward_template”: { “message”: “” }, “_id”: “4e4dfab6c47eed727b005c38”, “tags”: null, “id”: “4e4dfab6c47eed727b005c38”, “active_end_at”: null, “type”: “achievement”, “hint”: “Reply to 25 Comments”, “assignable”: false, “allow_duplicates”: false, “site_id”: “4e4d5bf5c47eed25a0000e8f”, “active”: true, “message”: “You won the internet!” }.
Methods included from Helpers
#ensure_array, #property_params
Constructor Details
#initialize(json = nil) ⇒ Reward
example:
{
"name": "A Way with Words",
"active_start_at": null,
"image_file_name": "9fQ2IU6-0.ftbs4fsoogp3c8fr.png",
"data": {
"verb": "commented",
"threshold": 2
},
"created_at": "2011-08-18T22:55:03-07:00",
"image_url": "http://s3.amazonaws.com/badgeville-production-reward-definitions/images/original.png?1313733302",
"components": "[{\"command\":\"count\",\"comparator\":{\"$gte\":2},\"config\":{},\"where\":{\"verb\":\"commented\",\"player_id\":\"%player_id\"}}]",
"reward_template": {
"message": ""
},
"_id": "4e4dfab6c47eed727b005c38",
"tags": null,
"id": "4e4dfab6c47eed727b005c38",
"active_end_at": null,
"type": "achievement",
"hint": "Reply to 25 Comments",
"assignable": false,
"allow_duplicates": false,
"site_id": "4e4d5bf5c47eed25a0000e8f",
"active": true,
"message": "You won the internet!"
}
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/badgeville/reward.rb', line 37 def initialize(json=nil) if json reward_definition = json["definition"] reward_definition ? init_from(reward_definition) : init_from(json) if json.has_key?('user_id') # it's an earned reward for a specific user @earned_at = DateTime.parse(json["created_at"]).to_time @id = json["id"] end end end |
Instance Attribute Details
#active ⇒ Object
Returns the value of attribute active.
5 6 7 |
# File 'lib/badgeville/reward.rb', line 5 def active @active end |
#definition_id ⇒ Object
Returns the value of attribute definition_id.
6 7 8 |
# File 'lib/badgeville/reward.rb', line 6 def definition_id @definition_id end |
#earned_at ⇒ Object
Returns the value of attribute earned_at.
5 6 7 |
# File 'lib/badgeville/reward.rb', line 5 def earned_at @earned_at end |
#hint ⇒ Object
Returns the value of attribute hint.
5 6 7 |
# File 'lib/badgeville/reward.rb', line 5 def hint @hint end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/badgeville/reward.rb', line 5 def id @id end |
#image_url(format = :original) ⇒ Object
48 49 50 |
# File 'lib/badgeville/reward.rb', line 48 def image_url(format = :original) @image_url.sub('original', format.to_s).sub(/^https?:/, '') if @image_url end |
#message ⇒ Object
Returns the value of attribute message.
5 6 7 |
# File 'lib/badgeville/reward.rb', line 5 def @message end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/badgeville/reward.rb', line 5 def name @name end |
#tags ⇒ Object
Returns the value of attribute tags.
6 7 8 |
# File 'lib/badgeville/reward.rb', line 6 def @tags end |
#threshold ⇒ Object
Returns the value of attribute threshold.
6 7 8 |
# File 'lib/badgeville/reward.rb', line 6 def threshold @threshold end |
#verb ⇒ Object
Returns the value of attribute verb.
6 7 8 |
# File 'lib/badgeville/reward.rb', line 6 def verb @verb end |
Instance Method Details
#grayscale_url ⇒ Object
DEPRECATED: Please use image_url('grayscale')
instead.
53 54 55 56 |
# File 'lib/badgeville/reward.rb', line 53 def grayscale_url warn "[DEPRECATION] `grayscale_url` is deprecated. Please use `image_url(:grayscale)` instead." image_url(:grayscale) end |