Class: CSVPlusPlus::SourceCode

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/csv_plus_plus/source_code.rb

Overview

Information about the unparsed source code

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, input: nil) ⇒ SourceCode

Returns a new instance of SourceCode.

Parameters:

  • filename (::String)

    The name of the file the source came from.



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

#filenameObject (readonly)

Returns the value of attribute filename.



13
14
15
# File 'lib/csv_plus_plus/source_code.rb', line 13

def filename
  @filename
end

#inputObject (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_sectionObject (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_sectionObject (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_fileObject (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)

Parameters:

  • line_number (Integer)

Returns:

  • (T::Boolean)


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?

Parameters:

  • line_number (Integer)

Returns:

  • (T::Boolean)


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