Class: SeeingIsBelieving::Binary::AlignFile
- Inherits:
-
Object
- Object
- SeeingIsBelieving::Binary::AlignFile
- Defined in:
- lib/seeing_is_believing/binary/align_file.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#end_line ⇒ Object
Returns the value of attribute end_line.
-
#start_line ⇒ Object
Returns the value of attribute start_line.
Instance Method Summary collapse
-
#initialize(body, start_line, end_line) ⇒ AlignFile
constructor
A new instance of AlignFile.
-
#line_length_for(line_number) ⇒ Object
max line length of the lines to output (exempting comments) + 2 spaces for padding.
- #start_of_data_segment?(line) ⇒ Boolean
Constructor Details
#initialize(body, start_line, end_line) ⇒ AlignFile
Returns a new instance of AlignFile.
6 7 8 |
# File 'lib/seeing_is_believing/binary/align_file.rb', line 6 def initialize(body, start_line, end_line) self.body, self.start_line, self.end_line = body, start_line, end_line end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
4 5 6 |
# File 'lib/seeing_is_believing/binary/align_file.rb', line 4 def body @body end |
#end_line ⇒ Object
Returns the value of attribute end_line.
4 5 6 |
# File 'lib/seeing_is_believing/binary/align_file.rb', line 4 def end_line @end_line end |
#start_line ⇒ Object
Returns the value of attribute start_line.
4 5 6 |
# File 'lib/seeing_is_believing/binary/align_file.rb', line 4 def start_line @start_line end |
Instance Method Details
#line_length_for(line_number) ⇒ Object
max line length of the lines to output (exempting comments) + 2 spaces for padding
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/seeing_is_believing/binary/align_file.rb', line 11 def line_length_for(line_number) @max_source_line_length ||= 2 + body.each_line .map(&:chomp) .select.with_index(1) { |line, index| start_line <= index && index <= end_line } .take_while { |line| not start_of_data_segment? line } .select { |line| not SyntaxAnalyzer.begins_multiline_comment?(line) .. SyntaxAnalyzer.ends_multiline_comment?(line ) } .reject { |line| SyntaxAnalyzer.ends_in_comment? line } .map(&:length) .concat([0]) .max end |
#start_of_data_segment?(line) ⇒ Boolean
23 24 25 |
# File 'lib/seeing_is_believing/binary/align_file.rb', line 23 def start_of_data_segment?(line) SyntaxAnalyzer.begins_data_segment?(line.chomp) end |