class Shrink::Wrap::Property::Translation
Constants
- ATTRIBUTES
Public Class Methods
new(opts = {})
click to toggle source
# File lib/shrink/wrap/property/translation.rb, line 17 def initialize(opts = {}) self.allow_nil = opts.fetch(:allow_nil) { false } self.default = opts[:default] self.from = opts.fetch(:from) end
Public Instance Methods
translate(opts = {})
click to toggle source
# File lib/shrink/wrap/property/translation.rb, line 23 def translate(opts = {}) ensure_type!(Hash, opts) translate_single(opts) end
Private Instance Methods
key_error!(opts)
click to toggle source
# File lib/shrink/wrap/property/translation.rb, line 38 def key_error!(opts) pretty_hash = StringIO.new PP.pp(opts, pretty_hash) raise KeyError, <<~MSG Key not found `#{from.inspect}` Searching: #{pretty_hash.string} MSG end
translate_single(opts)
click to toggle source
# File lib/shrink/wrap/property/translation.rb, line 30 def translate_single(opts) return opts[from] if allow_nil return opts.fetch(from) { key_error!(opts) } if default.nil? ensure_callable!(default, 0) opts[from] || default.call end