Class: Alf::Algebra::Signature
- Inherits:
-
Object
- Object
- Alf::Algebra::Signature
- Defined in:
- lib/alf/shell/ext/signature.rb
Instance Method Summary collapse
-
#argv2args(argv) ⇒ Object
Converts commandline arguments to operator constructor arguments.
-
#to_shell ⇒ Object
Returns a shell synopsis for this signature.
Instance Method Details
#argv2args(argv) ⇒ Object
Converts commandline arguments to operator constructor arguments
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/alf/shell/ext/signature.rb', line 6 def argv2args(argv) # First split over -- argv = Quickl.split_commandline_args(argv) # Parse the options and replace argv[0] by remaining arguments opts = {} argv[0] = option_parser(opts).parse!(argv[0]) opts = .merge(opts) # Operands are argv[0], and can be removed oper = argv.shift # Coerce each remaining argument according to the signature args = [] with_each_arg(argv) do |name,dom,value| invalid_args!(args) if value.nil? args << Shell.from_argv(Array(value), dom) end [oper, args, opts] end |
#to_shell ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/alf/shell/ext/signature.rb', line 34 def to_shell oper = operator.nullary? ? "" : (operator.unary? ? "[OPERAND]" : "[LEFT] RIGHT") opts = .map{|opt| "[#{option_name(opt)}]" }.join(" ") args = arguments.map{|arg,_| "#{arg.to_s.upcase}" }.join(" -- ") optargs = "#{opts} #{oper} " + (args.empty? ? "" : "-- #{args}") "alf #{operator.rubycase_name} #{optargs.strip}".strip end |