Class: SimplePoParser::Tokenizer

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

Overview

Split a PO file into single PO message entities (a message is seperated by two newline)

Instance Method Summary collapse

Constructor Details

#initializeTokenizer

Returns a new instance of Tokenizer.



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

def initialize
  @messages = []
end

Instance Method Details

#parse_file(path) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/simple_po_parser/tokenizer.rb', line 10

def parse_file(path)
  file = File.open(path, "r")
  if(file.gets =~ /\r$/)
    # detected windows line ending
    file.close
    file = File.open(path, "rt")
  else
    file.rewind
  end
  file.each_line("\n\n") do |block|
    block.strip! # dont parse empty blocks
    @messages << parse_block(block) if block != ''
  end
  @messages
end