Class: GitTrelloPostCommit::MessageParser
- Inherits:
-
Object
- Object
- GitTrelloPostCommit::MessageParser
- Defined in:
- lib/git_trello_post_commit.rb
Instance Method Summary collapse
- #categorize_keyword(keyword) ⇒ Object
- #extract_instructions(raw_matches) ⇒ Object
- #get_raw_matches ⇒ Object
-
#initialize(message) ⇒ MessageParser
constructor
A new instance of MessageParser.
- #instructions ⇒ Object
- #normalize_matches(matches) ⇒ Object
- #parse_instructions ⇒ Object
Constructor Details
#initialize(message) ⇒ MessageParser
Returns a new instance of MessageParser.
20 21 22 |
# File 'lib/git_trello_post_commit.rb', line 20 def initialize() @message = end |
Instance Method Details
#categorize_keyword(keyword) ⇒ Object
40 41 42 43 44 |
# File 'lib/git_trello_post_commit.rb', line 40 def categorize_keyword(keyword) if DONE_KEYWORDS.include?(keyword) then :done elsif IN_PROGRESS_KEYWORDS.include?(keyword) then :in_progress end end |
#extract_instructions(raw_matches) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/git_trello_post_commit.rb', line 46 def extract_instructions(raw_matches) raw_matches.reduce(Hash.new { |hash, key| hash[key] = [] }) do |matches, raw_match| keyword = raw_match.first.downcase.to_sym id_list = raw_match.last if keyword and id_list ids = id_list.scan(ID_CAPTURE_REGEX).flatten.map(&:to_i).select { |n| n>0 } ids.each do |id| matches[id] << keyword end end matches end end |
#get_raw_matches ⇒ Object
34 35 36 37 38 |
# File 'lib/git_trello_post_commit.rb', line 34 def get_raw_matches @message.scan(REF_REGEX).map do |match| match.compact[1..-1] end end |
#instructions ⇒ Object
24 25 26 |
# File 'lib/git_trello_post_commit.rb', line 24 def instructions @instructions ||= parse_instructions end |
#normalize_matches(matches) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/git_trello_post_commit.rb', line 60 def normalize_matches(matches) matches.reduce({}) do |norm_matches, (card_id, keywords)| keywords.uniq! categories = keywords.map { |kw| categorize_keyword(kw) }.compact.uniq if categories.length > 1 and categories.include?(:done) norm_matches[card_id] = :done elsif categories.length == 1 norm_matches[card_id] = categories.first end norm_matches end end |
#parse_instructions ⇒ Object
28 29 30 31 32 |
# File 'lib/git_trello_post_commit.rb', line 28 def parse_instructions raw_matches = get_raw_matches matches = extract_instructions(raw_matches) normalize_matches(matches) end |