Module: IphoneParser

Defined in:
lib/iphone_parser.rb,
lib/iphone_parser/parse.rb,
lib/iphone_parser/version.rb,
lib/iphone_parser/ast_nodes.rb,
lib/iphone_parser/exceptions.rb

Defined Under Namespace

Classes: Comment, Entry, InvalidEntry, Label, ParseError, Text

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.create_resource_file(entries) ⇒ Object

Raises:



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/iphone_parser.rb', line 22

def self.create_resource_file(entries)
  raise InvalidEntry unless entries.kind_of? Hash

  entries.reduce("") do |out, entry|
    label = entry[0]
    text_and_comment = entry[1]
    raise InvalidEntry unless text_and_comment.kind_of?(Hash)
    text = text_and_comment[:text]

    raise InvalidEntry if !label.kind_of?(String) || !text.kind_of?(String)

    out += "\"#{label}\"=\"#{text_and_comment[:text]}\";"
  end
end

.parseObject



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/iphone_parser.rb', line 8

def self.parse(file_content)
  @@parser ||= IphoneResourceFileParser.new
  ast = @@parser.parse(file_content)
  if ast
    generate_hash(ast)
  else
    @@parser.failure_reason =~ /^(Expected .+) after/m
    error = "#{$1.gsub("\n", '$NEWLINE')}:" + "\n"
    error += file_content.lines.to_a[@@parser.failure_line - 1]
    error += "#{'~' * (@@parser.failure_column - 1)}^"
    raise ParseError, error
  end
end