Sha256: c185c06f4c828d0e7dced065decb7fc5d7ab950788d3581a8d1a186af23218a4

Contents?: true

Size: 1.45 KB

Versions: 7

Compression:

Stored size: 1.45 KB

Contents

class Radiosonde::DSL::Unit
  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 << self
    def conv_to_alias(unit)
      ALIASES[unit] || unit
    end

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

    def normalize(unit)
      (ALIASES.respond_to?(:key) ? ALIASES.key(unit) : ALIASES.index(unit)) || unit
    end
  end # of class methods
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
radiosonde-0.2.0.beta5 lib/radiosonde/dsl/unit.rb
radiosonde-0.2.0.beta4 lib/radiosonde/dsl/unit.rb
radiosonde-0.2.0.beta3 lib/radiosonde/dsl/unit.rb
radiosonde-0.2.0.beta2 lib/radiosonde/dsl/unit.rb
radiosonde-0.2.0.beta lib/radiosonde/dsl/unit.rb
radiosonde-0.1.1 lib/radiosonde/dsl/unit.rb
radiosonde-0.1.0 lib/radiosonde/dsl/unit.rb