Class: Gonzui::CatalogValidator
- Inherits:
-
Object
- Object
- Gonzui::CatalogValidator
- Defined in:
- lib/gonzui/gettext.rb
Instance Attribute Summary collapse
-
#error_messages ⇒ Object
readonly
Returns the value of attribute error_messages.
Instance Method Summary collapse
- #collect_messages(content) ⇒ Object
-
#initialize(source_file_name, messages) ⇒ CatalogValidator
constructor
A new instance of CatalogValidator.
- #ok? ⇒ Boolean
- #read_file_with_numbering(file_name) ⇒ Object
- #validate ⇒ Object
Constructor Details
#initialize(source_file_name, messages) ⇒ CatalogValidator
Returns a new instance of CatalogValidator.
64 65 66 67 68 |
# File 'lib/gonzui/gettext.rb', line 64 def initialize(source_file_name, ) @source_file_name = source_file_name @gettext_catalog = @error_messages = [] end |
Instance Attribute Details
#error_messages ⇒ Object (readonly)
Returns the value of attribute error_messages.
69 70 71 |
# File 'lib/gonzui/gettext.rb', line 69 def @error_messages end |
Instance Method Details
#collect_messages(content) ⇒ Object
80 81 82 83 84 85 86 87 88 |
# File 'lib/gonzui/gettext.rb', line 80 def (content) = [] while content.sub!(/\bN?_\[(\d+)\]\(("(?:\\"|.)*?").*?\)/m, "") lineno = $1.to_i = eval($2) .push([lineno, ]) end end |
#ok? ⇒ Boolean
109 110 111 |
# File 'lib/gonzui/gettext.rb', line 109 def ok? @error_messages.empty? end |
#read_file_with_numbering(file_name) ⇒ Object
71 72 73 74 75 76 77 78 |
# File 'lib/gonzui/gettext.rb', line 71 def read_file_with_numbering(file_name) content = '' File.open(file_name).each_with_index {|line, idx| lineno = idx + 1 content << line.gsub(/\bN?_\(/, "_[#{lineno}](") } content end |
#validate ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/gonzui/gettext.rb', line 90 def validate @gettext_catalog or return content = read_file_with_numbering(@source_file_name) = (content) .each {|lineno, | = @gettext_catalog[] if not = sprintf("%s:%d: %s", @source_file_name, lineno, .inspect) @error_messages.push() elsif .count("%") != .count("%") = sprintf("%s:%d: %s => # of %% mismatch.", @source_file_name, lineno, .inspect, ) @error_messages.push() end } end |