Class: PoParser::Tokenizer

Inherits:
Object
  • Object
show all
Defined in:
lib/poparser/tokenizer.rb

Overview

Feed each block of PO file to Parser.

Instance Method Summary collapse

Constructor Details

#initializeTokenizer

Returns a new instance of Tokenizer.



6
7
8
9
# File 'lib/poparser/tokenizer.rb', line 6

def initialize
  @parser = Parser.new
  @po     = Po.new
end

Instance Method Details

#extract_entries(path) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/poparser/tokenizer.rb', line 11

def extract_entries(path)
  @po.path = path
  block = ''
  File.open(path, 'r') do |f|
    f.each_line do |line|
      if line.match(/^\n$/)
        @po << parse_block(block)
        block = ''
      elsif f.eof?
        block += line
        @po << parse_block(block)
      else
        block += line
      end
    end
  end
  @po
end