Class: SeeingIsBelieving::Binary::FormatComment
- Inherits:
-
Object
- Object
- SeeingIsBelieving::Binary::FormatComment
- Defined in:
- lib/seeing_is_believing/binary/format_comment.rb
Overview
not sure I like this name, it formats comments that show results e.g. “# => [1, 2, 3]”
line_length is the length of the line this comment is being appended to
For examples of what the options are, and how they all fit together, see spec/binary/format_comment.rb
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(line_length, separator, result, options) ⇒ FormatComment
constructor
A new instance of FormatComment.
Constructor Details
#initialize(line_length, separator, result, options) ⇒ FormatComment
Returns a new instance of FormatComment.
19 20 21 22 23 24 |
# File 'lib/seeing_is_believing/binary/format_comment.rb', line 19 def initialize(line_length, separator, result, ) self.line_length = line_length self.separator = separator self.result = result self. = end |
Class Method Details
.call(*args) ⇒ Object
15 16 17 |
# File 'lib/seeing_is_believing/binary/format_comment.rb', line 15 def self.call(*args) new(*args).call end |
Instance Method Details
#call ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/seeing_is_believing/binary/format_comment.rb', line 26 def call @formatted ||= begin formatted = escape_non_printable result, chars_not_to_escape formatted = truncate "#{separator}#{formatted}", max_result_length formatted = "#{' '*padding_length}#{formatted}" formatted = truncate formatted, max_line_length formatted = '' unless formatted.sub(/^ */, '').start_with? separator formatted end end |