Class: Torque::FormatString
- Inherits:
-
Object
- Object
- Torque::FormatString
- Defined in:
- lib/torque/format_string.rb
Overview
Applies a format string to stories, generating custom string output for each story
Parameters:
-
%a => Date accepted (MM/DD)
-
%A => Date accepted (YYYY/MM/DD)
-
%d => Description
-
%D => Description (tabbed once on each newline)
-
%e => Estimate
-
%i => ID
-
%l => Labels (separated by “, ”)
-
%n => Newline character
-
%N => Name
-
%o => Owner of the story
-
%p => ID of the story’s project
-
%u => URL pointing to the story
-
%t => Tab character
-
%T => Type (feature, bug, etc)
Class Method Summary collapse
-
.default ⇒ Object
Returns the deafault format string to use.
Instance Method Summary collapse
-
#apply(story) ⇒ Object
A string representing the story formatted according to the format string.
-
#initialize(format_string) ⇒ FormatString
constructor
A new instance of FormatString.
Constructor Details
#initialize(format_string) ⇒ FormatString
Returns a new instance of FormatString.
27 28 29 |
# File 'lib/torque/format_string.rb', line 27 def initialize(format_string) @format_string = format_string end |
Class Method Details
.default ⇒ Object
Returns the deafault format string to use
33 34 35 |
# File 'lib/torque/format_string.rb', line 33 def self.default "%i%n%N%nAccepted on %A%n%u%n%D" end |
Instance Method Details
#apply(story) ⇒ Object
Returns A string representing the story formatted according to the format string.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/torque/format_string.rb', line 41 def apply(story) story_string = @format_string.clone # %a a = (story.date_accepted ? story.date_accepted.strftime("%m/%d") : "") story_string.gsub!("%a", "#{a}") # %A aa = (story.date_accepted ? story.date_accepted.strftime("%Y/%m/%d") : "") story_string.gsub!("%A", "#{aa}") # %d d = story.description story_string.gsub!("%d", "#{d}") # %D dd = "" story.description.each_line {|line| dd += "\t#{line}"} if story.description story_string.gsub!("%D", "#{dd}") # %e e = story.estimate story_string.gsub!("%e", "#{e}") # %i i = story.id story_string.gsub!("%i", "#{i}") # %l l = (story.labels ? story.labels.join(", ") : "") story_string.gsub!("%l", "#{l}") # %n n = "\n" story_string.gsub!("%n", "#{n}") # %N nn = story.name story_string.gsub!("%N", "#{nn}") # %o o = story.owner story_string.gsub!("%o", "#{o}") # %p p = story.project_id story_string.gsub!("%p", "#{p}") # %t t = "\t" story_string.gsub!("%t", "#{t}") # %T tt = story.type story_string.gsub!("%T", "#{tt}") # %u u = story.url story_string.gsub!("%u", "#{u}") story_string end |