Class: Restfully::Link
Constant Summary collapse
- VALID_RELATIONSHIPS =
%w{member parent collection self alternate next}
- RELATIONSHIPS_REQUIRING_TITLE =
%w{collection member}
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#href ⇒ Object
readonly
Returns the value of attribute href.
-
#rel ⇒ Object
readonly
Returns the value of attribute rel.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ Link
constructor
A new instance of Link.
- #resolvable? ⇒ Boolean
- #resolved? ⇒ Boolean
- #self? ⇒ Boolean
- #valid? ⇒ Boolean
Constructor Details
#initialize(attributes = {}) ⇒ Link
Returns a new instance of Link.
10 11 12 13 14 15 16 |
# File 'lib/restfully/link.rb', line 10 def initialize(attributes = {}) @rel = attributes['rel'] @title = attributes['title'] @href = URI.parse(attributes['href'].to_s) @resolvable = attributes['resolvable'] || false @resolved = attributes['resolved'] || false end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
8 9 10 |
# File 'lib/restfully/link.rb', line 8 def errors @errors end |
#href ⇒ Object (readonly)
Returns the value of attribute href.
8 9 10 |
# File 'lib/restfully/link.rb', line 8 def href @href end |
#rel ⇒ Object (readonly)
Returns the value of attribute rel.
8 9 10 |
# File 'lib/restfully/link.rb', line 8 def rel @rel end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
8 9 10 |
# File 'lib/restfully/link.rb', line 8 def title @title end |
Instance Method Details
#resolvable? ⇒ Boolean
18 |
# File 'lib/restfully/link.rb', line 18 def resolvable?; @resolvable == true; end |
#resolved? ⇒ Boolean
19 |
# File 'lib/restfully/link.rb', line 19 def resolved?; @resolved == true; end |
#self? ⇒ Boolean
20 |
# File 'lib/restfully/link.rb', line 20 def self?; @rel == 'self'; end |
#valid? ⇒ Boolean
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/restfully/link.rb', line 22 def valid? @errors = [] if href.nil? errors << "href cannot be nil." end unless VALID_RELATIONSHIPS.include?(rel) errors << "#{rel} is not a valid link relationship." end if (!title || title.empty?) && RELATIONSHIPS_REQUIRING_TITLE.include?(rel) errors << "#{rel} #{href} has no title." end errors.empty? end |