class Xenon::ETag
An Etag, see {tools.ietf.org/html/rfc7232#section-2.3 RFC 7232 § 2.3}.
Attributes
Public Class Methods
Initializes a new ETag
instance. @param tag [String] The opaque tag. @param weak [true, false] Whether the tag is weak.
# File lib/xenon/etag.rb, line 11 def initialize(tag, weak: false) @tag = tag @weak = weak freeze end
Parses an ETag
string. @param s [String] The ETag
string. @return [ETag] An `ETag` object.
# File lib/xenon/etag.rb, line 27 def self.parse(s) tree = Parsers::ETag.new.etag.parse(s) Parsers::ETagHeaderTransform.new.apply(tree) rescue Parslet::ParseFailed raise Xenon::ParseError.new("Invalid ETag (#{s}).") end
Public Instance Methods
An equality function that checks the ETags have the same strength and tag. @return [true, false] `true` if the ETags have the same strength and tag; otherwise `false`.
# File lib/xenon/etag.rb, line 60 def ==(other) strong? == other.strong? && @tag == other.tag end
A case equality function that uses {strong_eq?} or {weak_eq?} depending on whether the receiving tag is strong or weak, respectively. @return [true, false] `true` if the other ETag
matches; otherwise `false`.
# File lib/xenon/etag.rb, line 68 def ===(other) strong? ? strong_eq?(other) : weak_eq?(other) end
Prevents further modifications to the ETag
. @return [ETag] This method returns self.
# File lib/xenon/etag.rb, line 19 def freeze @tag.freeze super end
The strong equality function, see {tools.ietf.org/html/rfc7232#section-2.3.2 RFC 7232 § 2.3.2}. @return [true, false] `true` if the ETags are both strong and have the same tag; otherwise `false`.
# File lib/xenon/etag.rb, line 48 def strong_eq?(other) strong? && other.strong? && @tag == other.tag end
The weak equality function, see {tools.ietf.org/html/rfc7232#section-2.3.2 RFC 7232 § 2.3.2}. @return [true, false] `true` if the ETags have the same tag; otherwise `false`.
# File lib/xenon/etag.rb, line 54 def weak_eq?(other) @tag == other.tag end