Class: OGP::OpenGraph

Inherits:
Object
  • Object
show all
Defined in:
lib/ogp/open_graph.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#audiosObject

Returns the value of attribute audios.



14
15
16
# File 'lib/ogp/open_graph.rb', line 14

def audios
  @audios
end

#descriptionObject

Optional Accessors



13
14
15
# File 'lib/ogp/open_graph.rb', line 13

def description
  @description
end

#determinerObject

Optional Accessors



13
14
15
# File 'lib/ogp/open_graph.rb', line 13

def determiner
  @determiner
end

#imagesObject

Returns the value of attribute images.



10
11
12
# File 'lib/ogp/open_graph.rb', line 10

def images
  @images
end

#localesObject

Returns the value of attribute locales.



15
16
17
# File 'lib/ogp/open_graph.rb', line 15

def locales
  @locales
end

#site_nameObject

Optional Accessors



13
14
15
# File 'lib/ogp/open_graph.rb', line 13

def site_name
  @site_name
end

#titleObject

Required Accessors



9
10
11
# File 'lib/ogp/open_graph.rb', line 9

def title
  @title
end

#typeObject

Required Accessors



9
10
11
# File 'lib/ogp/open_graph.rb', line 9

def type
  @type
end

#urlObject

Required Accessors



9
10
11
# File 'lib/ogp/open_graph.rb', line 9

def url
  @url
end

#videosObject

Returns the value of attribute videos.



16
17
18
# File 'lib/ogp/open_graph.rb', line 16

def videos
  @videos
end

Instance Method Details

#imageObject



37
38
39
40
# File 'lib/ogp/open_graph.rb', line 37

def image
  return if images.nil?
  images.first
end