Class: Ksql::Collection

Inherits:
Struct
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ksql/collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(struct_schema, items) ⇒ Collection

  • Generate a class to fit ksqlDB query returned data

  • Populate the collection

Parameters:

  • struct_schema (Hash)

    Struct Schema definition

  • items (Array)

    Collection rows



16
17
18
19
# File 'lib/ksql/collection.rb', line 16

def initialize(struct_schema, items)
  struct = Ksql.const_set(id_to_struct(struct_schema['queryId']), Class.new(Struct.new(*struct_schema['columnNames'].map { |n| n.downcase.to_sym })))
  self.rows = items.map { |i| struct.new(*i) }
end

Instance Attribute Details

#rowsObject

Returns the value of attribute rows

Returns:

  • (Object)

    the current value of rows



6
7
8
# File 'lib/ksql/collection.rb', line 6

def rows
  @rows
end

Instance Method Details

#each(&block) ⇒ Array

Allow iterations block on Rows

Parameters:

  • &block (Block)

    Block to execute on each row

Returns:

  • (Array)

    Rows enumerable



28
29
30
31
32
# File 'lib/ksql/collection.rb', line 28

def each(&block)
  rows.each do |r|
    yield(r)
  end
end