lib/kommand/scripts/arguments.rb in kommand-0.0.1 vs lib/kommand/scripts/arguments.rb in kommand-0.0.2

- old
+ new

@@ -1,8 +1,30 @@ module Kommand module Scripts class Arguments < Array - + + def named + args = self.class.new + args.concat(select { |arg| !arg.unnamed? }) + end + + def unnamed + args = self.class.new + args.concat(select { |arg| arg.unnamed? }) + end + + def arg(key) + named.select { |arg| arg.name.to_s == key.to_s }.first + end + + def arg?(key) + !arg(key).nil? + end + + def get(key) + arg?(key) ? arg(key).value : nil + end + def to_s map do |arg| #if arg.valid.nil? || arg.valid.empty? "[#{arg.keys.join(", ")}]" #else