Module: Bovem::ParserMethods::General::ClassMethods
- Defined in:
- lib/bovem/parser.rb
Overview
Class methods
Instance Method Summary (collapse)
-
- (Hash|NilClass) find_command(arg, command, args: {}, separator: ":")
Finds a command which corresponds to an argument.
-
- (Hash|NilClass) parse(command, args)
Parses a command/application.
-
- (String) smart_join(array, separator: ", ", last_separator: " and ", quote: "\"")
Joins an array using multiple separators.
Instance Method Details
- (Hash|NilClass) find_command(arg, command, args: {}, separator: ":")
Finds a command which corresponds to an argument.
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/bovem/parser.rb', line 37 def find_command(arg, command, args: {}, separator: ":") return nil unless command.commands.present? arg, args = adjust_command(arg, args, separator) matching = match_subcommands(arg, command) if matching.length == 1 # Found a command {name: matching[0], args: args} elsif matching.length > 1 # Ambiguous match raise Bovem::Errors::Error.new(command, :ambiguous_command, command.i18n.ambigous_command(arg, format_alternatives(matching, command))) end end |
- (Hash|NilClass) parse(command, args)
Parses a command/application.
55 56 57 |
# File 'lib/bovem/parser.rb', line 55 def parse(command, args) Bovem::Parser.new.parse(command, args) end |
- (String) smart_join(array, separator: ", ", last_separator: " and ", quote: "\"")
Joins an array using multiple separators.
23 24 25 26 27 28 |
# File 'lib/bovem/parser.rb', line 23 def smart_join(array, separator: ", ", last_separator: " and ", quote: "\"") separator = separator.ensure_string last_separator = last_separator.ensure_string array = array.ensure_array { |a| quote.present? ? "#{quote}#{a}#{quote}" : a.ensure_string } perform_smart_join(array, last_separator, separator) end |