Class: Restfully::Link
- Inherits:
-
Object
- Object
- Restfully::Link
- Defined in:
- lib/restfully/link.rb
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.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #id ⇒ Object
-
#initialize(attributes = {}) ⇒ Link
constructor
A new instance of Link.
- #media_type ⇒ Object
- #self? ⇒ Boolean
- #types ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(attributes = {}) ⇒ Link
Returns a new instance of Link.
7 8 9 10 11 12 13 14 |
# File 'lib/restfully/link.rb', line 7 def initialize(attributes = {}) attributes = attributes.symbolize_keys @rel = attributes[:rel] @title = attributes[:title] || @rel @href = URI.parse(attributes[:href].to_s) @type = attributes[:type] @id = attributes[:id] end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
5 6 7 |
# File 'lib/restfully/link.rb', line 5 def errors @errors end |
#href ⇒ Object (readonly)
Returns the value of attribute href.
5 6 7 |
# File 'lib/restfully/link.rb', line 5 def href @href end |
#rel ⇒ Object (readonly)
Returns the value of attribute rel.
5 6 7 |
# File 'lib/restfully/link.rb', line 5 def rel @rel end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
5 6 7 |
# File 'lib/restfully/link.rb', line 5 def title @title end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
5 6 7 |
# File 'lib/restfully/link.rb', line 5 def type @type end |
Instance Method Details
#id ⇒ Object
34 35 36 |
# File 'lib/restfully/link.rb', line 34 def id title.to_s.downcase.gsub(/[^a-z]/,'_').squeeze('_').to_sym end |
#media_type ⇒ Object
30 31 32 |
# File 'lib/restfully/link.rb', line 30 def media_type @media_type ||= MediaType.find(type) end |
#self? ⇒ Boolean
16 |
# File 'lib/restfully/link.rb', line 16 def self?; @rel == 'self'; end |
#types ⇒ Object
18 19 20 |
# File 'lib/restfully/link.rb', line 18 def types (type || "").split(";") end |
#valid? ⇒ Boolean
22 23 24 25 26 27 28 |
# File 'lib/restfully/link.rb', line 22 def valid? @errors = [] if href.nil? errors << "href cannot be nil" end errors.empty? end |