Class: OpenGraphy::MetaTags

Inherits:
Object
  • Object
show all
Defined in:
lib/open_graphy/meta_tags.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_sym, *arguments, &block) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/open_graphy/meta_tags.rb', line 46

def method_missing(method_sym, *arguments, &block)
  if method_sym.to_s.end_with?('?')
    false
  else
    super
  end
end

Instance Method Details

#add(key, value, namespace: TagNamespace.new) ⇒ Object



23
24
25
26
27
# File 'lib/open_graphy/meta_tags.rb', line 23

def add(key, value, namespace: TagNamespace.new)
  data[key] = value
  namespace.add_to(key, value, self)
  self
end

#define_namespace(name) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/open_graphy/meta_tags.rb', line 29

def define_namespace(name)
  if respond_to?(name)
    public_send(name)
  else
    MetaTags.new.tap { |tag|
      define_singleton_method(name, -> { tag })
    }
  end
end

#define_value(key, value) ⇒ Object



39
40
41
42
43
44
# File 'lib/open_graphy/meta_tags.rb', line 39

def define_value(key, value)
  if define_accessors?(key)
    define_singleton_method key, -> { value }
    define_singleton_method "#{key}?", -> { !!value }
  end
end

#imageObject



11
12
13
14
15
16
17
# File 'lib/open_graphy/meta_tags.rb', line 11

def image
  if valid_image_url?
    image_url
  else
    raise NoMethodError
  end
end

#image?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/open_graphy/meta_tags.rb', line 19

def image?
  valid_image_url?
end

#respond_to?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/open_graphy/meta_tags.rb', line 54

def respond_to?(method_name, include_private = false)
  method_name.to_s.end_with?('?') || super
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/open_graphy/meta_tags.rb', line 58

def respond_to_missing?(method_name, include_private = false)
  method_name.to_s.end_with?('?') || super
end

#titleObject



3
4
5
# File 'lib/open_graphy/meta_tags.rb', line 3

def title
  data.fetch('title', __html_title_tag)
end

#title?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/open_graphy/meta_tags.rb', line 7

def title?
  !!title
end