Class: Onebox::OpenGraph
- Inherits:
-
Object
show all
- Defined in:
- lib/onebox/open_graph.rb
Direct Known Subclasses
Oembed
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(doc) ⇒ OpenGraph
Returns a new instance of OpenGraph.
8
9
10
|
# File 'lib/onebox/open_graph.rb', line 8
def initialize(doc)
@data = (doc)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(attr, *args, &block) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/onebox/open_graph.rb', line 26
def method_missing(attr, *args, &block)
value = get(attr, *args)
return nil if Onebox::Helpers::blank?(value)
method_name = attr.to_s
if method_name.end_with?(*integer_suffixes)
value.to_i
elsif method_name.end_with?(*url_suffixes)
result = Onebox::Helpers.normalize_url_for_output(value)
result unless Onebox::Helpers::blank?(result)
else
value
end
end
|
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
6
7
8
|
# File 'lib/onebox/open_graph.rb', line 6
def data
@data
end
|
Instance Method Details
#get(attr, length = nil, sanitize = true) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/onebox/open_graph.rb', line 42
def get(attr, length = nil, sanitize = true)
return nil if Onebox::Helpers::blank?(data)
value = data[attr]
return nil if Onebox::Helpers::blank?(value)
value = html_entities.decode(value)
value = Sanitize.fragment(value) if sanitize
value.strip!
value = Onebox::Helpers.truncate(value, length) unless length.nil?
value
end
|
#secure_image_url ⇒ Object
20
21
22
23
24
|
# File 'lib/onebox/open_graph.rb', line 20
def secure_image_url
secure_url = URI(get(:image))
secure_url.scheme = 'https'
secure_url.to_s
end
|
#title ⇒ Object
12
13
14
|
# File 'lib/onebox/open_graph.rb', line 12
def title
get(:title, 80)
end
|
#title_attr ⇒ Object
16
17
18
|
# File 'lib/onebox/open_graph.rb', line 16
def title_attr
!title.nil? ? "title='#{title}'" : ""
end
|