Class: SeeingIsBelieving::Binary::AlignLine

Inherits:
Object
  • Object
show all
Defined in:
lib/seeing_is_believing/binary/align_line.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#bodyObject

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_lengthsObject



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