Sha256: 33502b1b838e7159aed9361ba04c1270892ccb9ddedcd6488680f8932b4b6cb0

Contents?: true

Size: 1.18 KB

Versions: 53

Compression:

Stored size: 1.18 KB

Contents

# encoding: UTF-8

module NdrImport
  module NonTabular
    # 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.
    class Line
      attr_accessor :absolute_line_number,
                    :captured_fields,
                    :captures_values,
                    :in_a_record,
                    :record_line_number,
                    :removed

      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

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

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

      def to_s
        @line
      end

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

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

Version data entries

53 entries across 53 versions & 1 rubygems

Version Path
ndr_import-4.1.1 lib/ndr_import/non_tabular/line.rb
ndr_import-4.1.0 lib/ndr_import/non_tabular/line.rb
ndr_import-4.0.1 lib/ndr_import/non_tabular/line.rb
ndr_import-4.0.0 lib/ndr_import/non_tabular/line.rb
ndr_import-3.1.6 lib/ndr_import/non_tabular/line.rb
ndr_import-3.1.5 lib/ndr_import/non_tabular/line.rb
ndr_import-3.1.4 lib/ndr_import/non_tabular/line.rb
ndr_import-3.1.3 lib/ndr_import/non_tabular/line.rb
ndr_import-3.1.2 lib/ndr_import/non_tabular/line.rb
ndr_import-3.1.1 lib/ndr_import/non_tabular/line.rb
ndr_import-3.1.0 lib/ndr_import/non_tabular/line.rb
ndr_import-3.0.1 lib/ndr_import/non_tabular/line.rb
ndr_import-3.0.0 lib/ndr_import/non_tabular/line.rb