Class: SplitAndMatchProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/split_and_match_processor.rb

Instance Method Summary collapse

Constructor Details

#initialize(state_mapper) ⇒ SplitAndMatchProcessor

Returns a new instance of SplitAndMatchProcessor.



3
4
5
# File 'lib/split_and_match_processor.rb', line 3

def initialize(state_mapper)
  @state_mapper = state_mapper
end

Instance Method Details

#execute(raw_commit) ⇒ Object



7
8
9
# File 'lib/split_and_match_processor.rb', line 7

def execute(raw_commit)
  @state_mapper.execute(process(raw_commit))
end

#match_commit(commit_line) ⇒ Object



28
29
30
# File 'lib/split_and_match_processor.rb', line 28

def match_commit(commit_line)
  /^\w*/.match(commit_line)
end

#match_story(commit_line) ⇒ Object



24
25
26
# File 'lib/split_and_match_processor.rb', line 24

def match_story(commit_line)
  /\[#(\d*)\]/.match(commit_line)
end

#process(raw_commit) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/split_and_match_processor.rb', line 11

def process(raw_commit)
  commit_lines = raw_commit.split("\n")
  commits_with_story = reject_no_story(commit_lines)
  story_commit = commits_with_story.reverse.map do |cl|
    [match_story(cl)[1], match_commit(cl)[0]]
  end
  Hash[story_commit]
end

#reject_no_story(commit_lines) ⇒ Object



20
21
22
# File 'lib/split_and_match_processor.rb', line 20

def reject_no_story(commit_lines)
  commit_lines.reject { |cl| match_story(cl).nil? }
end