Module: Postmark::HashHelper
Instance Method Summary collapse
Instance Method Details
#to_postmark(object, options = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/postmark/helpers/hash_helper.rb', line 6 def to_postmark(object, = {}) deep = .fetch(:deep, false) case object when Hash object.reduce({}) do |m, (k, v)| m.tap do |h| h[Inflector.to_postmark(k)] = deep ? to_postmark(v, ) : v end end when Array deep ? object.map { |v| to_postmark(v, ) } : object else object end end |
#to_ruby(object, options = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/postmark/helpers/hash_helper.rb', line 23 def to_ruby(object, = {}) compatible = .fetch(:compatible, false) deep = .fetch(:deep, false) case object when Hash object.reduce({}) do |m, (k, v)| m.tap do |h| h[Inflector.to_ruby(k)] = deep ? to_ruby(v, ) : v end end.tap do |result| if compatible result.merge!(object) enhance_with_compatibility_warning(result) end end when Array deep ? object.map { |v| to_ruby(v, ) } : object else object end end |