Module: I18n::Tasks::Data::Adapter::YamlAdapter
- Defined in:
- lib/i18n/tasks/data/adapter/yaml_adapter.rb
Constant Summary collapse
- EMOJI_REGEX =
/\\u[\da-f]{8}/i.freeze
- TRAILING_SPACE_REGEX =
/ $/.freeze
Class Method Summary collapse
- .dump(tree, options) ⇒ String
-
.parse(str, options) ⇒ Hash
Locale tree.
- .restore_emojis(yaml) ⇒ String
- .strip_trailing_spaces(yaml) ⇒ String
Class Method Details
.dump(tree, options) ⇒ String
23 24 25 |
# File 'lib/i18n/tasks/data/adapter/yaml_adapter.rb', line 23 def dump(tree, ) strip_trailing_spaces(restore_emojis(tree.to_yaml( || {}))) end |
.parse(str, options) ⇒ Hash
Returns locale tree.
13 14 15 16 17 18 19 20 |
# File 'lib/i18n/tasks/data/adapter/yaml_adapter.rb', line 13 def parse(str, ) if YAML.method(:load).arity.abs == 2 YAML.safe_load(str, **( || {}), permitted_classes: [Symbol], aliases: true) else # older jruby and rbx 2.2.7 do not accept options YAML.load(str) end end |
.restore_emojis(yaml) ⇒ String
28 29 30 |
# File 'lib/i18n/tasks/data/adapter/yaml_adapter.rb', line 28 def restore_emojis(yaml) yaml.gsub(EMOJI_REGEX) { |m| [m[-8..].to_i(16)].pack('U') } end |
.strip_trailing_spaces(yaml) ⇒ String
33 34 35 |
# File 'lib/i18n/tasks/data/adapter/yaml_adapter.rb', line 33 def strip_trailing_spaces(yaml) yaml.gsub(TRAILING_SPACE_REGEX, '') end |