Class: TentClient::LinkHeader::Link
- Inherits:
-
Object
- Object
- TentClient::LinkHeader::Link
- Defined in:
- lib/tent-client/link_header.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#uri ⇒ Object
Returns the value of attribute uri.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #[](k) ⇒ Object
- #[]=(k, v) ⇒ Object
-
#initialize(uri, attributes = {}) ⇒ Link
constructor
A new instance of Link.
- #to_s ⇒ Object
Constructor Details
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
23 24 25 |
# File 'lib/tent-client/link_header.rb', line 23 def attributes @attributes end |
#uri ⇒ Object
Returns the value of attribute uri.
23 24 25 |
# File 'lib/tent-client/link_header.rb', line 23 def uri @uri end |
Class Method Details
.parse(link_text) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/tent-client/link_header.rb', line 25 def self.parse(link_text) s = StringScanner.new(link_text) s.scan(/[^<]+/) link = s.scan(/<[^\s]+>/) raise MalformedLinkHeader.new("Link: #{s.inspect}") unless link link = link[1..-2] s.scan(/[^a-z]+/) attrs = {} while attr = s.scan(/[a-z0-9*\-]+=/) next if attr =~ /\*/ val = s.scan(/".+?"|[^\s";]+/).sub(/\A"/, '').sub(/"\Z/, '') attrs[attr[0..-2]] = val s.scan(/[^a-z]+/) end new(link, attrs) end |
Instance Method Details
#==(other) ⇒ Object
50 51 52 53 |
# File 'lib/tent-client/link_header.rb', line 50 def ==(other) false unless is_a?(self.class) uri == other.uri && attributes == other.attributes end |
#[](k) ⇒ Object
55 56 57 |
# File 'lib/tent-client/link_header.rb', line 55 def [](k) attributes[k] end |
#[]=(k, v) ⇒ Object
59 60 61 |
# File 'lib/tent-client/link_header.rb', line 59 def []=(k, v) attributes[k.to_s] = v.to_s end |
#to_s ⇒ Object
63 64 65 66 |
# File 'lib/tent-client/link_header.rb', line 63 def to_s attr_string = "; " + attributes.sort.map { |k,v| "#{k}=#{v.inspect}" }.join('; ') if attributes "<#{uri}>#{attr_string}" end |