Sha256: 51700a403072547524ef76fecc952a7940ceb56e730721ee24134729396a85f6
Contents?: true
Size: 906 Bytes
Versions: 1
Compression:
Stored size: 906 Bytes
Contents
# frozen_string_literal: true module ShellOnRuby # A command construction, contains the command name and it's arguments / options. class Command attr_reader :name, :arguments, :options def initialize(name, *args, **kargs) @name = name.to_s @arguments = [] @options = {} command_args = args.flatten.map { |arg| argument_symbol_parse(arg) } kargs.map do |key, value| if [IO, Array].include?(key.class) @options[key] = value next end [argument_symbol_parse(key), value.to_s] end.compact.flatten => command_kargs @arguments = [*command_args, *command_kargs] end def self.method_missing(name, *args, **kargs) new(name, *args, **kargs) end private def argument_symbol_parse(symbol) symbol.is_a?(Symbol) ? "-#{'-' if symbol.size > 1}#{symbol}" : symbol.to_s end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
shell_on_ruby-1.0.0 | lib/ruby_on_shell/command.rb |