Module: MeasureScaler::Prefixes
- Included in:
- Prefix
- Defined in:
- lib/measure_scaler/prefixes.rb
Constant Summary collapse
- LIST =
["y", "z", "a", "f", "p", "n", "µ", "m", "", "k", "M", "G", "T", "P", "E", "Z", "Y"]
- MAX_FACTOR =
24
- MIN_FACTOR =
-24
- STEP =
3
Instance Method Summary collapse
-
#find_factor(symbol) ⇒ Object
Get the base-10 exponent related to the symbol Example: find_factor(“M”) # => 6 (million).
-
#find_symbol(factor) ⇒ Object
Get the symbol related to base-10 passed The factor should be a multiple of 3, greater or equal to -24 and smaller or equal to 24 Example: find_symbol(-3) # => “m” (thousandth).
-
#symbols_list ⇒ Object
Return the list of available symbols.
-
#valid?(symbol) ⇒ Boolean
Is a valid symbol?.
Instance Method Details
#find_factor(symbol) ⇒ Object
Get the base-10 exponent related to the symbol Example: find_factor(“M”) # => 6 (million)
12 13 14 |
# File 'lib/measure_scaler/prefixes.rb', line 12 def find_factor(symbol) valid?(symbol) ? (LIST.index(symbol)*STEP)+MIN_FACTOR : nil end |
#find_symbol(factor) ⇒ Object
Get the symbol related to base-10 passed The factor should be a multiple of 3, greater or equal to -24 and smaller or equal to 24 Example: find_symbol(-3) # => “m” (thousandth)
20 21 22 23 |
# File 'lib/measure_scaler/prefixes.rb', line 20 def find_symbol(factor) return nil if factor%STEP!=0 || factor<MIN_FACTOR || factor>MAX_FACTOR LIST[(factor-MIN_FACTOR)/STEP] end |
#symbols_list ⇒ Object
Return the list of available symbols
31 32 33 |
# File 'lib/measure_scaler/prefixes.rb', line 31 def symbols_list LIST end |
#valid?(symbol) ⇒ Boolean
Is a valid symbol?
26 27 28 |
# File 'lib/measure_scaler/prefixes.rb', line 26 def valid?(symbol) LIST.include?(symbol) end |