Class: CSVPlusPlus::SourceCode
- Inherits:
-
Object
- Object
- CSVPlusPlus::SourceCode
- Extended by:
- T::Sig
- Defined in:
- lib/csv_plus_plus/source_code.rb
Overview
Information about the unparsed source code
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#length_of_code_section ⇒ Object
readonly
Returns the value of attribute length_of_code_section.
-
#length_of_csv_section ⇒ Object
readonly
Returns the value of attribute length_of_csv_section.
-
#length_of_file ⇒ Object
readonly
Returns the value of attribute length_of_file.
Instance Method Summary collapse
-
#in_code_section?(line_number) ⇒ T::Boolean
Does the given
line_numberland in the code section of the file? (which includes the — separator). -
#in_csv_section?(line_number) ⇒ T::Boolean
Does the given
line_numberland in the CSV section of the file?. -
#initialize(input:, filename: nil) ⇒ SourceCode
constructor
A new instance of SourceCode.
Constructor Details
#initialize(input:, filename: nil) ⇒ SourceCode
Returns a new instance of SourceCode.
28 29 30 31 32 33 34 35 36 |
# File 'lib/csv_plus_plus/source_code.rb', line 28 def initialize(input:, filename: nil) @input = input @filename = ::T.let(filename || 'stdin', ::String) lines = input.split(/[\r\n]/) @length_of_file = ::T.let(lines.length, ::Integer) @length_of_code_section = ::T.let(count_code_section_lines(lines), ::Integer) @length_of_csv_section = ::T.let(@length_of_file - @length_of_code_section, ::Integer) end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
13 14 15 |
# File 'lib/csv_plus_plus/source_code.rb', line 13 def filename @filename end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
10 11 12 |
# File 'lib/csv_plus_plus/source_code.rb', line 10 def input @input end |
#length_of_code_section ⇒ Object (readonly)
Returns the value of attribute length_of_code_section.
19 20 21 |
# File 'lib/csv_plus_plus/source_code.rb', line 19 def length_of_code_section @length_of_code_section end |
#length_of_csv_section ⇒ Object (readonly)
Returns the value of attribute length_of_csv_section.
16 17 18 |
# File 'lib/csv_plus_plus/source_code.rb', line 16 def length_of_csv_section @length_of_csv_section end |
#length_of_file ⇒ Object (readonly)
Returns the value of attribute length_of_file.
22 23 24 |
# File 'lib/csv_plus_plus/source_code.rb', line 22 def length_of_file @length_of_file end |
Instance Method Details
#in_code_section?(line_number) ⇒ T::Boolean
Does the given line_number land in the code section of the file? (which includes the — separator)
44 45 46 |
# File 'lib/csv_plus_plus/source_code.rb', line 44 def in_code_section?(line_number) line_number <= @length_of_code_section end |
#in_csv_section?(line_number) ⇒ T::Boolean
Does the given line_number land in the CSV section of the file?
54 55 56 |
# File 'lib/csv_plus_plus/source_code.rb', line 54 def in_csv_section?(line_number) line_number > @length_of_code_section end |