Class: CrateRuby::ResultSet
- Inherits:
-
Object
- Object
- CrateRuby::ResultSet
- Includes:
- Enumerable
- Defined in:
- lib/crate_ruby/result_set.rb
Instance Attribute Summary collapse
-
#cols ⇒ Object
readonly
Returns the value of attribute cols.
-
#duration ⇒ Object
readonly
Returns the value of attribute duration.
-
#rowcount ⇒ Object
readonly
Returns the value of attribute rowcount.
Instance Method Summary collapse
- #<<(val) ⇒ Object
- #[](val) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(result) ⇒ ResultSet
constructor
A new instance of ResultSet.
- #inspect ⇒ Object
-
#select_columns(ary, &block) ⇒ Array
Filtered rows.
-
#values ⇒ Array
Returns all rows as Array of arrays.
Constructor Details
#initialize(result) ⇒ ResultSet
Returns a new instance of ResultSet.
28 29 30 31 32 33 34 |
# File 'lib/crate_ruby/result_set.rb', line 28 def initialize(result) result = JSON.parse(result) @cols = result['cols'] @rows = result['rows'] @rowcount = result['rowcount'] @duration = result['duration'] end |
Instance Attribute Details
#cols ⇒ Object (readonly)
Returns the value of attribute cols.
25 26 27 |
# File 'lib/crate_ruby/result_set.rb', line 25 def cols @cols end |
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
25 26 27 |
# File 'lib/crate_ruby/result_set.rb', line 25 def duration @duration end |
#rowcount ⇒ Object (readonly)
Returns the value of attribute rowcount.
25 26 27 |
# File 'lib/crate_ruby/result_set.rb', line 25 def rowcount @rowcount end |
Instance Method Details
#<<(val) ⇒ Object
40 41 42 |
# File 'lib/crate_ruby/result_set.rb', line 40 def <<(val) @rows << val end |
#[](val) ⇒ Object
48 49 50 |
# File 'lib/crate_ruby/result_set.rb', line 48 def [](val) @rows[val] end |
#each(&block) ⇒ Object
44 45 46 |
# File 'lib/crate_ruby/result_set.rb', line 44 def each(&block) @rows.each(&block) end |
#inspect ⇒ Object
36 37 38 |
# File 'lib/crate_ruby/result_set.rb', line 36 def inspect %(#<CrateRuby::ResultSet:#{object_id}>, @rowcount="#{@rowcount}", @duration=#{@duration}>) end |
#select_columns(ary, &block) ⇒ Array
Returns Filtered rows.
59 60 61 62 |
# File 'lib/crate_ruby/result_set.rb', line 59 def select_columns(ary, &block) indexes = ary.map { |col| @cols.index(col) }.compact @rows.map { |r| r.values_at(*indexes) }.each(&block) end |
#values ⇒ Array
Returns all rows as Array of arrays
53 54 55 |
# File 'lib/crate_ruby/result_set.rb', line 53 def values @rows end |