Class: LineReader
- Inherits:
-
Object
- Object
- LineReader
- Includes:
- LogUtils::Logging
- Defined in:
- lib/textutils/reader/line_reader.rb
Instance Method Summary collapse
- #each_line ⇒ Object
-
#initialize(path) ⇒ LineReader
constructor
A new instance of LineReader.
Constructor Details
#initialize(path) ⇒ LineReader
Returns a new instance of LineReader.
48 49 50 51 52 53 54 |
# File 'lib/textutils/reader/line_reader.rb', line 48 def initialize( path ) @path = path ## nb: assume/enfore utf-8 encoding (with or without BOM - byte order mark) ## - see textutils/utils.rb @data = File.read_utf8( @path ) end |
Instance Method Details
#each_line ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/textutils/reader/line_reader.rb', line 56 def each_line @data.each_line do |line| # comments allow: # 1) ##### (shell/ruby style) # 2) -- comment here (haskel/?? style) # 3) % comment here (tex/latex style) if line =~ /^\s*#/ || line =~ /^\s*--/ || line =~ /^\s*%/ # skip komments and do NOT copy to result (keep comments secret!) logger.debug 'skipping comment line' next end if line =~ /^\s*$/ # kommentar oder leerzeile überspringen logger.debug 'skipping blank line' next end # pass 1) remove possible trailing eol comment ## e.g -> nyc, New York # Sample EOL Comment Here (with or without commas,,,,) ## becomes -> nyc, New York line = line.sub( /\s+#.+$/, '' ) # pass 2) remove leading and trailing whitespace line = line.strip yield( line ) end # each lines end |