Module: ArgsParser
- Defined in:
- lib/args-parser.rb
Class Method Summary collapse
- .eval_pipes(arg) ⇒ Object
- .eval_pipes_with_val(value, pipes) ⇒ Object
- .parse(content) ⇒ Object
- .split_args(content) ⇒ Object
Class Method Details
.eval_pipes(arg) ⇒ Object
38 39 40 41 42 |
# File 'lib/args-parser.rb', line 38 def self.eval_pipes(arg) parts = arg.split(" | ").map(&:strip) value = parts.shift eval_pipes_with_val(value, parts) end |
.eval_pipes_with_val(value, pipes) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/args-parser.rb', line 24 def self.eval_pipes_with_val(value, pipes) pipes.each do |pipe| if (match = pipe.match(/\[(-?\d+):(-?\d+)\]/)) start_idx, end_idx = match[1].to_i, match[2].to_i value = value[start_idx..end_idx] elsif StringManipulation.respond_to?(pipe) value = StringManipulation.public_send(pipe, value) else raise ArgumentError, "Unkown pipe '#{pipe}'" end end value end |
.parse(content) ⇒ Object
44 45 46 |
# File 'lib/args-parser.rb', line 44 def self.parse(content) split_args(content).map { |arg| eval_pipes(arg) } end |
.split_args(content) ⇒ Object
20 21 22 |
# File 'lib/args-parser.rb', line 20 def self.split_args(content) content.split(" ; ").map(&:strip) end |