Class: Widescreen::Stat
- Inherits:
-
Object
- Object
- Widescreen::Stat
- Defined in:
- lib/widescreen/stat.rb
Instance Attribute Summary collapse
-
#metric ⇒ Object
Returns the value of attribute metric.
-
#time ⇒ Object
Returns the value of attribute time.
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(metric, time, value = 1) ⇒ Stat
constructor
A new instance of Stat.
- #save ⇒ Object
Constructor Details
#initialize(metric, time, value = 1) ⇒ Stat
Returns a new instance of Stat.
5 6 7 8 9 |
# File 'lib/widescreen/stat.rb', line 5 def initialize(metric, time, value = 1) @metric = Widescreen::Metric.find_or_create(metric) @time = time @value = value end |
Instance Attribute Details
#metric ⇒ Object
Returns the value of attribute metric.
3 4 5 |
# File 'lib/widescreen/stat.rb', line 3 def metric @metric end |
#time ⇒ Object
Returns the value of attribute time.
3 4 5 |
# File 'lib/widescreen/stat.rb', line 3 def time @time end |
#value ⇒ Object
Returns the value of attribute value.
3 4 5 |
# File 'lib/widescreen/stat.rb', line 3 def value @value end |
Class Method Details
.add(metric, value = 1) ⇒ Object
15 16 17 |
# File 'lib/widescreen/stat.rb', line 15 def self.add(metric, value = 1) new(metric, Time.now, value).save end |
.find(key) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/widescreen/stat.rb', line 19 def self.find(key) value = Widescreen.redis.get(key) return if value.nil? metric_name, time = key.split(Widescreen::SEPARATOR, 2) new(metric_name, Time.parse(time), value) end |
Instance Method Details
#save ⇒ Object
11 12 13 |
# File 'lib/widescreen/stat.rb', line 11 def save Widescreen.redis.incrby(key, value) end |