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.
- #scale(method) ⇒ Object
- #scale_inverse(method) ⇒ Object
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
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/charty/vector.rb', line 82 def categorical_order(order=nil) if order.nil? case when categorical? order = categories else order = unique_values.compact if numeric? order.sort_by! {|x| Util.missing?(x) ? Float::INFINITY : x } end end order.compact! end order end |
#scale(method) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/charty/vector.rb', line 57 def scale(method) case method when :linear self when :log adapter.log_scale(method) else raise ArgumentError, "Invalid scaling method: %p" % method end end |
#scale_inverse(method) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/charty/vector.rb', line 69 def scale_inverse(method) case method when :linear self when :log adapter.inverse_log_scale(method) else raise ArgumentError, "Invalid scaling method: %p" % method end end |