Class: Txbr::StringsManifest
- Inherits:
-
Object
- Object
- Txbr::StringsManifest
- Includes:
- Enumerable
- Defined in:
- lib/txbr/strings_manifest.rb
Instance Method Summary collapse
- #add(path, value) ⇒ Object
- #each(&block) ⇒ Object (also: #each_string)
- #empty? ⇒ Boolean
-
#initialize ⇒ StringsManifest
constructor
A new instance of StringsManifest.
- #merge(other_manifest) ⇒ Object
- #merge!(other_manifest) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize ⇒ StringsManifest
5 6 7 |
# File 'lib/txbr/strings_manifest.rb', line 5 def initialize @strings ||= {} end |
Instance Method Details
#add(path, value) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/txbr/strings_manifest.rb', line 9 def add(path, value) root = path[0...-1].inject(@strings) do |ret, key| ret[key] ||= {} end root[path.last] = value end |
#each(&block) ⇒ Object Also known as: each_string
34 35 36 37 |
# File 'lib/txbr/strings_manifest.rb', line 34 def each(&block) return to_enum(__method__) unless block_given? each_helper(@strings, [], &block) end |
#empty? ⇒ Boolean
41 42 43 |
# File 'lib/txbr/strings_manifest.rb', line 41 def empty? @strings.empty? end |
#merge(other_manifest) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/txbr/strings_manifest.rb', line 17 def merge(other_manifest) self.class.new.tap do |new_manifest| new_manifest.merge!(self) new_manifest.merge!(other_manifest) end end |
#merge!(other_manifest) ⇒ Object
24 25 26 27 28 |
# File 'lib/txbr/strings_manifest.rb', line 24 def merge!(other_manifest) other_manifest.each_string do |path, value| add(path, value) end end |
#to_h ⇒ Object
30 31 32 |
# File 'lib/txbr/strings_manifest.rb', line 30 def to_h @strings end |