Class: OpenGraphy::TagNamespace

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/open_graphy/tag_namespace.rb

Instance Method Summary collapse

Constructor Details

#initialize(namespace = []) ⇒ TagNamespace

Returns a new instance of TagNamespace.



8
9
10
# File 'lib/open_graphy/tag_namespace.rb', line 8

def initialize(namespace=[])
  @namespace = namespace
end

Instance Method Details

#add_to(key, value, tag) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/open_graphy/tag_namespace.rb', line 16

def add_to(key, value, tag)
  if any?
    tag.define_namespace(child_name).add(key, value, namespace: self.next)
  else
    tag.define_value(key, value)
  end
end

#any?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/open_graphy/tag_namespace.rb', line 12

def any?
  namespace.any? && first != 'og'
end

#child_nameObject



24
25
26
# File 'lib/open_graphy/tag_namespace.rb', line 24

def child_name
  namespace.first
end

#nextObject



28
29
30
31
32
# File 'lib/open_graphy/tag_namespace.rb', line 28

def next
  TagNamespace.new(
    [namespace.size > 1 ? namespace.last : nil].compact
  )
end