Class: Babelyoda::Strings
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#language ⇒ Object
readonly
Returns the value of attribute language.
Attributes inherited from Keyset
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(filename, language) ⇒ Strings
constructor
A new instance of Strings.
- #read ⇒ Object
- #read! ⇒ Object
- #save! ⇒ Object
Methods inherited from Keyset
#debug_counts, #drop_empty!, #empty?, #ensure_languages!, keyset_name, #merge!, #merge_key!, parse_xml, #to_s, #to_strings, #to_xml
Constructor Details
#initialize(filename, language) ⇒ Strings
Returns a new instance of Strings.
41 42 43 44 |
# File 'lib/babelyoda/strings.rb', line 41 def initialize(filename, language) super(Babelyoda::Keyset.keyset_name(filename)) @filename, @language = filename, language end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
38 39 40 |
# File 'lib/babelyoda/strings.rb', line 38 def filename @filename end |
#language ⇒ Object (readonly)
Returns the value of attribute language.
39 40 41 |
# File 'lib/babelyoda/strings.rb', line 39 def language @language end |
Class Method Details
.save_keyset(keyset, filename, language) ⇒ Object
71 72 73 74 75 |
# File 'lib/babelyoda/strings.rb', line 71 def self.save_keyset(keyset, filename, language) strings = self.new(filename, language) strings.merge!(keyset) strings.save! end |
Instance Method Details
#read ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/babelyoda/strings.rb', line 51 def read if File.exist?(@filename) File.open(@filename, read_mode) do |f| lexer = StringsLexer.new parser = StringsParser.new(lexer, @language) parser.parse(f.read) do |localization_key| merge_key!(localization_key) end end end self end |
#read! ⇒ Object
46 47 48 49 |
# File 'lib/babelyoda/strings.rb', line 46 def read! raise ArgumentError.new("File not found: #{filename}") unless File.exist?(@filename) read end |