Class: LineReader

Inherits:
Object
  • Object
show all
Includes:
LogUtils::Logging
Defined in:
lib/textutils/reader/line_reader.rb

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ LineReader

Returns a new instance of LineReader.



45
46
47
48
49
50
51
# File 'lib/textutils/reader/line_reader.rb', line 45

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_lineObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/textutils/reader/line_reader.rb', line 53

def each_line
  @data.each_line do |line|

    if 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

    # remove leading and trailing whitespace
    line = line.strip
 
    yield( line )
  end # each lines
end