Class: Ucode::Parsers::Base::Line

Inherits:
Struct
  • Object
show all
Defined in:
lib/ucode/parsers/base.rb

Overview

One physical line from the source file, post-filter (blanks and comment-only lines are skipped before yielding).

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#commentObject

Returns the value of attribute comment

Returns:

  • (Object)

    the current value of comment



21
22
23
# File 'lib/ucode/parsers/base.rb', line 21

def comment
  @comment
end

#numberObject

Returns the value of attribute number

Returns:

  • (Object)

    the current value of number



21
22
23
# File 'lib/ucode/parsers/base.rb', line 21

def number
  @number
end

#textObject

Returns the value of attribute text

Returns:

  • (Object)

    the current value of text



21
22
23
# File 'lib/ucode/parsers/base.rb', line 21

def text
  @text
end

Instance Method Details

#dataObject

Returns the data part of the line — everything before the first ‘#`, rstripped. For lines with no comment this is just the text.



24
25
26
27
# File 'lib/ucode/parsers/base.rb', line 24

def data
  idx = text.index("#")
  idx.nil? ? text : text[0...idx].rstrip
end

#field(n) ⇒ Object

Returns the n-th field (0-based), or nil if out of range.



35
36
37
# File 'lib/ucode/parsers/base.rb', line 35

def field(n)
  fields[n]
end

#fieldsObject

Splits the data part on ‘;` into stripped fields.



30
31
32
# File 'lib/ucode/parsers/base.rb', line 30

def fields
  data.split(";").map(&:strip)
end