Class: KOSapiClient::Entity::Link
- Inherits:
-
Object
- Object
- KOSapiClient::Entity::Link
show all
- Defined in:
- lib/kosapi_client/entity/link.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(title, href, rel, client = nil) ⇒ Link
Returns a new instance of Link.
7
8
9
10
11
12
|
# File 'lib/kosapi_client/entity/link.rb', line 7
def initialize(title, href, rel, client = nil)
@link_title = title
@link_href = escape_url(href)
@link_rel = rel
@client = client
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
41
42
43
|
# File 'lib/kosapi_client/entity/link.rb', line 41
def method_missing(method, *args, **kwargs, &block)
target.send(method, *args, **kwargs, &block)
end
|
Instance Attribute Details
#link_href ⇒ Object
Returns the value of attribute link_href.
5
6
7
|
# File 'lib/kosapi_client/entity/link.rb', line 5
def link_href
@link_href
end
|
#link_rel ⇒ Object
Returns the value of attribute link_rel.
5
6
7
|
# File 'lib/kosapi_client/entity/link.rb', line 5
def link_rel
@link_rel
end
|
#link_title ⇒ Object
Returns the value of attribute link_title.
5
6
7
|
# File 'lib/kosapi_client/entity/link.rb', line 5
def link_title
@link_title
end
|
Class Method Details
.parse(contents) ⇒ Object
14
15
16
17
|
# File 'lib/kosapi_client/entity/link.rb', line 14
def self.parse(contents)
href = contents[:xlink_href] || contents[:href]
new(contents[:__content__], href, contents[:rel])
end
|
Instance Method Details
#escape_url(url) ⇒ Object
54
55
56
|
# File 'lib/kosapi_client/entity/link.rb', line 54
def escape_url(url)
url.gsub(';','%3B')
end
|
#follow ⇒ Object
23
24
25
26
|
# File 'lib/kosapi_client/entity/link.rb', line 23
def follow
raise "HTTP client not set, cannot send request to #{link_href}" unless @client
@client.send_request(:get, link_href)
end
|
#inject_client(client) ⇒ Object
28
29
30
|
# File 'lib/kosapi_client/entity/link.rb', line 28
def inject_client(client)
@client = client
end
|
#link_id ⇒ Object
19
20
21
|
# File 'lib/kosapi_client/entity/link.rb', line 19
def link_id
@link_href.split('/').last
end
|
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
50
51
52
|
# File 'lib/kosapi_client/entity/link.rb', line 50
def respond_to_missing?(method_name, include_private = false)
target.respond_to?(method_name, include_private)
end
|
#target ⇒ Object
32
33
34
|
# File 'lib/kosapi_client/entity/link.rb', line 32
def target
@target ||= follow
end
|
#to_hash ⇒ Object
36
37
38
|
# File 'lib/kosapi_client/entity/link.rb', line 36
def to_hash
{ href: link_href, rel: link_rel, title: link_title }
end
|