Class: RFC::Web::Link::Parsers::Pair
- Inherits:
-
Object
- Object
- RFC::Web::Link::Parsers::Pair
- Defined in:
- lib/rfc/web/link/parsers/pair.rb
Overview
Parses a header key/value pair into a record.
Instance Method Summary collapse
- #call(text, root_uri:) ⇒ Object
-
#initialize(split_pattern: /(?<target>=)|(?<extended>\*=)/, decoder: Decoder.new, model: Models::Pair) ⇒ Pair
constructor
A new instance of Pair.
Constructor Details
#initialize(split_pattern: /(?<target>=)|(?<extended>\*=)/, decoder: Decoder.new, model: Models::Pair) ⇒ Pair
Returns a new instance of Pair.
9 10 11 12 13 14 15 |
# File 'lib/rfc/web/link/parsers/pair.rb', line 9 def initialize split_pattern: /(?<target>=)|(?<extended>\*=)/, decoder: Decoder.new, model: Models::Pair @split_pattern = split_pattern @decoder = decoder @model = model end |
Instance Method Details
#call(text, root_uri:) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rfc/web/link/parsers/pair.rb', line 17 def call text, root_uri: key, delimiter, value = text.split split_pattern key.strip! attributes = decoder.call value value = attributes.delete :value value = "#{root_uri}#{value}" if key == "anchor" && value.start_with?("/") attributes[:value] = value model[key:, delimiter:, **attributes] end |