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.
30 31 32 33 34 35 36 |
# File 'lib/crate_ruby/result_set.rb', line 30 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.
27 28 29 |
# File 'lib/crate_ruby/result_set.rb', line 27 def cols @cols end |
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
27 28 29 |
# File 'lib/crate_ruby/result_set.rb', line 27 def duration @duration end |
#rowcount ⇒ Object (readonly)
Returns the value of attribute rowcount.
27 28 29 |
# File 'lib/crate_ruby/result_set.rb', line 27 def rowcount @rowcount end |
Instance Method Details
#<<(val) ⇒ Object
42 43 44 |
# File 'lib/crate_ruby/result_set.rb', line 42 def <<(val) @rows << val end |
#[](val) ⇒ Object
50 51 52 |
# File 'lib/crate_ruby/result_set.rb', line 50 def [](val) @rows[val] end |
#each(&block) ⇒ Object
46 47 48 |
# File 'lib/crate_ruby/result_set.rb', line 46 def each(&block) @rows.each(&block) end |
#inspect ⇒ Object
38 39 40 |
# File 'lib/crate_ruby/result_set.rb', line 38 def inspect %(#<CrateRuby::ResultSet:#{object_id}>, @rowcount="#{@rowcount}", @duration=#{@duration}>) end |
#select_columns(ary, &block) ⇒ Array
Returns Filtered rows.
61 62 63 64 |
# File 'lib/crate_ruby/result_set.rb', line 61 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
55 56 57 |
# File 'lib/crate_ruby/result_set.rb', line 55 def values @rows end |