Class: NdrImport::NonTabular::Line

Inherits:
Object
  • Object
show all
Defined in:
lib/ndr_import/non_tabular/line.rb

Overview

This class behaves like a string and is used instead of the each source line of text. It allows us to contain additional information relating to the use of the line e.g. is the line within a record or for which fields the line has been used to capture a value.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(line, absolute_line_number) ⇒ Line

Returns a new instance of Line.



16
17
18
19
20
21
22
23
# File 'lib/ndr_import/non_tabular/line.rb', line 16

def initialize(line, absolute_line_number)
  @line = line.rstrip
  @absolute_line_number = absolute_line_number
  @in_a_record = false
  @removed = false
  @captured_fields = []
  @captures_values = []
end

Instance Attribute Details

#absolute_line_numberObject

Returns the value of attribute absolute_line_number.



9
10
11
# File 'lib/ndr_import/non_tabular/line.rb', line 9

def absolute_line_number
  @absolute_line_number
end

#captured_fieldsObject

Returns the value of attribute captured_fields.



9
10
11
# File 'lib/ndr_import/non_tabular/line.rb', line 9

def captured_fields
  @captured_fields
end

#captures_valuesObject

Returns the value of attribute captures_values.



9
10
11
# File 'lib/ndr_import/non_tabular/line.rb', line 9

def captures_values
  @captures_values
end

#in_a_recordObject

Returns the value of attribute in_a_record.



9
10
11
# File 'lib/ndr_import/non_tabular/line.rb', line 9

def in_a_record
  @in_a_record
end

#record_line_numberObject

Returns the value of attribute record_line_number.



9
10
11
# File 'lib/ndr_import/non_tabular/line.rb', line 9

def record_line_number
  @record_line_number
end

#removedObject

Returns the value of attribute removed.



9
10
11
# File 'lib/ndr_import/non_tabular/line.rb', line 9

def removed
  @removed
end

Instance Method Details

#=~(other) ⇒ Object



25
26
27
# File 'lib/ndr_import/non_tabular/line.rb', line 25

def =~(other)
  @line =~ other
end

#captured_for(field) ⇒ Object



37
38
39
# File 'lib/ndr_import/non_tabular/line.rb', line 37

def captured_for(field)
  @captured_fields << field if field && !@captured_fields.include?(field)
end

#match(*args) ⇒ Object



29
30
31
# File 'lib/ndr_import/non_tabular/line.rb', line 29

def match(*args)
  @line.match(*args)
end

#matches_for(field, value) ⇒ Object



41
42
43
# File 'lib/ndr_import/non_tabular/line.rb', line 41

def matches_for(field, value)
  @captures_values << [field, value]
end

#to_sObject



33
34
35
# File 'lib/ndr_import/non_tabular/line.rb', line 33

def to_s
  @line
end