Class: JIRADiff::Story

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(story) ⇒ Story

Returns a new instance of Story.

Raises:

  • (ArgumentError)


4
5
6
7
8
9
10
11
12
# File 'lib/jira_diff/story.rb', line 4

def initialize( story )
  unless story =~ /\S+|\S+/
    raise ArgumentError, "story must follow 'SHA|description' format"
  end

  @sha, @description = story.split('|')

  raise ArgumentError if @sha.nil? || @description.nil?
end

Instance Attribute Details

#shaObject (readonly)

Returns the value of attribute sha.



13
14
15
# File 'lib/jira_diff/story.rb', line 13

def sha
  @sha
end

Instance Method Details

#descObject



44
45
46
# File 'lib/jira_diff/story.rb', line 44

def desc
  (split_story)[1]
end

#split_story(description = @description) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/jira_diff/story.rb', line 15

def split_story( description = @description )
  raise RuntimeError 'description cannot be blank' unless description

  stories = []
  story_pattern = /\[?(((SRMPRT|OSMCLOUD)\-\d+)|NO-JIRA)\]?[,:\-\s]+\s*(.*)$/
  line = description.match(story_pattern)

  if line.nil? # did not find a JIRA ticket pattern
    stories.push 'NO-JIRA'
    desc = description.strip
  else
    stories.push line.captures[0]
    desc = line.captures[3].strip
  end

  # Perform recursion if there are multiple tickets in the description
  if desc =~ story_pattern
    new_story, new_desc = split_story desc
    stories.push new_story
    desc = new_desc
  end

  [stories.flatten, desc]
end

#ticketsObject



40
41
42
# File 'lib/jira_diff/story.rb', line 40

def tickets
  (split_story)[0]
end

#to_sObject



48
49
50
# File 'lib/jira_diff/story.rb', line 48

def to_s
  '[%07.07s] %s - %s' % [sha, tickets.join(', '), desc]
end