Class: SeeingIsBelieving::Binary::AlignLine
- Inherits:
-
Object
- Object
- SeeingIsBelieving::Binary::AlignLine
- Defined in:
- lib/seeing_is_believing/binary/align_line.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
Instance Method Summary collapse
-
#initialize(body) ⇒ AlignLine
constructor
A new instance of AlignLine.
-
#line_length_for(line_number) ⇒ Object
length of the line + 2 spaces for padding.
- #line_lengths ⇒ Object
Constructor Details
#initialize(body) ⇒ AlignLine
Returns a new instance of AlignLine.
6 7 8 |
# File 'lib/seeing_is_believing/binary/align_line.rb', line 6 def initialize(body) self.body = body end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
4 5 6 |
# File 'lib/seeing_is_believing/binary/align_line.rb', line 4 def body @body end |
Instance Method Details
#line_length_for(line_number) ⇒ Object
length of the line + 2 spaces for padding
11 12 13 |
# File 'lib/seeing_is_believing/binary/align_line.rb', line 11 def line_length_for(line_number) line_lengths[line_number] end |
#line_lengths ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/seeing_is_believing/binary/align_line.rb', line 15 def line_lengths @line_lengths ||= Hash[ body.each_line .map(&:chomp) .each .with_index(1) .map { |line, index| [index, line.length+2] } ] end |