Class: Mikon::Row
- Inherits:
-
Object
- Object
- Mikon::Row
- Defined in:
- lib/mikon/core/dataframe.rb
Overview
Row class for internal use
Instance Attribute Summary collapse
-
#arr ⇒ Object
readonly
Returns the value of attribute arr.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#labels ⇒ Object
readonly
Returns the value of attribute labels.
Instance Method Summary collapse
- #[](name) ⇒ Object
- #[]=(name, val) ⇒ Object
-
#initialize(labels, arr, index) ⇒ Row
constructor
A new instance of Row.
- #method_missing(name, *args) ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(labels, arr, index) ⇒ Row
Returns a new instance of Row.
361 362 363 364 365 |
# File 'lib/mikon/core/dataframe.rb', line 361 def initialize(labels, arr, index) @labels = labels @arr = arr @index = index end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
385 386 387 388 389 |
# File 'lib/mikon/core/dataframe.rb', line 385 def method_missing(name, *args) super unless args.length == 0 pos = @labels.index(name) pos.nil? ? super : @arr[pos] end |
Instance Attribute Details
#arr ⇒ Object (readonly)
Returns the value of attribute arr.
398 399 400 |
# File 'lib/mikon/core/dataframe.rb', line 398 def arr @arr end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
398 399 400 |
# File 'lib/mikon/core/dataframe.rb', line 398 def index @index end |
#labels ⇒ Object (readonly)
Returns the value of attribute labels.
398 399 400 |
# File 'lib/mikon/core/dataframe.rb', line 398 def labels @labels end |
Instance Method Details
#[](name) ⇒ Object
367 368 369 370 |
# File 'lib/mikon/core/dataframe.rb', line 367 def [](name) pos = @labels.index(name) pos.nil? ? nil : @arr[pos] end |
#[]=(name, val) ⇒ Object
372 373 374 375 376 377 378 379 380 |
# File 'lib/mikon/core/dataframe.rb', line 372 def []=(name, val) pos = @labels.index(name) if pos.nil? @labels.push(name) @arr.push(val) else @arr[pos] = val end end |
#to_hash ⇒ Object
391 392 393 394 395 396 |
# File 'lib/mikon/core/dataframe.rb', line 391 def to_hash @labels.each.with_index.reduce({}) do |memo, (label, i)| memo[label] = @arr[i] memo end end |