Class: Jacoat::Document::Link
- Inherits:
-
Object
- Object
- Jacoat::Document::Link
show all
- Defined in:
- lib/jacoat/document/link.rb
Defined Under Namespace
Classes: Complex, Simple
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Link
Returns a new instance of Link.
10
11
12
|
# File 'lib/jacoat/document/link.rb', line 10
def initialize
@hash = {}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args) ⇒ Object
14
15
16
17
18
19
20
21
|
# File 'lib/jacoat/document/link.rb', line 14
def method_missing(m, *args)
if /^(\w+)=$/ =~ m
@hash[:"#{$1}"] = args[0]
end
@hash[:"#{m}"]
end
|
Class Method Details
.from_jsonapi(hash) ⇒ Object
4
5
6
7
8
|
# File 'lib/jacoat/document/link.rb', line 4
def self.from_jsonapi(hash)
link = Link.new
link.process_links(hash)
link
end
|
Instance Method Details
#add_link(title, href, options = {}) ⇒ Object
43
44
45
46
47
48
49
50
51
|
# File 'lib/jacoat/document/link.rb', line 43
def add_link(title, href, options = {})
if options.empty?
link = Simple.new(href)
else
link = Complex.new(href: href, meta: options)
end
send("#{title}=", link)
self
end
|
#process_links(arguments) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/jacoat/document/link.rb', line 31
def process_links(arguments)
return if arguments.nil?
arguments.each_pair do |k, v|
if v.is_a?(String)
link = Simple.new(v)
else
link = Complex.new(v)
end
send("#{k}=", link)
end
end
|
#to_hash ⇒ Object
23
24
25
26
27
28
29
|
# File 'lib/jacoat/document/link.rb', line 23
def to_hash
hash = {}
@hash.each_pair do |k, v|
hash[k] = v.to_hash
end
hash
end
|