Class: Zoid::Resources
- Inherits:
-
Object
- Object
- Zoid::Resources
- Includes:
- Enumerable
- Defined in:
- lib/zoid/resources.rb
Instance Method Summary collapse
- #[](index) ⇒ Object
- #each(&block) ⇒ Object
- #find_by(criteria) ⇒ Object
-
#initialize(resources) ⇒ Resources
constructor
A new instance of Resources.
- #length ⇒ Object
Constructor Details
#initialize(resources) ⇒ Resources
Returns a new instance of Resources.
5 6 7 |
# File 'lib/zoid/resources.rb', line 5 def initialize(resources) @resources = resources end |
Instance Method Details
#[](index) ⇒ Object
20 21 22 |
# File 'lib/zoid/resources.rb', line 20 def [](index) @resources[index] end |
#each(&block) ⇒ Object
16 17 18 |
# File 'lib/zoid/resources.rb', line 16 def each(&block) @resources.each(&block) end |
#find_by(criteria) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/zoid/resources.rb', line 9 def find_by(criteria) key = criteria.keys.first value = criteria[key] @resources.find { |resource| resource.public_send(key) == value } end |
#length ⇒ Object
24 25 26 |
# File 'lib/zoid/resources.rb', line 24 def length @resources.length end |