Sha256: d380eb5af4697e4b41ef6ab99ab39f2f8c5fdcbdd3fc8592441814bea733bb9d
Contents?: true
Size: 868 Bytes
Versions: 2
Compression:
Stored size: 868 Bytes
Contents
module CrateRuby class ResultSet include Enumerable attr_reader :rowcount, :duration, :cols # @param [String] Crate result def initialize(result) result = JSON.parse(result) @cols = result['cols'] @rows = result['rows'] @rowcount = result['rowcount'] @duration = result['duration'] end def inspect %Q{#<CrateRuby::ResultSet:#{object_id}>, @rowcount="#{@rowcount}", @duration=#{@duration}>} end def <<(val) @rows << val end def each(&block) @rows.each(&block) nil end def [](val) @rows[val] end # @param [Array] ary Column names to filer on # @return [Array] Filtered rows def select_columns(ary, &block) indexes = ary.map {|col| @cols.index(col)}.compact @rows.map{|r| r.values_at(*indexes)}.each(&block) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
crate_ruby-0.0.2 | lib/crate_ruby/result_set.rb |
crate_ruby-0.0.1 | lib/crate_ruby/result_set.rb |