Class: CassandraCQL::Row

Inherits:
Object
  • Object
show all
Defined in:
lib/cassandra-cql/row.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(row, schema) ⇒ Row

Returns a new instance of Row.



21
22
23
# File 'lib/cassandra-cql/row.rb', line 21

def initialize(row, schema)
  @row, @schema = row, schema
end

Instance Attribute Details

#rowObject (readonly)

Returns the value of attribute row.



19
20
21
# File 'lib/cassandra-cql/row.rb', line 19

def row
  @row
end

Instance Method Details

#[](obj) ⇒ Object



25
26
27
28
29
# File 'lib/cassandra-cql/row.rb', line 25

def [](obj)
  column_index = obj.kind_of?(Fixnum) ? obj : column_names.index(obj)
  return nil if column_index.nil?
  column_values[column_index]
end

#column_namesObject



31
32
33
34
35
# File 'lib/cassandra-cql/row.rb', line 31

def column_names
  @names ||= @row.columns.map do |column|
    ColumnFamily.cast(column.name, @schema.names[column.name])
  end
end

#column_valuesObject



37
38
39
# File 'lib/cassandra-cql/row.rb', line 37

def column_values
  @values ||= @row.columns.map { |column| ColumnFamily.cast(column.value, @schema.values[column.name]) }
end

#columnsObject



41
42
43
# File 'lib/cassandra-cql/row.rb', line 41

def columns
  @row.columns.size
end

#to_aObject



45
46
47
# File 'lib/cassandra-cql/row.rb', line 45

def to_a
  column_values
end

#to_hashObject

TODO: This should be an ordered hash



50
51
52
# File 'lib/cassandra-cql/row.rb', line 50

def to_hash
  Hash[([column_names, column_values]).transpose]
end