Class: Tweetwine::StartupConfig
- Inherits:
-
Object
- Object
- Tweetwine::StartupConfig
- Defined in:
- lib/tweetwine/startup_config.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#supported_commands ⇒ Object
readonly
Returns the value of attribute supported_commands.
Instance Method Summary collapse
-
#initialize(supported_commands) ⇒ StartupConfig
constructor
A new instance of StartupConfig.
- #parse(args = [], config_file = nil, &cmd_parser) ⇒ Object
Constructor Details
#initialize(supported_commands) ⇒ StartupConfig
Returns a new instance of StartupConfig.
7 8 9 10 11 12 13 |
# File 'lib/tweetwine/startup_config.rb', line 7 def initialize(supported_commands) @supported_commands = supported_commands.to_a raise ArgumentError, "Must give at least one supported command" if @supported_commands.empty? @options = {} @command = @supported_commands.first @args = [] end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
5 6 7 |
# File 'lib/tweetwine/startup_config.rb', line 5 def args @args end |
#command ⇒ Object (readonly)
Returns the value of attribute command.
5 6 7 |
# File 'lib/tweetwine/startup_config.rb', line 5 def command @command end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/tweetwine/startup_config.rb', line 5 def @options end |
#supported_commands ⇒ Object (readonly)
Returns the value of attribute supported_commands.
5 6 7 |
# File 'lib/tweetwine/startup_config.rb', line 5 def supported_commands @supported_commands end |
Instance Method Details
#parse(args = [], config_file = nil, &cmd_parser) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/tweetwine/startup_config.rb', line 15 def parse(args = [], config_file = nil, &cmd_parser) = (args, config_file, &cmd_parser) command = if args.empty? then @supported_commands.first else args.shift.to_sym end raise ArgumentError, "Unknown command" unless @supported_commands.include? command @options, @command, @args = , command, args self end |