Class: RFC::Web::Link::Models::Pair
- Inherits:
-
Data
- Object
- Data
- RFC::Web::Link::Models::Pair
- Defined in:
- lib/rfc/web/link/models/pair.rb
Overview
Models the key, delimiter, and decoded value associated with a link.
Instance Attribute Summary collapse
-
#delimiter ⇒ Object
readonly
Returns the value of attribute delimiter.
-
#encoding ⇒ Object
readonly
Returns the value of attribute encoding.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#language ⇒ Object
readonly
Returns the value of attribute language.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #encoded? ⇒ Boolean
-
#initialize(key:, value:, delimiter: "=", encoding: nil, language: nil) ⇒ Pair
constructor
A new instance of Pair.
- #to_s(key_map: {"relation" => "rel", "language" => "hreflang"}.freeze, encoder: Encoder.new) ⇒ Object (also: #to_str)
Constructor Details
#initialize(key:, value:, delimiter: "=", encoding: nil, language: nil) ⇒ Pair
Returns a new instance of Pair.
9 10 11 |
# File 'lib/rfc/web/link/models/pair.rb', line 9 def initialize key:, value:, delimiter: "=", encoding: nil, language: nil super key: key.to_s, value:, delimiter:, encoding:, language: end |
Instance Attribute Details
#delimiter ⇒ Object (readonly)
Returns the value of attribute delimiter
8 9 10 |
# File 'lib/rfc/web/link/models/pair.rb', line 8 def delimiter @delimiter end |
#encoding ⇒ Object (readonly)
Returns the value of attribute encoding
8 9 10 |
# File 'lib/rfc/web/link/models/pair.rb', line 8 def encoding @encoding end |
#key ⇒ Object (readonly)
Returns the value of attribute key
8 9 10 |
# File 'lib/rfc/web/link/models/pair.rb', line 8 def key @key end |
#language ⇒ Object (readonly)
Returns the value of attribute language
8 9 10 |
# File 'lib/rfc/web/link/models/pair.rb', line 8 def language @language end |
#value ⇒ Object (readonly)
Returns the value of attribute value
8 9 10 |
# File 'lib/rfc/web/link/models/pair.rb', line 8 def value @value end |
Instance Method Details
#encoded? ⇒ Boolean
13 |
# File 'lib/rfc/web/link/models/pair.rb', line 13 def encoded? = delimiter == "*=" |
#to_s(key_map: {"relation" => "rel", "language" => "hreflang"}.freeze, encoder: Encoder.new) ⇒ Object Also known as: to_str
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rfc/web/link/models/pair.rb', line 15 def to_s key_map: {"relation" => "rel", "language" => "hreflang"}.freeze, encoder: Encoder.new transformed_key = key_map.fetch(key) { it } if encoding "#{transformed_key}#{delimiter}#{encoding}'#{language}'" \ "#{encoder.call value.encode(encoding)}" else "#{transformed_key}#{delimiter}#{value}" end end |