Class: CinnamonSerial::Resolver
- Inherits:
-
Object
- Object
- CinnamonSerial::Resolver
- Defined in:
- lib/cinnamon_serial/resolver.rb
Overview
Class that allows an engineer to specify what to do about mapping a key for a serializer.
Instance Attribute Summary collapse
-
#as ⇒ Object
Returns the value of attribute as.
-
#blank ⇒ Object
Returns the value of attribute blank.
-
#false_alias ⇒ Object
Returns the value of attribute false_alias.
-
#for ⇒ Object
Returns the value of attribute for.
-
#manual ⇒ Object
Returns the value of attribute manual.
-
#mask ⇒ Object
Returns the value of attribute mask.
-
#mask_char ⇒ Object
Returns the value of attribute mask_char.
-
#mask_len ⇒ Object
Returns the value of attribute mask_len.
-
#method ⇒ Object
Returns the value of attribute method.
-
#null ⇒ Object
Returns the value of attribute null.
-
#percent ⇒ Object
Returns the value of attribute percent.
-
#present ⇒ Object
Returns the value of attribute present.
-
#through ⇒ Object
Returns the value of attribute through.
-
#transform ⇒ Object
Returns the value of attribute transform.
-
#true_alias ⇒ Object
Returns the value of attribute true_alias.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Resolver
constructor
A new instance of Resolver.
- #resolve(presenter, key) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Resolver
Returns a new instance of Resolver.
29 30 31 32 33 34 35 36 37 |
# File 'lib/cinnamon_serial/resolver.rb', line 29 def initialize( = {}) @option_keys = .keys.map(&:to_s).to_set .each do |key, value| raise ArgumentError, "Illegal option: #{key}" unless respond_to?(key) send("#{key}=", value) end end |
Instance Attribute Details
#as ⇒ Object
Returns the value of attribute as.
13 14 15 |
# File 'lib/cinnamon_serial/resolver.rb', line 13 def as @as end |
#blank ⇒ Object
Returns the value of attribute blank.
13 14 15 |
# File 'lib/cinnamon_serial/resolver.rb', line 13 def blank @blank end |
#false_alias ⇒ Object
Returns the value of attribute false_alias.
13 14 15 |
# File 'lib/cinnamon_serial/resolver.rb', line 13 def false_alias @false_alias end |
#for ⇒ Object
Returns the value of attribute for.
13 14 15 |
# File 'lib/cinnamon_serial/resolver.rb', line 13 def for @for end |
#manual ⇒ Object
Returns the value of attribute manual.
13 14 15 |
# File 'lib/cinnamon_serial/resolver.rb', line 13 def manual @manual end |
#mask ⇒ Object
Returns the value of attribute mask.
13 14 15 |
# File 'lib/cinnamon_serial/resolver.rb', line 13 def mask @mask end |
#mask_char ⇒ Object
Returns the value of attribute mask_char.
13 14 15 |
# File 'lib/cinnamon_serial/resolver.rb', line 13 def mask_char @mask_char end |
#mask_len ⇒ Object
Returns the value of attribute mask_len.
13 14 15 |
# File 'lib/cinnamon_serial/resolver.rb', line 13 def mask_len @mask_len end |
#method ⇒ Object
Returns the value of attribute method.
13 14 15 |
# File 'lib/cinnamon_serial/resolver.rb', line 13 def method @method end |
#null ⇒ Object
Returns the value of attribute null.
13 14 15 |
# File 'lib/cinnamon_serial/resolver.rb', line 13 def null @null end |
#percent ⇒ Object
Returns the value of attribute percent.
13 14 15 |
# File 'lib/cinnamon_serial/resolver.rb', line 13 def percent @percent end |
#present ⇒ Object
Returns the value of attribute present.
13 14 15 |
# File 'lib/cinnamon_serial/resolver.rb', line 13 def present @present end |
#through ⇒ Object
Returns the value of attribute through.
13 14 15 |
# File 'lib/cinnamon_serial/resolver.rb', line 13 def through @through end |
#transform ⇒ Object
Returns the value of attribute transform.
13 14 15 |
# File 'lib/cinnamon_serial/resolver.rb', line 13 def transform @transform end |
#true_alias ⇒ Object
Returns the value of attribute true_alias.
13 14 15 |
# File 'lib/cinnamon_serial/resolver.rb', line 13 def true_alias @true_alias end |
Instance Method Details
#resolve(presenter, key) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/cinnamon_serial/resolver.rb', line 39 def resolve(presenter, key) raise ArgumentError, 'Presenter is required' unless presenter return if manual # Get the value value = resolve_value(presenter, key) # Transform the value value = resolve_transform(presenter, key, value) value = resolve_alias(value) value = resolve_as(presenter, value) # Format the value value = resolve_percent(value) resolve_mask(value) end |