Class: ParamsReady::Marshaller::TupleMarshallers::StringMarshaller

Inherits:
Object
  • Object
show all
Includes:
AbstractMarshaller
Defined in:
lib/params_ready/marshaller/tuple_marshallers.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AbstractMarshaller

#marshal, marshal_fields

Constructor Details

#initialize(separator) ⇒ StringMarshaller

Returns a new instance of StringMarshaller.



75
76
77
# File 'lib/params_ready/marshaller/tuple_marshallers.rb', line 75

def initialize(separator)
  @separator = separator.to_s.freeze
end

Instance Attribute Details

#separatorObject (readonly)

Returns the value of attribute separator.



68
69
70
# File 'lib/params_ready/marshaller/tuple_marshallers.rb', line 68

def separator
  @separator
end

Class Method Details

.instance(separator:) ⇒ Object



70
71
72
73
# File 'lib/params_ready/marshaller/tuple_marshallers.rb', line 70

def self.instance(separator:)
  instance = new separator
  [String, instance.freeze]
end

Instance Method Details

#canonicalize(definition, string, context, validator) ⇒ Object



79
80
81
82
# File 'lib/params_ready/marshaller/tuple_marshallers.rb', line 79

def canonicalize(definition, string, context, validator)
  array = string.split(separator)
  ArrayMarshaller.canonicalize(definition, array, context, validator)
end

#do_marshal(fields, _) ⇒ Object



84
85
86
# File 'lib/params_ready/marshaller/tuple_marshallers.rb', line 84

def do_marshal(fields, _)
  fields.join(separator)
end