Class: JIRADiff::Story
- Inherits:
-
Object
- Object
- JIRADiff::Story
- Defined in:
- lib/jira_diff/story.rb
Instance Attribute Summary collapse
-
#sha ⇒ Object
readonly
Returns the value of attribute sha.
Instance Method Summary collapse
- #desc ⇒ Object
-
#initialize(story) ⇒ Story
constructor
A new instance of Story.
- #split_story(description = @description) ⇒ Object
- #tickets ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(story) ⇒ Story
Returns a new instance of Story.
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
#sha ⇒ Object (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
#desc ⇒ Object
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 |
#tickets ⇒ Object
40 41 42 |
# File 'lib/jira_diff/story.rb', line 40 def tickets (split_story)[0] end |
#to_s ⇒ Object
48 49 50 |
# File 'lib/jira_diff/story.rb', line 48 def to_s '[%07.07s] %s - %s' % [sha, tickets.join(', '), desc] end |