Class: Cliqr::Parser::TokenFactory Private
- Inherits:
-
Object
- Object
- Cliqr::Parser::TokenFactory
- Defined in:
- lib/cliqr/parser/token_factory.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
A factory class to get a instance of CLI::Parser::Token based on the argument
Instance Method Summary collapse
-
#get_token(arg = nil) ⇒ Cliqr::CLI::Parser::Token
private
Get a new instance of CLI::Parser::Token based on the argument.
-
#initialize(config) ⇒ Cliqr::CLI::Parser::TokenFactory
constructor
private
Create a new token factory instance.
Constructor Details
#initialize(config) ⇒ Cliqr::CLI::Parser::TokenFactory
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create a new token factory instance
20 21 22 |
# File 'lib/cliqr/parser/token_factory.rb', line 20 def initialize(config) @config = config end |
Instance Method Details
#get_token(arg = nil) ⇒ Cliqr::CLI::Parser::Token
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get a new instance of CLI::Parser::Token based on the argument
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/cliqr/parser/token_factory.rb', line 29 def get_token(arg = nil) if arg.nil? Token.new else case arg when /^--(no-)?([a-zA-Z][a-zA-Z0-9\-_]*)$/, /^(-)([a-zA-Z])$/ option_config = get_option_config(Regexp.last_match(2), arg) build_token(option_config, arg) else fail Cliqr::Error::IllegalArgumentError, "invalid command argument \"#{arg}\"" \ unless @config.arguments? ArgumentToken.new(arg) end end end |