Class: Exoteric::Counter

Inherits:
Object
  • Object
show all
Defined in:
lib/exoteric/counter.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Counter

Returns a new instance of Counter.

Raises:

  • (ArgumentError)


17
18
19
20
# File 'lib/exoteric/counter.rb', line 17

def initialize(options = {})
  @url, @options = options[:url], options
  raise ArgumentError, "Site url not specified" if @url.to_s.empty?
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/exoteric/counter.rb', line 6

def options
  @options
end

#urlObject (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

.countersObject



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