Class: Radiosonde::DSL::Unit

Inherits:
Object
  • Object
show all
Defined in:
lib/radiosonde/dsl/unit.rb

Constant Summary collapse

ALIASES =
{
  'Seconds'          => :seconds,
  'Microseconds'     => :microseconds,
  'Milliseconds'     => :milliseconds,
  'Bytes'            => :bytes,
  'Kilobytes'        => :kilobytes,
  'Megabytes'        => :megabytes,
  'Gigabytes'        => :gigabytes,
  'Terabytes'        => :terabytes,
  'Bits'             => :bits,
  'Kilobits'         => :kilobits,
  'Megabits'         => :megabits,
  'Gigabits'         => :gigabits,
  'Terabits'         => :terabits,
  'Percent'          => :percent,
  'Count'            => :count,
  'Bytes/Second'     => :bytes_per_second,
  'Kilobytes/Second' => :kilobytes_per_second,
  'Megabytes/Second' => :megabytes_per_second,
  'Gigabytes/Second' => :gigabytes_per_second,
  'Terabytes/Second' => :terabytes_per_second,
  'Bits/Second'      => :bits_per_second,
  'Kilobits/Second'  => :kilobits_per_second,
  'Megabits/Second'  => :megabits_per_second,
  'Gigabits/Second'  => :gigabits_per_second,
  'Terabits/Second'  => :terabits_per_second,
  'Count/Second'     => :count_per_second,
  'None'             => :none,
}

Class Method Summary collapse

Class Method Details

.conv_to_alias(unit) ⇒ Object



33
34
35
# File 'lib/radiosonde/dsl/unit.rb', line 33

def conv_to_alias(unit)
  ALIASES[unit] || unit
end

.normalize(unit) ⇒ Object



41
42
43
# File 'lib/radiosonde/dsl/unit.rb', line 41

def normalize(unit)
  (ALIASES.respond_to?(:key) ? ALIASES.key(unit) : ALIASES.index(unit)) || unit
end

.valid?(unit) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/radiosonde/dsl/unit.rb', line 37

def valid?(unit)
  ALIASES.keys.include?(unit) or ALIASES.values.include?(unit)
end