Class: BenchmarkSpec::OutputFormatter
- Inherits:
-
Object
- Object
- BenchmarkSpec::OutputFormatter
- Defined in:
- lib/benchmark_spec/output_formatter.rb
Constant Summary collapse
- TITLE_LENGHT =
100- TITLE_FILLER =
'-'- MIN_NUM_OF_FILLERS =
20
Instance Attribute Summary collapse
-
#indent_level ⇒ Object
Returns the value of attribute indent_level.
-
#space_per_indent ⇒ Object
Returns the value of attribute space_per_indent.
Class Method Summary collapse
Instance Method Summary collapse
- #indent_message(message) ⇒ Object
-
#initialize(indent_level: 0, space_per_indent: 2) ⇒ OutputFormatter
constructor
A new instance of OutputFormatter.
- #margin ⇒ Object
- #new_line ⇒ Object
- #print(message) ⇒ Object
- #title(content) ⇒ Object
- #with_margins_vertically(*a, &b) ⇒ Object
Constructor Details
#initialize(indent_level: 0, space_per_indent: 2) ⇒ OutputFormatter
Returns a new instance of OutputFormatter.
9 10 11 12 |
# 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 |
Instance Attribute Details
#indent_level ⇒ Object
Returns the value of attribute indent_level.
3 4 5 |
# File 'lib/benchmark_spec/output_formatter.rb', line 3 def indent_level @indent_level end |
#space_per_indent ⇒ Object
Returns the value of attribute space_per_indent.
3 4 5 |
# File 'lib/benchmark_spec/output_formatter.rb', line 3 def space_per_indent @space_per_indent end |
Class Method Details
.new_line ⇒ Object
30 31 32 |
# File 'lib/benchmark_spec/output_formatter.rb', line 30 def new_line puts "\n" end |
.title(content) ⇒ Object
15 16 17 18 19 20 21 22 |
# 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) ⇒ Object
24 25 26 27 28 |
# 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 |
Instance Method Details
#indent_message(message) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/benchmark_spec/output_formatter.rb', line 52 def () return unless indent_level > 0 = .gsub("\n", "\n" + margin) return "#{margin}#{}" end |
#margin ⇒ Object
60 61 62 |
# File 'lib/benchmark_spec/output_formatter.rb', line 60 def margin " " * indent_level * space_per_indent end |
#new_line ⇒ Object
39 40 41 |
# File 'lib/benchmark_spec/output_formatter.rb', line 39 def new_line self.class.new_line end |
#print(message) ⇒ Object
47 48 49 50 |
# File 'lib/benchmark_spec/output_formatter.rb', line 47 def print() = () puts end |
#title(content) ⇒ Object
35 36 37 |
# File 'lib/benchmark_spec/output_formatter.rb', line 35 def title(content) self.class.title(content) end |
#with_margins_vertically(*a, &b) ⇒ Object
43 44 45 |
# File 'lib/benchmark_spec/output_formatter.rb', line 43 def with_margins_vertically(*a, &b) self.class.with_margins_vertically(*a, &b) end |