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
30 31 32 33 34 |
# File 'lib/args-parser.rb', line 30 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
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/args-parser.rb', line 10 def self.eval_pipes_with_val(value, pipes) pipes.each do |pipe| args = pipe.split(" ") || [] func = args.shift || 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?(func) value = StringManipulation.public_send(func, value, args) elsif NumbersManipulation.respond_to?(func) value = NumbersManipulation.public_send(func, value, args) elsif ArraysManipulation.respond_to?(func) value = ArraysManipulation.public_send(func, value, args) else raise ArgumentError, "Unknown function '#{func}'" end end value end |
.parse(content) ⇒ Object
36 37 38 |
# File 'lib/args-parser.rb', line 36 def self.parse(content) split_args(content).map { |arg| eval_pipes(arg) } end |
.split_args(content) ⇒ Object
6 7 8 |
# File 'lib/args-parser.rb', line 6 def self.split_args(content) content.split(" ; ").map(&:strip) end |