Class: Exoteric::Counter
- Inherits:
-
Object
- Object
- Exoteric::Counter
- Defined in:
- lib/exoteric/counter.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #count(*counters) ⇒ Object
-
#initialize(options = {}) ⇒ Counter
constructor
A new instance of Counter.
Constructor Details
#initialize(options = {}) ⇒ Counter
Returns a new instance of Counter.
17 18 19 20 |
# File 'lib/exoteric/counter.rb', line 17 def initialize( = {}) @url, @options = [:url], raise ArgumentError, "Site url not specified" if @url.to_s.empty? end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/exoteric/counter.rb', line 6 def @options end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
6 7 8 |
# File 'lib/exoteric/counter.rb', line 6 def url @url end |
Class Method Details
.<<(counter) ⇒ Object
8 9 10 11 |
# File 'lib/exoteric/counter.rb', line 8 def self.<<(counter) send :include, counter counters << counter.id end |
.counters ⇒ Object
13 14 15 |
# File 'lib/exoteric/counter.rb', line 13 def self.counters @counters ||= [] end |
Instance Method Details
#count(*counters) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/exoteric/counter.rb', line 22 def count(*counters) if counters.size == 0 || counters.first == :all counters = self.class.counters end counters.inject({}) do |res, name| res[name] = send("#{name}_count") res end end |