Module: CA::TableMethods
- Defined in:
- lib/carray/io/table.rb
Instance Attribute Summary collapse
-
#column_names ⇒ Object
Returns the value of attribute column_names.
Instance Method Summary collapse
Instance Attribute Details
#column_names ⇒ Object
Returns the value of attribute column_names.
6 7 8 |
# File 'lib/carray/io/table.rb', line 6 def column_names @column_names end |
Instance Method Details
#column(name) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/carray/io/table.rb', line 22 def column (name) if name.is_a?(Integer) return self[false, name] elsif @column_names case name when Symbol if i = @column_names.index(name) or i = @column_names.index(name.to_s) return self[false, i] end when String if i = @column_names.index(name) or i = @column_names.index(name.intern) return self[false, i] end end end return nil end |
#row(i) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/carray/io/table.rb', line 40 def row (i) keys = @column_names || (0...dim0).to_a output = {} data = self[i, nil] keys.each_with_index do |key, j| output[key] = data[j] end return output end |
#rows(arg) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/carray/io/table.rb', line 50 def rows (arg) table = self[arg, nil].to_ca table.extend(CA::TableMethods) table.column_names = @column_names return table end |
#select ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/carray/io/table.rb', line 57 def select idx = yield(self) case idx.data_type when CA_BOOLEAN idx = idx.where end return rows(+idx) end |