class MetaHari::Helpers::OpenGraph

Attributes

document[R]

Public Class Methods

new(document) click to toggle source
# File lib/meta_hari/helpers/open_graph.rb, line 6
def initialize(document)
  @document = document
end

Public Instance Methods

data() click to toggle source
# File lib/meta_hari/helpers/open_graph.rb, line 10
def data
  hash
end

Protected Instance Methods

hash() click to toggle source
# File lib/meta_hari/helpers/open_graph.rb, line 20
def hash
  @hash ||= begin
              result = {}
              document.css(selector).each do |meta|
                key   = meta.attr('property').to_s.gsub(/^og:/i, '')
                value = meta.attr('content')
                result[key_map(key)] = value
              end
              result
            end
end
key_map(key) click to toggle source
# File lib/meta_hari/helpers/open_graph.rb, line 32
def key_map(key)
  case key.downcase
  when 'title' then 'name'
  else
    key.downcase
  end
end
selector() click to toggle source
# File lib/meta_hari/helpers/open_graph.rb, line 16
def selector
  'meta[property^="og:"]'
end