Class: OGP::OpenGraph
- Inherits:
-
Object
- Object
- OGP::OpenGraph
- Defined in:
- lib/ogp/open_graph.rb
Instance Attribute Summary collapse
-
#audios ⇒ Object
Returns the value of attribute audios.
-
#description ⇒ Object
Optional Accessors.
-
#determiner ⇒ Object
Optional Accessors.
-
#images ⇒ Object
Returns the value of attribute images.
-
#locales ⇒ Object
Returns the value of attribute locales.
-
#site_name ⇒ Object
Optional Accessors.
-
#title ⇒ Object
Required Accessors.
-
#type ⇒ Object
Required Accessors.
-
#url ⇒ Object
Required Accessors.
-
#videos ⇒ Object
Returns the value of attribute videos.
Instance Method Summary collapse
- #image ⇒ Object
-
#initialize(source) ⇒ OpenGraph
constructor
A new instance of OpenGraph.
Constructor Details
#initialize(source) ⇒ OpenGraph
Returns a new instance of OpenGraph.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ogp/open_graph.rb', line 18 def initialize(source) if source.nil? || source.empty? raise ArgumentError, '`source` cannot be nil or empty.' end raise MalformedSourceError unless source.include?('</html>') source.force_encoding('UTF-8') if source.encoding != 'UTF-8' self.images = [] self.audios = [] self.locales = [] self.videos = [] document = Oga.parse_html(source) check_required_attributes(document) parse_attributes(document) end |
Instance Attribute Details
#audios ⇒ Object
Returns the value of attribute audios.
14 15 16 |
# File 'lib/ogp/open_graph.rb', line 14 def audios @audios end |
#description ⇒ Object
Optional Accessors
13 14 15 |
# File 'lib/ogp/open_graph.rb', line 13 def description @description end |
#determiner ⇒ Object
Optional Accessors
13 14 15 |
# File 'lib/ogp/open_graph.rb', line 13 def determiner @determiner end |
#images ⇒ Object
Returns the value of attribute images.
10 11 12 |
# File 'lib/ogp/open_graph.rb', line 10 def images @images end |
#locales ⇒ Object
Returns the value of attribute locales.
15 16 17 |
# File 'lib/ogp/open_graph.rb', line 15 def locales @locales end |
#site_name ⇒ Object
Optional Accessors
13 14 15 |
# File 'lib/ogp/open_graph.rb', line 13 def site_name @site_name end |
#title ⇒ Object
Required Accessors
9 10 11 |
# File 'lib/ogp/open_graph.rb', line 9 def title @title end |
#type ⇒ Object
Required Accessors
9 10 11 |
# File 'lib/ogp/open_graph.rb', line 9 def type @type end |
#url ⇒ Object
Required Accessors
9 10 11 |
# File 'lib/ogp/open_graph.rb', line 9 def url @url end |
#videos ⇒ Object
Returns the value of attribute videos.
16 17 18 |
# File 'lib/ogp/open_graph.rb', line 16 def videos @videos end |
Instance Method Details
#image ⇒ Object
37 38 39 40 |
# File 'lib/ogp/open_graph.rb', line 37 def image return if images.nil? images.first end |