Module: Seriamp::Utils
- Defined in:
- lib/seriamp/utils.rb
Class Method Summary collapse
Class Method Details
.consume_data(io, logger, msg) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/seriamp/utils.rb', line 21 module_function def consume_data(io, logger, msg) warned = false buf = +'' while IO.select([io], nil, nil, 0) unless warned logger&.warn(msg) warned = true end buf += io.read_nonblock(1024) end if buf.empty? nil else logger&.warn("Consumed #{buf.length} bytes") buf end end |
.monotime ⇒ Object
17 18 19 |
# File 'lib/seriamp/utils.rb', line 17 module_function def monotime Process.clock_gettime(Process::CLOCK_MONOTONIC) end |
.parse_on_off(value) ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/seriamp/utils.rb', line 6 module_function def parse_on_off(value) case value&.downcase when '1', 'on', 'yes', 'true' true when '0', 'off', 'no', 'false' false else raise InvalidOnOffValue, "Invalid on/off value: #{value}" end end |