class Torque::FormatString

Applies a format string to stories, generating custom string output for each story

Parameters:

Public Class Methods

default() click to toggle source

Returns the deafault format string to use

# File lib/torque/format_string.rb, line 33
def self.default
  "%i%n%N%nAccepted on %A%n%u%n%D"
end
new(format_string) click to toggle source

@param format_string The format string to use

# File lib/torque/format_string.rb, line 27
def initialize(format_string)
  @format_string = format_string
end

Public Instance Methods

apply(story) click to toggle source

@param story A Torque::Story object

@return A string representing the story formatted according to the format string

# 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