Module: Linzer::Message::Field::Identifier::Parser Private

Extended by:
Parser
Included in:
Parser
Defined in:
lib/linzer/message/field/parser.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Parses component identifier strings into structured items.

Handles various formats:

  • Simple names: ‘“content-type”`

  • Derived components: ‘“@method”`

  • With parameters: ‘“content-type”;bs`, `“example-dict”;key=“a”`

  • Already serialized: ‘’“content-type”‘`

Instance Method Summary collapse

Instance Method Details

#parse(field_name) ⇒ Starry::Item

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.

Parses a field name into a structured item.

Parameters:

  • field_name (String)

    The component identifier string

Returns:

  • (Starry::Item)

    The parsed structured field item

Raises:

  • (Error)

    If the field name cannot be parsed



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/linzer/message/field/parser.rb', line 24

def parse(field_name)
  case
  when field_name.match?(/";/), field_name.start_with?('"')
    Starry.parse_item(field_name)
  when field_name.match?(/;/)
    parse_unserialized_input(field_name)
  when field_name.start_with?("@"), field_name.match?(/^[a-z]/)
    Starry.parse_item(Starry.serialize(field_name))
  else
    raise Error, "Invalid component identifier: '#{field_name}'!"
  end
rescue Starry::ParseError => ex
  parse_error = "Failed to parse component identifier: '#{field_name}'!"
  raise Error, parse_error, cause: ex
end