class Raph::Parser::BaseParser

Base class for all argument parsers.

You can create a custom parser by subclassing ‘Raph::Parser::BaseParser` and overriding some methods, or by implementing all the methods by duck typing.

Public Instance Methods

id() click to toggle source

Parser unique id. If parser class name follows a convention NameParser then it’s id will be automatically determined as it’s name in snake case plus suffix ‘s’

Example:

FlagParser.new.id                  # => :flags
FileParser.new.id                  # => :files
BaseArgumentParser.new.id          # => :base_arguments
# File lib/raph/parser/base_parser.rb, line 19
def id
  name = class_name.gsub(/parser$/i, '')
  name << 's' # make it plural
  to_underscored_sym(name)
end
parse(args) click to toggle source

Parses arguments and returns results of parsing.

# File lib/raph/parser/base_parser.rb, line 26
def parse(args)
end

Protected Instance Methods

to_underscored_sym(str) click to toggle source

Returns underscored symbol of string (snake case format).

# File lib/raph/parser/base_parser.rb, line 33
def to_underscored_sym(str)
  str.gsub(/^[-]+/, '').
    gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
    gsub(/([a-z\d])([A-Z])/,'\1_\2').
    tr("-", "_").
    downcase.
    to_sym
end

Private Instance Methods

class_name() click to toggle source

Returns name of current class.

# File lib/raph/parser/base_parser.rb, line 45
def class_name
  self.class.name.split('::').last || ''
end