Module: DTAS::ParseFreq

Defined in:
lib/dtas/parse_freq.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#parse_freq(val, round = true) ⇒ Object

may return a negative frequency meaning lowpass


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/dtas/parse_freq.rb', line 8

def parse_freq(val, round = true)
  case val
  when String
    val = val.dup
    mult = val.sub!(/k\z/, '') ? 1000 : 1
    val = (val.to_f * mult)
  when Numeric
    val
  else
    raise ArgumentError, "non-numeric value given"
  end

  case round
  when true, :int
    val.round
  when :float
    val.to_f
  else
    raise ArgumentError, "usage: parse_freq(val, (true|:round))"
  end
end