Class: ParamsReady::Marshaller::ArrayMarshallers::StringMarshaller
- Inherits:
-
Object
- Object
- ParamsReady::Marshaller::ArrayMarshallers::StringMarshaller
- Includes:
- AbstractMarshaller
- Defined in:
- lib/params_ready/marshaller/array_marshallers.rb
Instance Attribute Summary collapse
-
#separator ⇒ Object
readonly
Returns the value of attribute separator.
Class Method Summary collapse
Instance Method Summary collapse
- #canonicalize(definition, string, context, validator) ⇒ Object
- #do_marshal(array, _, _) ⇒ Object
-
#initialize(separator, split_pattern) ⇒ StringMarshaller
constructor
A new instance of StringMarshaller.
- #split_pattern ⇒ Object
Methods included from AbstractMarshaller
Constructor Details
#initialize(separator, split_pattern) ⇒ StringMarshaller
Returns a new instance of StringMarshaller.
99 100 101 102 |
# File 'lib/params_ready/marshaller/array_marshallers.rb', line 99 def initialize(separator, split_pattern) @separator = separator.to_s.freeze @split_pattern = split_pattern.freeze end |
Instance Attribute Details
#separator ⇒ Object (readonly)
Returns the value of attribute separator.
92 93 94 |
# File 'lib/params_ready/marshaller/array_marshallers.rb', line 92 def separator @separator end |
Class Method Details
.instance(separator:, split_pattern: nil) ⇒ Object
94 95 96 97 |
# File 'lib/params_ready/marshaller/array_marshallers.rb', line 94 def self.instance(separator:, split_pattern: nil) instance = new separator, split_pattern [String, instance.freeze] end |
Instance Method Details
#canonicalize(definition, string, context, validator) ⇒ Object
108 109 110 111 |
# File 'lib/params_ready/marshaller/array_marshallers.rb', line 108 def canonicalize(definition, string, context, validator) array = string.split(split_pattern).map(&:strip).reject(&:empty?) ArrayMarshaller.canonicalize(definition, array, context, validator) end |
#do_marshal(array, _, _) ⇒ Object
113 114 115 |
# File 'lib/params_ready/marshaller/array_marshallers.rb', line 113 def do_marshal(array, _, _) array.join(separator) end |
#split_pattern ⇒ Object
104 105 106 |
# File 'lib/params_ready/marshaller/array_marshallers.rb', line 104 def split_pattern @split_pattern || @separator end |