Class: Charty::Vector
- Inherits:
-
Object
- Object
- Charty::Vector
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/charty/vector.rb
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
Class Method Summary collapse
Instance Method Summary collapse
-
#categorical_order(order = nil) ⇒ Object
TODO: write test.
-
#initialize(data, index: nil, name: nil) ⇒ Vector
constructor
A new instance of Vector.
Constructor Details
#initialize(data, index: nil, name: nil) ⇒ Vector
Returns a new instance of Vector.
19 20 21 22 23 24 |
# File 'lib/charty/vector.rb', line 19 def initialize(data, index: nil, name: nil) adapter_class = VectorAdapters.find_adapter_class(data) @adapter = adapter_class.new(data) self.index = index unless index.nil? self.name = name unless name.nil? end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
26 27 28 |
# File 'lib/charty/vector.rb', line 26 def adapter @adapter end |
Class Method Details
.try_convert(obj) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/charty/vector.rb', line 8 def self.try_convert(obj) case obj when self obj else if VectorAdapters.find_adapter_class(obj, exception: false) new(obj) end end end |
Instance Method Details
#categorical_order(order = nil) ⇒ Object
TODO: write test
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/charty/vector.rb', line 55 def categorical_order(order=nil) if order.nil? case when categorical? order = categories else order = unique_values.compact order.sort! if numeric? end order.compact! end order end |