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_number
land in the code section of the file? (which includes the — separator). -
#in_csv_section?(line_number) ⇒ T::Boolean
Does the given
line_number
land in the CSV section of the file?. -
#initialize(filename, input: nil) ⇒ SourceCode
constructor
A new instance of SourceCode.
Constructor Details
#initialize(filename, input: nil) ⇒ SourceCode
Returns a new instance of SourceCode.
26 27 28 29 30 31 32 33 34 |
# File 'lib/csv_plus_plus/source_code.rb', line 26 def initialize(filename, input: nil) @filename = ::T.let(::Pathname.new(filename), ::Pathname) @input = ::T.let(input || read_file, ::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)
42 43 44 |
# File 'lib/csv_plus_plus/source_code.rb', line 42 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?
52 53 54 |
# File 'lib/csv_plus_plus/source_code.rb', line 52 def in_csv_section?(line_number) line_number > @length_of_code_section end |