Class: PocketAPI::Collection
- Inherits:
-
Object
- Object
- PocketAPI::Collection
- Includes:
- Enumerable
- Defined in:
- lib/pocket_api/collection.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(klass, hashes = []) ⇒ Collection
constructor
A new instance of Collection.
- #where(key_value) ⇒ Object
Constructor Details
#initialize(klass, hashes = []) ⇒ Collection
Returns a new instance of Collection.
7 8 9 10 |
# File 'lib/pocket_api/collection.rb', line 7 def initialize(klass, hashes=[]) @klass = klass @data = parse_hashes(hashes) end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
5 6 7 |
# File 'lib/pocket_api/collection.rb', line 5 def data @data end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
4 5 6 |
# File 'lib/pocket_api/collection.rb', line 4 def klass @klass end |
Instance Method Details
#each(&block) ⇒ Object
12 13 14 |
# File 'lib/pocket_api/collection.rb', line 12 def each(&block) @data.each{ |o| block.call(o) } end |
#where(key_value) ⇒ Object
16 17 18 19 20 21 22 |
# 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 |