Class: Tcl::Msgcat::Catalog
- Inherits:
-
Object
- Object
- Tcl::Msgcat::Catalog
- Defined in:
- lib/tcl/msgcat/catalog.rb
Instance Attribute Summary collapse
-
#msgs ⇒ Object
readonly
Returns the value of attribute msgs.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(msgs) ⇒ Catalog
constructor
A new instance of Catalog.
- #merge!(catalog) ⇒ Object
- #to_json(pretty = true) ⇒ Object
Constructor Details
#initialize(msgs) ⇒ Catalog
Returns a new instance of Catalog.
5 6 7 |
# File 'lib/tcl/msgcat/catalog.rb', line 5 def initialize(msgs) @msgs = msgs end |
Instance Attribute Details
#msgs ⇒ Object (readonly)
Returns the value of attribute msgs.
4 5 6 |
# File 'lib/tcl/msgcat/catalog.rb', line 4 def msgs @msgs end |
Class Method Details
.load(file) ⇒ Object
18 19 20 21 |
# File 'lib/tcl/msgcat/catalog.rb', line 18 def self.load(file) msgs = JSON.parse(File.read(file)) Tcl::Msgcat::Catalog.new(msgs) end |
Instance Method Details
#merge!(catalog) ⇒ Object
9 10 11 12 |
# File 'lib/tcl/msgcat/catalog.rb', line 9 def merge!(catalog) merger = proc { |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 } @msgs = catalog.msgs.merge(@msgs, &merger) end |
#to_json(pretty = true) ⇒ Object
14 15 16 |
# File 'lib/tcl/msgcat/catalog.rb', line 14 def to_json(pretty=true) pretty ? JSON.pretty_generate(@msgs) : @msgs.to_json end |