Class: Charty::TableAdapters::NMatrixAdapter
- Inherits:
-
Object
- Object
- Charty::TableAdapters::NMatrixAdapter
- Defined in:
- lib/charty/table_adapters/nmatrix_adapter.rb
Instance Attribute Summary collapse
-
#column_names ⇒ Object
readonly
Returns the value of attribute column_names.
Class Method Summary collapse
Instance Method Summary collapse
- #[](row, column) ⇒ Object
-
#initialize(data, columns: nil) ⇒ NMatrixAdapter
constructor
A new instance of NMatrixAdapter.
Constructor Details
#initialize(data, columns: nil) ⇒ NMatrixAdapter
Returns a new instance of NMatrixAdapter.
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/charty/table_adapters/nmatrix_adapter.rb', line 10 def initialize(data, columns: nil) case data.shape.length when 1 data = data.reshape(data.size, 1) when 2 # do nothing else raise ArgumentError, "Unsupported data format" end @data = data @column_names = generate_column_names(data.shape[1], columns) end |
Instance Attribute Details
#column_names ⇒ Object (readonly)
Returns the value of attribute column_names.
23 24 25 |
# File 'lib/charty/table_adapters/nmatrix_adapter.rb', line 23 def column_names @column_names end |
Class Method Details
.supported?(data) ⇒ Boolean
6 7 8 |
# File 'lib/charty/table_adapters/nmatrix_adapter.rb', line 6 def self.supported?(data) defined?(NMatrix) && data.is_a?(NMatrix) && data.shape.length <= 2 end |
Instance Method Details
#[](row, column) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/charty/table_adapters/nmatrix_adapter.rb', line 25 def [](row, column) if row @data[row, resolve_column_index(column)] else @data[:*, resolve_column_index(column)].reshape([@data.shape[0]]) end end |