Class: GetText::GtkBuilderUIDefinitionsParser
- Inherits:
-
Object
- Object
- GetText::GtkBuilderUIDefinitionsParser
- Defined in:
- lib/gettext/tools/parser/gtk_builder_ui_definitions.rb
Class Method Summary collapse
-
.init(config) ⇒ Object
Sets some preferences to parse GtkBuilder UI definitions files.
- .parse(path, options = {}) ⇒ Object
-
.target?(file) ⇒ Boolean
:nodoc:.
Instance Method Summary collapse
-
#initialize(path, options = {}) ⇒ GtkBuilderUIDefinitionsParser
constructor
A new instance of GtkBuilderUIDefinitionsParser.
-
#parse ⇒ Object
:nodoc:.
Constructor Details
#initialize(path, options = {}) ⇒ GtkBuilderUIDefinitionsParser
Returns a new instance of GtkBuilderUIDefinitionsParser.
56 57 58 59 |
# File 'lib/gettext/tools/parser/gtk_builder_ui_definitions.rb', line 56 def initialize(path, ={}) @path = path @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", ".glade"].
35 36 37 38 39 |
# File 'lib/gettext/tools/parser/gtk_builder_ui_definitions.rb', line 35 def init(config) config.each do |k, v| @config[k] = v end end |
.parse(path, options = {}) ⇒ Object
50 51 52 53 |
# File 'lib/gettext/tools/parser/gtk_builder_ui_definitions.rb', line 50 def parse(path, ={}) parser = new(path, ) parser.parse end |
.target?(file) ⇒ Boolean
:nodoc:
41 42 43 44 45 46 47 48 |
# File 'lib/gettext/tools/parser/gtk_builder_ui_definitions.rb', line 41 def target?(file) # :nodoc: @config[:extnames].each do |extname| next unless File.extname(file) == extname next unless File.read(file).include?("<interface>") return true end false end |
Instance Method Details
#parse ⇒ Object
:nodoc:
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/gettext/tools/parser/gtk_builder_ui_definitions.rb', line 61 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 |