Class: MetaProject::Patois::Parser
- Inherits:
-
Object
- Object
- MetaProject::Patois::Parser
- Defined in:
- lib/meta_project/patois/parser.rb
Overview
Parses Patois
Defined Under Namespace
Classes: Command
Constant Summary collapse
- SUPPORTED_COMMANDS =
{ 'close' => ':close', 'closed' => ':close', 'closes' => ':close', 'fix' => ':close', 'fixed' => ':close', 'fixes' => ':close', 'addresses' => ':comment', 're' => ':comment', 'ref' => ':comment', 'references' => ':comment', 'refs' => ':comment', 'see' => ':comment' }
Instance Method Summary collapse
-
#initialize(command_pattern, issue_pattern) ⇒ Parser
constructor
Creates a new parser that will parse commands with
command_pattern
and emit individual commands withissue_pattern
. -
#parse(msg) ⇒ Object
Parses a patois String and yields commands.
Constructor Details
#initialize(command_pattern, issue_pattern) ⇒ Parser
Creates a new parser that will parse commands with command_pattern
and emit individual commands with issue_pattern
.
71 72 73 74 |
# File 'lib/meta_project/patois/parser.rb', line 71 def initialize(command_pattern, issue_pattern) @command_pattern = command_pattern @issue_pattern = issue_pattern end |
Instance Method Details
#parse(msg) ⇒ Object
Parses a patois String and yields commands. TODO: Each operation can be executed with execute
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/meta_project/patois/parser.rb', line 78 def parse(msg) msg.scan(@command_pattern) do |cmd_group| cmd = SUPPORTED_COMMANDS[cmd_group[0].downcase] if(cmd) cmd_group[1].scan(@issue_pattern) do |issue_id_array| yield Command.new(cmd, issue_id_array[0].upcase, msg) end end end end |