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
13
# File 'lib/jira_diff/story.rb', line 4

def initialize(story)
  unless story =~ /\w{40}|.*/
    raise ArgumentError, 'story must follow "SHA|description" format'
  end

  @sha, description      = story.split("|")
  @stories, @description = split_story description

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

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



15
16
17
# File 'lib/jira_diff/story.rb', line 15

def description
  @description
end

#shaObject (readonly)

Returns the value of attribute sha.



15
16
17
# File 'lib/jira_diff/story.rb', line 15

def sha
  @sha
end

#storiesObject (readonly)

Returns the value of attribute stories.



15
16
17
# File 'lib/jira_diff/story.rb', line 15

def stories
  @stories
end

Instance Method Details

#split_story(description) ⇒ Object

Raises:

  • (RuntimeError)


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

def split_story(description)
  raise RuntimeError, "description cannot be blank" unless description

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

  stories.push line ? line.captures[0] : "JIRA-NOT-FOUND"
  desc = (line ? line.captures[3] : description).strip

  # 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

#subjectObject



37
38
39
# File 'lib/jira_diff/story.rb', line 37

def subject
  @description.split("\n")[0].gsub(/[*:-]/, " ").strip rescue "No Description Provided"
end

#to_sObject



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

def to_s
  "[%07.07s] %-14s - %.80s" % [sha, stories.join(", "), subject]
end