Class: RallyAPI::RallyCollection
- Inherits:
-
Object
- Object
- RallyAPI::RallyCollection
- Includes:
- Enumerable
- Defined in:
- lib/rally_api/rally_collection.rb
Instance Attribute Summary collapse
-
#results ⇒ Object
(also: #values)
readonly
Returns the value of attribute results.
Instance Method Summary collapse
- #<<(item) ⇒ Object
- #[](index) ⇒ Object
- #each(&block) ⇒ Object (also: #each_value)
- #empty? ⇒ Boolean
- #include?(name) ⇒ Boolean
-
#initialize(results) ⇒ RallyCollection
constructor
A new instance of RallyCollection.
- #length ⇒ Object
- #push(item) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(results) ⇒ RallyCollection
Returns a new instance of RallyCollection.
16 17 18 |
# File 'lib/rally_api/rally_collection.rb', line 16 def initialize(results) @results = results end |
Instance Attribute Details
#results ⇒ Object (readonly) Also known as: values
Returns the value of attribute results.
13 14 15 |
# File 'lib/rally_api/rally_collection.rb', line 13 def results @results end |
Instance Method Details
#<<(item) ⇒ Object
62 63 64 |
# File 'lib/rally_api/rally_collection.rb', line 62 def <<(item) push(item) end |
#[](index) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/rally_api/rally_collection.rb', line 20 def [](index) if (index.kind_of? Fixnum) @results[index] else all = @results.find_all { |object| object.name == index } all.length == 1 ? all[0] : all end end |
#each(&block) ⇒ Object Also known as: each_value
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rally_api/rally_collection.rb', line 29 def each(&block) # check for parameters method so we don't blow up on Ruby 1.8.7 if (block.respond_to?('parameters') && block.parameters.length == 2) @results.each do |record| block.call(record.to_s, record) end else @results.each &block end end |
#empty? ⇒ Boolean
53 54 55 |
# File 'lib/rally_api/rally_collection.rb', line 53 def empty? length == 0 end |
#include?(name) ⇒ Boolean
49 50 51 |
# File 'lib/rally_api/rally_collection.rb', line 49 def include?(name) self[name.to_s] != [] end |
#length ⇒ Object
45 46 47 |
# File 'lib/rally_api/rally_collection.rb', line 45 def length @results.count end |
#push(item) ⇒ Object
57 58 59 60 |
# File 'lib/rally_api/rally_collection.rb', line 57 def push(item) item = RallyObject.new(@rally_rest, item) if item.is_a?(Hash) @results.push(item) end |
#size ⇒ Object
41 42 43 |
# File 'lib/rally_api/rally_collection.rb', line 41 def size length end |