Module: VectorNumber::Stringifying
- Included in:
- VectorNumber
- Defined in:
- lib/vector_number/stringifying.rb
Overview
Methods and options for string representation.
Constant Summary collapse
- MULT_STRINGS =
Predefined symbols for multiplication to display between unit and coefficient.
{ asterisk: "*", # U+002A cross: "×", # U+00D7 dot: "⋅", # U+22C5 invisible: "", # U+2062, zero-width multiplication operator space: " ", none: "", }.freeze
Instance Method Summary collapse
-
#inspect ⇒ String
Get a string representation of the vector.
-
#to_s(mult: options[:mult]) ⇒ String
Get a string representation of the vector.
Instance Method Details
#inspect ⇒ String
Get a string representation of the vector.
This is similar to Complex#inspect: it returns result of #to_s in round brackets.
65 66 67 68 |
# File 'lib/vector_number/stringifying.rb', line 65 def inspect # TODO: Probably make this independent of options. "(#{self})" end |
#to_s(mult: options[:mult]) ⇒ String
Get a string representation of the vector.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/vector_number/stringifying.rb', line 38 def to_s(mult: [:mult]) return "0" if zero? result = +"" each_with_index do |(unit, coefficient), index| if index.zero? result << "-" if coefficient.negative? else result << (coefficient.positive? ? " + " : " - ") end result << value_to_s(unit, coefficient.abs, mult: mult) end result end |