Class: Eco::CLI::Scripting::Arguments
- Inherits:
-
Object
- Object
- Eco::CLI::Scripting::Arguments
- Includes:
- Enumerable
- Defined in:
- lib/eco/cli/scripting/arguments.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
Instance Method Summary collapse
- #<<(arg) ⇒ Object
- #add(key, with_param: false) ⇒ Object
- #any_unkown?(exclude: []) ⇒ Boolean
- #each(&block) ⇒ Object
-
#initialize(args = ARGV) ⇒ Arguments
constructor
A new instance of Arguments.
- #keys ⇒ Object
- #known?(value) ⇒ Boolean
- #unknown(exclude: []) ⇒ Object
Constructor Details
#initialize(args = ARGV) ⇒ Arguments
Returns a new instance of Arguments.
9 10 11 12 |
# File 'lib/eco/cli/scripting/arguments.rb', line 9 def initialize(args = ARGV) @args = args @known = {} end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
7 8 9 |
# File 'lib/eco/cli/scripting/arguments.rb', line 7 def args @args end |
Instance Method Details
#<<(arg) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/eco/cli/scripting/arguments.rb', line 23 def <<(arg) raise "Expected Argument. Given #{arg.class}" unless arg.is_a?(Argument) if karg = @known[arg.key] #puts "Found already existent option #{arg.key} (with_param: arg.with_param?)" karg.with_param! if arg.with_param? else #puts "Adding unexistent option #{arg.key}" @known[arg.key] = arg end self end |
#add(key, with_param: false) ⇒ Object
19 20 21 |
# File 'lib/eco/cli/scripting/arguments.rb', line 19 def add(key, with_param: false) self << Argument.new(key, with_param: with_param) end |
#any_unkown?(exclude: []) ⇒ Boolean
49 50 51 |
# File 'lib/eco/cli/scripting/arguments.rb', line 49 def any_unkown?(exclude: []) unknown(exclude: exclude).length > 0 end |
#each(&block) ⇒ Object
14 15 16 17 |
# File 'lib/eco/cli/scripting/arguments.rb', line 14 def each(&block) return to_enum(:each) unless block @known.values.each(&block) end |
#keys ⇒ Object
39 40 41 |
# File 'lib/eco/cli/scripting/arguments.rb', line 39 def keys @known.keys end |
#known?(value) ⇒ Boolean
35 36 37 |
# File 'lib/eco/cli/scripting/arguments.rb', line 35 def known?(value) @known.key?(to_key(value)) end |
#unknown(exclude: []) ⇒ Object
43 44 45 46 47 |
# File 'lib/eco/cli/scripting/arguments.rb', line 43 def unknown(exclude: []) reduce(args.dup - exclude) do |not_known, arg| arg.args_slice(*not_known) end end |