Class: TimeCamp::EntryCollection

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ResourceCollection

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

Constructor Details

#initialize(response) ⇒ EntryCollection

Returns a new instance of EntryCollection.



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

def initialize(response)
  @resources = response.map{|entry| Entry.new(entry) }
end

Class Method Details

.parse(response) ⇒ Object



11
12
13
14
# File 'lib/ruby-timecamp/resources/entry_collection.rb', line 11

def self.parse(response)
  return EntryCollection.new([]) if response.blank?
  return response.is_a?(Array) ? EntryCollection.new(response) : Entry.new(response)
end

Instance Method Details

#find(entry_id) ⇒ Object



7
8
9
# File 'lib/ruby-timecamp/resources/entry_collection.rb', line 7

def find(entry_id)
  return @resources.select{ |entry| entry.id == entry_id }.try(:first)
end