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.
91 92 93 94 95 96 97 |
# File 'lib/textutils/reader/line_reader.rb', line 91 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
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/textutils/reader/line_reader.rb', line 99 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 |