Class: Fabes::Alternative
Instance Attribute Summary collapse
-
#hits ⇒ Object
TODO: move some of these to attr_reader.
-
#id ⇒ Object
TODO: move some of these to attr_reader.
-
#participants ⇒ Object
TODO: move some of these to attr_reader.
-
#payload ⇒ Object
TODO: move some of these to attr_reader.
-
#weight ⇒ Object
TODO: move some of these to attr_reader.
Class Method Summary collapse
Instance Method Summary collapse
- #increment_hits! ⇒ Object
- #increment_participants! ⇒ Object
-
#initialize(payload) ⇒ Alternative
constructor
A new instance of Alternative.
- #update_weight ⇒ Object
Constructor Details
#initialize(payload) ⇒ Alternative
Returns a new instance of Alternative.
6 7 8 9 10 11 12 |
# File 'lib/fabes/alternative.rb', line 6 def initialize(payload) @id = generate_id @weight = 0.0 @participants = 0 @hits = 0 @payload = payload end |
Instance Attribute Details
#hits ⇒ Object
TODO: move some of these to attr_reader
4 5 6 |
# File 'lib/fabes/alternative.rb', line 4 def hits @hits end |
#id ⇒ Object
TODO: move some of these to attr_reader
4 5 6 |
# File 'lib/fabes/alternative.rb', line 4 def id @id end |
#participants ⇒ Object
TODO: move some of these to attr_reader
4 5 6 |
# File 'lib/fabes/alternative.rb', line 4 def participants @participants end |
#payload ⇒ Object
TODO: move some of these to attr_reader
4 5 6 |
# File 'lib/fabes/alternative.rb', line 4 def payload @payload end |
#weight ⇒ Object
TODO: move some of these to attr_reader
4 5 6 |
# File 'lib/fabes/alternative.rb', line 4 def weight @weight end |
Class Method Details
.create_from(data) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/fabes/alternative.rb', line 29 def self.create_from(data) alternative = new(data.delete :payload) data.each do |k, v| alternative.send "#{k}=", v end alternative rescue raise 'Error creating an alternative' end |
Instance Method Details
#increment_hits! ⇒ Object
19 20 21 22 |
# File 'lib/fabes/alternative.rb', line 19 def increment_hits! @hits = @hits.to_i + 1 Fabes.db.increment_hits!(id) end |