You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

fixture.rb 1013B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. class String
  2. alias :colorize_old :colorize
  3. COLORS = {
  4. critical: { color: :white, background: :red },
  5. error: :red,
  6. warning: :light_red,
  7. good: :green,
  8. great: :blue,
  9. best: :magenta,
  10. unknown: { background: :black }
  11. }
  12. def colorize(state)
  13. color = COLORS[state] || state
  14. self.colorize_old color
  15. end
  16. end
  17. class Exception
  18. BACKTRACE_REGEXP = /^(.*):(\d+):in `(.*)'$/
  19. def colorize
  20. $stderr.puts self.message.colorize(:red)
  21. self.backtrace.each do |line|
  22. line = BACKTRACE_REGEXP.match line
  23. line = '%s:%s:in `%s\'' % [
  24. line[1].colorize(:yellow),
  25. line[2].colorize(:blue),
  26. line[3].colorize(:magenta)
  27. ]
  28. $stderr.puts line
  29. end
  30. end
  31. end
  32. class Integer
  33. def humanize
  34. secs = self
  35. [[60, :second],
  36. [60, :minute],
  37. [24, :hour],
  38. [30, :day],
  39. [12, :month]].map do |count, name|
  40. if secs > 0
  41. secs, n = secs.divmod count
  42. n = n.to_i
  43. n > 0 ? "#{n} #{name}#{n > 1 ? 's' : ''}" : nil
  44. end
  45. end.compact.reverse.join ' '
  46. end
  47. end