Module: RubyJard::Commands::ValidationHelpers
- Included in:
- DownCommand, FrameCommand, NextCommand, StepCommand, StepOutCommand, UpCommand
- Defined in:
- lib/ruby_jard/commands/validation_helpers.rb
Overview
Helpers to help validate commands
Instance Method Summary collapse
- #validate_non_negative_integer!(input) ⇒ Object
- #validate_positive_integer!(input) ⇒ Object
- #validate_present!(input) ⇒ Object
- #validate_range!(input, from, to) ⇒ Object
Instance Method Details
#validate_non_negative_integer!(input) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ruby_jard/commands/validation_helpers.rb', line 20 def validate_non_negative_integer!(input) input = input.to_s.strip unless input =~ /^[+\-\d]+$/ raise ::Pry::CommandError, 'argument is not an integer' end input = input.to_i raise ::Pry::CommandError, 'argument must be positive' if input < 0 input.to_i end |
#validate_positive_integer!(input) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/ruby_jard/commands/validation_helpers.rb', line 8 def validate_positive_integer!(input) input = input.to_s.strip unless input =~ /^[+\-\d]+$/ raise ::Pry::CommandError, '`argument is not an integer' end input = input.to_i raise ::Pry::CommandError, 'argument must be positive' if input <= 0 input end |
#validate_present!(input) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/ruby_jard/commands/validation_helpers.rb', line 32 def validate_present!(input) input = input.to_s.strip if input.empty? raise ::Pry::CommandError, 'argument must be present' end input end |
#validate_range!(input, from, to) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/ruby_jard/commands/validation_helpers.rb', line 41 def validate_range!(input, from, to) if input < from || input > to raise ::Pry::CommandError, "argument must be from #{from} to #{to}" end input end |