Class: RCheck::Formatter
- Inherits:
-
Object
- Object
- RCheck::Formatter
- Defined in:
- lib/rcheck/formatting.rb
Instance Method Summary collapse
- #format(margin, *lines) ⇒ Object
- #format_with_bullet(margin, bullet, *lines) ⇒ Object
- #format_with_bullets(margin, bullet, *lines) ⇒ Object
- #indent_with_opts(margin, bullet, bullet_all, *lines) ⇒ Object
- #trunc(*lines) ⇒ Object
- #trunc_cols(*lines) ⇒ Object
- #trunc_rows(*lines) ⇒ Object
Instance Method Details
#format(margin, *lines) ⇒ Object
54 55 56 |
# File 'lib/rcheck/formatting.rb', line 54 def format(margin, *lines) trunc indent_with_opts(margin, ' ', false, *lines) end |
#format_with_bullet(margin, bullet, *lines) ⇒ Object
46 47 48 |
# File 'lib/rcheck/formatting.rb', line 46 def format_with_bullet(margin, bullet, *lines) trunc indent_with_opts(margin, bullet, false, *lines) end |
#format_with_bullets(margin, bullet, *lines) ⇒ Object
50 51 52 |
# File 'lib/rcheck/formatting.rb', line 50 def format_with_bullets(margin, bullet, *lines) trunc indent_with_opts(margin, bullet, true, *lines) end |
#indent_with_opts(margin, bullet, bullet_all, *lines) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rcheck/formatting.rb', line 35 def indent_with_opts(margin, bullet, bullet_all, *lines) pad = ' ' * margin bullet_pad = (' ' * (margin - 3)) + " #{bullet} " result = [] result << bullet_pad + lines.shift if lines.any? lines.each do |line| result << (bullet_all ? bullet_pad : pad) + line end result end |
#trunc(*lines) ⇒ Object
31 32 33 |
# File 'lib/rcheck/formatting.rb', line 31 def trunc(*lines) trunc_cols(*trunc_rows(*lines)) end |
#trunc_cols(*lines) ⇒ Object
17 18 |
# File 'lib/rcheck/formatting.rb', line 17 def trunc_cols(*lines) end |
#trunc_rows(*lines) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rcheck/formatting.rb', line 20 def trunc_rows(*lines) if lines.count < max_rows lines else first = lines[0..(max_rows/2)] last = lines[(max_rows/2), -1] removed = lines.count - (first + last).count first + ["< ! #{removed} lines removed... >"] + last end end |