Class: Rescuetime::Collection
- Inherits:
-
Object
- Object
- Rescuetime::Collection
- Includes:
- Enumerable, QueryBuildable
- Defined in:
- lib/rescuetime/collection.rb
Overview
Represents a potential rescuetime collection. It holds the query information and performs the query lazily, when #all or an Enumerable method is called.
Constant Summary collapse
- HOST =
Rescuetime Analytics API endpoint
'https://www.rescuetime.com/anapi/data'.freeze
Constants included from QueryBuildable
QueryBuildable::BASE_PARAMS, QueryBuildable::VALID
Instance Method Summary collapse
-
#<<(terms) ⇒ Hash
Appends new terms onto the Rescuetime collection.
-
#all ⇒ Array, CSV
Performs the rescuetime query and returns an array or csv response.
-
#each(&block) ⇒ Array, CSV
Enumerates over the collection of Rescuetime report records.
-
#format(format) ⇒ Rescuetime::Collection
Sets the report format to a valid type.
-
#initialize(*terms) ⇒ Rescuetime::Collection
constructor
Returns a new Rescuetime collection.
Methods included from QueryBuildable
#activities, #categories, #date, #efficiency, #from, #order_by, #overview, #productivity, #to, #where
Constructor Details
#initialize(*terms) ⇒ Rescuetime::Collection
Returns a new Rescuetime collection. Default format is array.
22 23 24 25 |
# File 'lib/rescuetime/collection.rb', line 22 def initialize(*terms) @params = terms.reduce({}, :merge) @format = :array end |
Instance Method Details
#<<(terms) ⇒ Hash
Appends new terms onto the Rescuetime collection. In the case of duplicate keys, the later keys overwrite the former keys.
32 33 34 |
# File 'lib/rescuetime/collection.rb', line 32 def <<(terms) @params = params.merge terms end |
#all ⇒ Array, CSV
Performs the rescuetime query and returns an array or csv response.
41 42 43 44 45 |
# File 'lib/rescuetime/collection.rb', line 41 def all requester = Rescuetime::Requester host = HOST parse_response requester.get(host, params) end |
#each(&block) ⇒ Array, CSV
Enumerates over the collection of Rescuetime report records. Performs the query.
54 55 56 |
# File 'lib/rescuetime/collection.rb', line 54 def each(&block) all.each(&block) end |
#format(format) ⇒ Rescuetime::Collection
Sets the report format to a valid type
TODO: make chainable to the client
64 65 66 67 68 69 70 71 |
# File 'lib/rescuetime/collection.rb', line 64 def format(format) # Guard: fail if the passed format isn't on the whitelist format = format.to_s formatters.all.include?(format) || raise(Errors::InvalidFormatError) @format = format self end |