Class: Von::Counter
- Inherits:
-
Object
- Object
- Von::Counter
- Defined in:
- lib/von/counter.rb
Instance Method Summary collapse
- #best(unit) ⇒ Object
-
#initialize(field) ⇒ Counter
constructor
A new instance of Counter.
- #per(unit) ⇒ Object
- #this(unit) ⇒ Object (also: #current)
- #to_i ⇒ Object
- #to_s ⇒ Object
- #today ⇒ Object
- #total ⇒ Object
Constructor Details
#initialize(field) ⇒ Counter
Returns a new instance of Counter.
4 5 6 |
# File 'lib/von/counter.rb', line 4 def initialize(field) @field = field.to_sym end |
Instance Method Details
#best(unit) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/von/counter.rb', line 38 def best(unit) periods = Von.config.bests[@field] if !Period.time_unit_exists?(unit) raise ArgumentError, "`#{unit}' is an unknown time unit" else Counters::Best.new(@field, periods).count(unit) end rescue Redis::BaseError => e raise e if Von.config.raise_connection_errors end |
#per(unit) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/von/counter.rb', line 26 def per(unit) periods = Von.config.periods[@field] if !Period.time_unit_exists?(unit) raise ArgumentError, "`#{unit}' is an unknown time unit" else Counters::Period.new(@field, periods).count(unit) end rescue Redis::BaseError => e raise e if Von.config.raise_connection_errors end |
#this(unit) ⇒ Object Also known as: current
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/von/counter.rb', line 50 def this(unit) periods = Von.config.currents[@field] if !Period.time_unit_exists?(unit) raise ArgumentError, "`#{unit}' is an unknown time unit" else Counters::Current.new(@field, periods).count(unit) end rescue Redis::BaseError => e raise e if Von.config.raise_connection_errors end |
#to_i ⇒ Object
14 15 16 17 18 |
# File 'lib/von/counter.rb', line 14 def to_i Counters::Total.new(@field).count rescue Redis::BaseError => e raise e if Von.config.raise_connection_errors end |
#to_s ⇒ Object
8 9 10 11 12 |
# File 'lib/von/counter.rb', line 8 def to_s Counters::Total.new(@field).count.to_s rescue Redis::BaseError => e raise e if Von.config.raise_connection_errors end |