Class: Ogg::Generator::Property
- Inherits:
-
Object
- Object
- Ogg::Generator::Property
show all
- Defined in:
- lib/ogg/generator.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(property) ⇒ Property
Returns a new instance of Property.
11
12
13
14
|
# File 'lib/ogg/generator.rb', line 11
def initialize(property)
@property = property
@children = []
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/ogg/generator.rb', line 33
def method_missing(name, *args)
name = name.to_s
structured_property = @children.find{|child| [child.property, "#{child.property}="].include?(name) }
super unless structured_property
if name[-1] == "="
structured_property.content = args.shift
else
structured_property
end
end
|
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
8
9
10
|
# File 'lib/ogg/generator.rb', line 8
def content
@content
end
|
#property ⇒ Object
Returns the value of attribute property.
9
10
11
|
# File 'lib/ogg/generator.rb', line 9
def property
@property
end
|
Instance Method Details
#[](name) ⇒ Object
21
22
23
24
25
|
# File 'lib/ogg/generator.rb', line 21
def [](name)
return nil unless @children
name = name.to_s
@children.find{|child| child.property == name }
end
|
#[]=(name, value) ⇒ Object
27
28
29
30
31
|
# File 'lib/ogg/generator.rb', line 27
def []=(name, value)
child = __send__(:[], name)
raise ArgumentError unless child
child.content = value
end
|
#add_child(structured_property) ⇒ Object
16
17
18
19
|
# File 'lib/ogg/generator.rb', line 16
def add_child(structured_property)
raise ArgumentError unless @children
@children << structured_property
end
|
#changed? ⇒ Boolean
44
45
46
|
# File 'lib/ogg/generator.rb', line 44
def changed?
content
end
|
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/ogg/generator.rb', line 48
def meta_tag
tags = []
tags << "<meta property=\"og:#{@property}\" content=\"#{content}\">" if changed?
@children.each do |child|
next unless child.changed?
if child.alternative?
tags << "<meta property=\"og:#{@property}\" content=\"#{child.content}\"><a></a>" unless changed?
else
tags << child.meta_tag
end
end
tags.compact.join("\n")
end
|