Module: PseudoL10n::Transformer
- Defined in:
- lib/pseudo_l10n/transformer.rb
Constant Summary collapse
- MARKER =
"√"
- TEMPLATE =
"%{marker}%{msg}%{marker}"
- ESCAPE_PATTERN =
Regexp.new( "(#{ ["<.*?>", "{{.*?}}", "%{.*?}", "https?://\\S+", "&\\S*?;"].join("|") })" )
Class Method Summary collapse
- .call(original) ⇒ Object
- .half_to_full_width(string) ⇒ Object
- .lengthen_string(string) ⇒ Object
- .mark_string(string) ⇒ Object
Class Method Details
.call(original) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/pseudo_l10n/transformer.rb', line 17 def call(original) if original.is_a?(Hash) original.transform_values { |value| call(value) } elsif original.is_a?(Array) original.map { |value| call(value) } elsif original.is_a?(String) result = original result = lengthen_string(result) mark_string(result) else original end end |
.half_to_full_width(string) ⇒ Object
46 47 48 |
# File 'lib/pseudo_l10n/transformer.rb', line 46 def half_to_full_width(string) string.tr("0-9a-zA-Z", "0-9a-zA-Z") end |
.lengthen_string(string) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/pseudo_l10n/transformer.rb', line 35 def lengthen_string(string) parts = string .split(ESCAPE_PATTERN) .map do |part| part.match?(ESCAPE_PATTERN) ? part : half_to_full_width(part) end parts.join end |