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