Class: MeasureScaler::Unit
- Inherits:
-
Object
- Object
- MeasureScaler::Unit
- Defined in:
- lib/measure_scaler/unit.rb
Instance Attribute Summary collapse
-
#direction ⇒ Object
readonly
Returns the value of attribute direction.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#preunit ⇒ Object
readonly
Returns the value of attribute preunit.
-
#unit ⇒ Object
readonly
Returns the value of attribute unit.
Instance Method Summary collapse
-
#initialize(string_or_hash) ⇒ Unit
constructor
A new instance of Unit.
- #pattern_found? ⇒ Boolean
-
#scale(order) ⇒ Object
order is a multiple of 3.
- #to_s(prefix = nil) ⇒ Object
Constructor Details
#initialize(string_or_hash) ⇒ Unit
Returns a new instance of Unit.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/measure_scaler/unit.rb', line 4 def initialize(string_or_hash) case string_or_hash when String decode_string(string_or_hash) when Hash h = {direction: 1, preunit: nil}.merge(string_or_hash) @prefix = Prefix.new(h[:prefix]) @preunit = h[:preunit] @unit = h[:unit] @direction = h[:direction] else raise "attribute not valid" end end |
Instance Attribute Details
#direction ⇒ Object (readonly)
Returns the value of attribute direction.
3 4 5 |
# File 'lib/measure_scaler/unit.rb', line 3 def direction @direction end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
3 4 5 |
# File 'lib/measure_scaler/unit.rb', line 3 def prefix @prefix end |
#preunit ⇒ Object (readonly)
Returns the value of attribute preunit.
3 4 5 |
# File 'lib/measure_scaler/unit.rb', line 3 def preunit @preunit end |
#unit ⇒ Object (readonly)
Returns the value of attribute unit.
3 4 5 |
# File 'lib/measure_scaler/unit.rb', line 3 def unit @unit end |
Instance Method Details
#pattern_found? ⇒ Boolean
21 22 23 |
# File 'lib/measure_scaler/unit.rb', line 21 def pattern_found? !@prefix.nil? end |
#scale(order) ⇒ Object
order is a multiple of 3
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/measure_scaler/unit.rb', line 25 def scale(order) # order is a multiple of 3 definitive_order, new_prefix = @prefix.scale(order*@direction) [ definitive_order*@direction, Unit.new( prefix: new_prefix, preunit: @preunit, unit: @unit, direction: @direction) ] end |
#to_s(prefix = nil) ⇒ Object
36 37 38 |
# File 'lib/measure_scaler/unit.rb', line 36 def to_s(prefix=nil) "#{@preunit}#{prefix||@prefix}#{@unit}" end |