class PocketAPI::Collection
Attributes
data[RW]
klass[R]
Public Class Methods
new(klass, hashes=[])
click to toggle source
# File lib/pocket_api/collection.rb, line 7 def initialize(klass, hashes=[]) @klass = klass @data = parse_hashes(hashes) end
Public Instance Methods
each(&block)
click to toggle source
# File lib/pocket_api/collection.rb, line 12 def each(&block) @data.each{ |o| block.call(o) } end
where(key_value)
click to toggle source
# File lib/pocket_api/collection.rb, line 16 def where(key_value) key, value = key_value.first raise InvalidAttributeError, "Invalid attribute: #{key}" unless @klass.method_defined? key.to_sym dup_select { |o| o.send(key) == value } end
Private Instance Methods
dup_select(&block)
click to toggle source
# File lib/pocket_api/collection.rb, line 26 def dup_select(&block) dup = self.dup dup.data = select(&block) dup end
parse_hashes(hashes)
click to toggle source
# File lib/pocket_api/collection.rb, line 32 def parse_hashes(hashes) hashes.map { |hash| @klass.new(hash) } end