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.
371 372 373 374 375 |
# File 'lib/mikon/core/dataframe.rb', line 371 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
395 396 397 398 399 |
# File 'lib/mikon/core/dataframe.rb', line 395 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.
408 409 410 |
# File 'lib/mikon/core/dataframe.rb', line 408 def arr @arr end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
408 409 410 |
# File 'lib/mikon/core/dataframe.rb', line 408 def index @index end |
#labels ⇒ Object (readonly)
Returns the value of attribute labels.
408 409 410 |
# File 'lib/mikon/core/dataframe.rb', line 408 def labels @labels end |
Instance Method Details
#[](name) ⇒ Object
377 378 379 380 |
# File 'lib/mikon/core/dataframe.rb', line 377 def [](name) pos = @labels.index(name) pos.nil? ? nil : @arr[pos] end |
#[]=(name, val) ⇒ Object
382 383 384 385 386 387 388 389 390 |
# File 'lib/mikon/core/dataframe.rb', line 382 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
401 402 403 404 405 406 |
# File 'lib/mikon/core/dataframe.rb', line 401 def to_hash @labels.each.with_index.reduce({}) do |memo, (label, i)| memo[label] = @arr[i] memo end end |