Class: JIRADiff::Story
- Inherits:
-
Object
- Object
- JIRADiff::Story
- Defined in:
- lib/jira_diff/story.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#sha ⇒ Object
readonly
Returns the value of attribute sha.
-
#stories ⇒ Object
readonly
Returns the value of attribute stories.
Instance Method Summary collapse
-
#initialize(story) ⇒ Story
constructor
A new instance of Story.
- #split_story(description) ⇒ Object
- #subject ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(story) ⇒ Story
Returns a new instance of Story.
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
#description ⇒ Object (readonly)
Returns the value of attribute description.
15 16 17 |
# File 'lib/jira_diff/story.rb', line 15 def description @description end |
#sha ⇒ Object (readonly)
Returns the value of attribute sha.
15 16 17 |
# File 'lib/jira_diff/story.rb', line 15 def sha @sha end |
#stories ⇒ Object (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
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 |
#subject ⇒ Object
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_s ⇒ Object
41 42 43 |
# File 'lib/jira_diff/story.rb', line 41 def to_s "[%07.07s] %-14s - %.80s" % [sha, stories.join(", "), subject] end |