Class: Webmachine::ETag
- Inherits:
-
Object
- Object
- Webmachine::ETag
- Includes:
- QuotedString
- Defined in:
- lib/webmachine/etags.rb
Overview
A wrapper around entity tags that encapsulates their semantics. This class by itself represents a "strong" entity tag.
Direct Known Subclasses
Constant Summary collapse
- WEAK_ETAG =
The pattern for a weak entity tag
/^W\/#{QUOTED_STRING}$/.freeze
Constants included from QuotedString
QuotedString::QS_ANCHORED, QuotedString::QUOTED_STRING
Instance Attribute Summary collapse
-
#etag ⇒ Object
readonly
Returns the value of attribute etag.
Class Method Summary collapse
Instance Method Summary collapse
-
#==(other) ⇒ Object
An entity tag is equivalent to another entity tag if their quoted values are equivalent.
-
#initialize(etag) ⇒ ETag
constructor
A new instance of ETag.
-
#to_s ⇒ Object
Converts the entity tag into a string appropriate for use in a header.
Methods included from QuotedString
#escape_quotes, #quote, #unescape_quotes, #unquote
Constructor Details
#initialize(etag) ⇒ ETag
Returns a new instance of ETag.
22 23 24 |
# File 'lib/webmachine/etags.rb', line 22 def initialize(etag) @etag = quote(etag) end |
Instance Attribute Details
#etag ⇒ Object (readonly)
Returns the value of attribute etag.
20 21 22 |
# File 'lib/webmachine/etags.rb', line 20 def etag @etag end |
Class Method Details
.new(etag) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/webmachine/etags.rb', line 12 def self.new(etag) return etag if ETag === etag klass = WEAK_ETAG.match?(etag) ? WeakETag : self klass.send(:allocate).tap do |obj| obj.send(:initialize, etag) end end |
Instance Method Details
#==(other) ⇒ Object
An entity tag is equivalent to another entity tag if their quoted values are equivalent. It is also equivalent to a String which represents the equivalent ETag.
29 30 31 32 33 34 35 36 |
# File 'lib/webmachine/etags.rb', line 29 def ==(other) case other when ETag other.etag == @etag when String quote(other) == @etag end end |
#to_s ⇒ Object
Converts the entity tag into a string appropriate for use in a header.
40 41 42 |
# File 'lib/webmachine/etags.rb', line 40 def to_s quote @etag end |