Class: Linzer::Message::Field::Identifier Private

Inherits:
Struct
  • Object
show all
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

Attributes included from IdentifierMethods

#item

Class Method Summary collapse

Methods included from IdentifierMethods

#derived?, #initialize, #serialize

Instance Attribute Details

#field_nameObject

Returns the value of attribute field_name

Returns:

  • (Object)

    the current value of 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.

Parameters:

  • components (Array<String>)

    Serialized identifiers

Returns:

  • (Array<String>)

    Component 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.

Parameters:

  • component (String)

    The component name

Returns:

  • (String)

    The serialized 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.

Parameters:

  • components (Array<String>)

    Component names

Returns:

  • (Array<String>)

    Serialized 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.

Parameters:

  • components (Array<String>)

    Component names

Returns:

  • (Array(Array<String>, Array<Identifier>))

    Serialized strings and FieldId objects



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