Module: RSMP::TLC::Modules::Helpers
- Included in:
- TrafficController
- Defined in:
- lib/rsmp/tlc/modules/helpers.rb
Overview
Utility helper methods
Instance Method Summary collapse
- #bool_string_to_digit(bool) ⇒ Object
- #bool_to_digit(bool) ⇒ Object
- #find_plan(plan_nr) ⇒ Object
- #string_to_bool(bool_str) ⇒ Object
Instance Method Details
#bool_string_to_digit(bool) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rsmp/tlc/modules/helpers.rb', line 24 def bool_string_to_digit(bool) case bool when 'True' '1' when 'False' '0' else raise RSMP::MessageRejected, "Invalid boolean '#{bool}', must be 'True' or 'False'" end end |
#bool_to_digit(bool) ⇒ Object
35 36 37 |
# File 'lib/rsmp/tlc/modules/helpers.rb', line 35 def bool_to_digit(bool) bool ? '1' : '0' end |
#find_plan(plan_nr) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/rsmp/tlc/modules/helpers.rb', line 6 def find_plan(plan_nr) plan = @plans[plan_nr.to_i] raise InvalidMessage, "unknown signal plan #{plan_nr}, known only [#{@plans.keys.join(', ')}]" unless plan plan end |
#string_to_bool(bool_str) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/rsmp/tlc/modules/helpers.rb', line 13 def string_to_bool(bool_str) case bool_str when 'True' true when 'False' false else raise RSMP::MessageRejected, "Invalid boolean '#{bool}', must be 'True' or 'False'" end end |