Class: CassandraCQL::Row
- Inherits:
-
Object
- Object
- CassandraCQL::Row
- Defined in:
- lib/cassandra-cql/row.rb
Instance Attribute Summary collapse
-
#row ⇒ Object
readonly
Returns the value of attribute row.
Instance Method Summary collapse
- #[](obj) ⇒ Object
- #column_names ⇒ Object
- #column_values ⇒ Object
- #columns ⇒ Object
-
#initialize(row, schema) ⇒ Row
constructor
A new instance of Row.
- #to_a ⇒ Object
-
#to_hash ⇒ Object
TODO: This should be an ordered hash.
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
#row ⇒ Object (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_names ⇒ Object
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_values ⇒ Object
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 |
#columns ⇒ Object
41 42 43 |
# File 'lib/cassandra-cql/row.rb', line 41 def columns @row.columns.size end |
#to_a ⇒ Object
45 46 47 |
# File 'lib/cassandra-cql/row.rb', line 45 def to_a column_values end |
#to_hash ⇒ Object
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 |