Method: OGP::OpenGraph#initialize

Defined in:
lib/ogp/open_graph.rb

#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