Class: GetText::GtkBuilderUIDefinitionsParser

Inherits:
Object
  • Object
show all
Defined in:
lib/gettext/tools/parser/gtk_builder_ui_definitions.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, options = {}) ⇒ GtkBuilderUIDefinitionsParser

Returns a new instance of GtkBuilderUIDefinitionsParser.



53
54
55
56
# File 'lib/gettext/tools/parser/gtk_builder_ui_definitions.rb', line 53

def initialize(path, options={})
  @path = path
  @options = options
end

Class Method Details

.init(config) ⇒ Object

Sets some preferences to parse GtkBuilder UI definitions files.

  • config: a Hash of the config. It can takes some values below:
    • :extnames: An Array of target files extension. Default is [".ui"].


34
35
36
37
38
# File 'lib/gettext/tools/parser/gtk_builder_ui_definitions.rb', line 34

def init(config)
  config.each do |k, v|
    @config[k] = v
  end
end

.parse(path, options = {}) ⇒ Object



47
48
49
50
# File 'lib/gettext/tools/parser/gtk_builder_ui_definitions.rb', line 47

def parse(path, options={})
  parser = new(path, options)
  parser.parse
end

.target?(file) ⇒ Boolean

:nodoc:

Returns:

  • (Boolean)


40
41
42
43
44
45
# File 'lib/gettext/tools/parser/gtk_builder_ui_definitions.rb', line 40

def target?(file) # :nodoc:
  @config[:extnames].each do |extname|
    return true if File.extname(file) == extname
  end
  false
end

Instance Method Details

#parseObject

:nodoc:



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/gettext/tools/parser/gtk_builder_ui_definitions.rb', line 58

def parse # :nodoc:
  File.open(@path) do |file|
    po = []
    start_line_no = nil
    property = nil
    file.each_line do |line|
      case line
      when /<property/
        property = $POSTMATCH
        start_line_no = file.lineno
        if /<\/property>/ =~ property
          property << $PREMATCH
          add_po_entry(po, property, start_line_no)
          property = nil
        end
      when /<\/property>/
        property << $PREMATCH
        add_po_entry(po, property, start_line_no)
        property = nil
      else
        property << line if property
      end
    end
    po
  end
end