Class: FluentQuery::Result
- Inherits:
-
Object
- Object
- FluentQuery::Result
- Defined in:
- lib/fluent-query/result.rb
Overview
Represents result wrapper.
Instance Method Summary collapse
- #all ⇒ Object
- #assoc(*specification, &block) ⇒ Object
- #count ⇒ Object
- #each(&block) ⇒ Object
- #free! ⇒ Object (also: #finish!)
-
#initialize(result) ⇒ Result
constructor
A new instance of Result.
- #one ⇒ Object
- #repeat! ⇒ Object
- #single ⇒ Object
Constructor Details
#initialize(result) ⇒ Result
Returns a new instance of Result.
23 24 25 |
# File 'lib/fluent-query/result.rb', line 23 def initialize(result) @_result = result end |
Instance Method Details
#all ⇒ Object
42 43 44 |
# File 'lib/fluent-query/result.rb', line 42 def all @_result.all end |
#assoc(*specification, &block) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/fluent-query/result.rb', line 70 def assoc(*specification, &block) if block.nil? block = Proc::new { |v| v } end specification.map! { |i| i.to_s } length = specification.length result = { } ## if length == 0 raise FluentQuery::Exception::new("Specification must content at least one field name.") elsif length == 1 key = specification.first self.each do |item| result[item[key]] = block.call(item) end else key_1, key_2 = specification self.each do |item| target_1 = item[key_1] target_2 = item[key_2] if not result[target_1] result[target_1] = { } end result[target_1][target_2] = block.call(item) end end return result end |
#count ⇒ Object
132 133 134 |
# File 'lib/fluent-query/result.rb', line 132 def count @_result.count end |
#each(&block) ⇒ Object
113 114 115 116 |
# File 'lib/fluent-query/result.rb', line 113 def each(&block) @_result.each &block self.free! end |
#free! ⇒ Object Also known as: finish!
141 142 143 |
# File 'lib/fluent-query/result.rb', line 141 def free! @_result.free! end |
#one ⇒ Object
51 52 53 |
# File 'lib/fluent-query/result.rb', line 51 def one @_result.one end |
#repeat! ⇒ Object
123 124 125 |
# File 'lib/fluent-query/result.rb', line 123 def repeat! @_result.repeat! end |
#single ⇒ Object
60 61 62 |
# File 'lib/fluent-query/result.rb', line 60 def single @_result.single end |