Class: MetaProject::Patois::Parser

Inherits:
Object
  • Object
show all
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

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. 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