Class: Linzer::Message::Field::Identifier Private
- Inherits:
-
Struct
- Object
- Struct
- Linzer::Message::Field::Identifier
- Includes:
- IdentifierMethods
- Defined in:
- lib/linzer/message/field.rb,
lib/linzer/message/field.rb,
lib/linzer/message/field.rb,
lib/linzer/message/field/parser.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Defined Under Namespace
Modules: Parser
Instance Attribute Summary collapse
-
#field_name ⇒ Object
Returns the value of attribute field_name.
Attributes included from IdentifierMethods
Class Method Summary collapse
-
.deserialize_components(components) ⇒ Array<String>
private
Deserializes component identifiers back to names.
-
.serialize(component) ⇒ String
private
Serializes a single component identifier.
-
.serialize_components(components) ⇒ Array<String>
private
Serializes an array of component identifiers.
-
.serialize_components_with_field_ids(components) ⇒ Array(Array<String>, Array<Identifier>)
private
Serializes an array of component identifiers, returning both the serialized strings and the FieldId objects for reuse.
Methods included from IdentifierMethods
#derived?, #initialize, #serialize
Instance Attribute Details
#field_name ⇒ Object
Returns the value of attribute field_name
49 50 51 |
# File 'lib/linzer/message/field.rb', line 49 def field_name @field_name end |
Class Method Details
.deserialize_components(components) ⇒ Array<String>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Deserializes component identifiers back to names.
128 129 130 131 132 133 |
# File 'lib/linzer/message/field.rb', line 128 def deserialize_components(components) components.map do |c| item = Starry.parse_item(c) item.parameters.empty? ? item.value : Starry.serialize(item) end end |
.serialize(component) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Serializes a single component identifier.
85 86 87 |
# File 'lib/linzer/message/field.rb', line 85 def serialize(component) new(field_name: component).serialize end |
.serialize_components(components) ⇒ Array<String>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Serializes an array of component identifiers.
92 93 94 |
# File 'lib/linzer/message/field.rb', line 92 def serialize_components(components) components.map(&method(:serialize)) end |
.serialize_components_with_field_ids(components) ⇒ Array(Array<String>, Array<Identifier>)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Serializes an array of component identifiers, returning both the serialized strings and the FieldId objects for reuse.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/linzer/message/field.rb', line 100 def serialize_components_with_field_ids(components) serialized = Array.new(components.size) field_ids = Array.new(components.size) components.each_with_index do |c, i| if c.include?(";") || c.include?('"') # Complex component with parameters or already serialized: # fall back to full Starry parsing fid = new(field_name: c) field_ids[i] = fid serialized[i] = fid.serialize else # Simple component (e.g. "@method", "content-type"): # build the Item and serialized string directly, # bypassing Starry.parse_item + Starry.serialize quoted = "\"#{c}\"" item = Starry::Item.new(c, {}) field_ids[i] = FastIdentifier.new(quoted, item) serialized[i] = quoted end end [serialized, field_ids] end |