Class: TimeCamp::TaskCollection

Inherits:
ResourceCollection show all
Defined in:
lib/ruby-timecamp/resources/task_collection.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ResourceCollection

#[], #each, #map, #select, #size

Constructor Details

#initialize(response) ⇒ TaskCollection

Returns a new instance of TaskCollection.



3
4
5
6
# File 'lib/ruby-timecamp/resources/task_collection.rb', line 3

def initialize(response)
  filtered_response = response.map{|k, v| v }
  @resources = filtered_response.map{|task| Task.new(task) }
end

Class Method Details

.collection?(response) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
# File 'lib/ruby-timecamp/resources/task_collection.rb', line 12

def self.collection?(response)
  # return true if the response is an array
  # or if all of the keys are strings of digits only
  return response.is_a?(Array) || response.keys.all?{ |key| key.scan(/\D/).blank? }
end

.parse(response) ⇒ Object



8
9
10
# File 'lib/ruby-timecamp/resources/task_collection.rb', line 8

def self.parse(response)
  return TimeCamp::TaskCollection.collection?(response) ? TaskCollection.new(response) : Task.new(response)
end