class GitTrelloPostCommit::MessageParser

Public Class Methods

new(message) click to toggle source
# File lib/git_trello_post_commit.rb, line 20
def initialize(message)
  @message = message
end

Public Instance Methods

categorize_keyword(keyword) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/git_trello_post_commit.rb, line 24
def instructions
  @instructions ||= parse_instructions
end
normalize_matches(matches) click to toggle source
# 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() click to toggle source
# 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