Class: Ucode::Parsers::Base::Line
- Inherits:
-
Struct
- Object
- Struct
- Ucode::Parsers::Base::Line
- 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
-
#comment ⇒ Object
Returns the value of attribute comment.
-
#number ⇒ Object
Returns the value of attribute number.
-
#text ⇒ Object
Returns the value of attribute text.
Instance Method Summary collapse
-
#data ⇒ Object
Returns the data part of the line — everything before the first ‘#`, rstripped.
-
#field(n) ⇒ Object
Returns the n-th field (0-based), or nil if out of range.
-
#fields ⇒ Object
Splits the data part on ‘;` into stripped fields.
Instance Attribute Details
#comment ⇒ Object
Returns the value of attribute comment
21 22 23 |
# File 'lib/ucode/parsers/base.rb', line 21 def comment @comment end |
#number ⇒ Object
Returns the value of attribute number
21 22 23 |
# File 'lib/ucode/parsers/base.rb', line 21 def number @number end |
#text ⇒ Object
Returns the value of attribute text
21 22 23 |
# File 'lib/ucode/parsers/base.rb', line 21 def text @text end |
Instance Method Details
#data ⇒ Object
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 |
#fields ⇒ Object
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 |