class BenchmarkSpec::OutputFormatter
Constants
- MIN_NUM_OF_FILLERS
- TITLE_FILLER
- TITLE_LENGHT
Attributes
indent_level[RW]
space_per_indent[RW]
Public Class Methods
new(indent_level: 0, space_per_indent: 2)
click to toggle source
# File lib/benchmark_spec/output_formatter.rb, line 9 def initialize(indent_level: 0, space_per_indent: 2) @indent_level = indent_level @space_per_indent = space_per_indent end
new_line()
click to toggle source
# File lib/benchmark_spec/output_formatter.rb, line 30 def new_line puts "\n" end
title(content)
click to toggle source
# File lib/benchmark_spec/output_formatter.rb, line 15 def title(content) with_margins_vertically do side_fillers = TITLE_FILLER * ([TITLE_LENGHT - content.length, MIN_NUM_OF_FILLERS].max / 2 - 1) # -1 for the space puts "#{side_fillers} #{content} #{side_fillers}" end end
with_margins_vertically(num_of_lines = 1) { || ... }
click to toggle source
# File lib/benchmark_spec/output_formatter.rb, line 24 def with_margins_vertically(num_of_lines = 1) num_of_lines.times { new_line } yield num_of_lines.times { new_line } end
Public Instance Methods
indent_message(message)
click to toggle source
# File lib/benchmark_spec/output_formatter.rb, line 52 def indent_message(message) return message unless indent_level > 0 message = message.gsub("\n", "\n" + margin) return "#{margin}#{message}" end
margin()
click to toggle source
# File lib/benchmark_spec/output_formatter.rb, line 60 def margin " " * indent_level * space_per_indent end
new_line()
click to toggle source
# File lib/benchmark_spec/output_formatter.rb, line 39 def new_line self.class.new_line end
print(message)
click to toggle source
# File lib/benchmark_spec/output_formatter.rb, line 47 def print(message) message = indent_message(message) puts message end
title(content)
click to toggle source
# File lib/benchmark_spec/output_formatter.rb, line 35 def title(content) self.class.title(content) end
with_margins_vertically(*a, &b)
click to toggle source
# File lib/benchmark_spec/output_formatter.rb, line 43 def with_margins_vertically(*a, &b) self.class.with_margins_vertically(*a, &b) end