Class: Microformats2::Property::Foundation
- Inherits:
-
Object
- Object
- Microformats2::Property::Foundation
show all
- Defined in:
- lib/microformats2/property/foundation.rb
Constant Summary
collapse
- VALUE_CLASS_REG_EXP =
/^(value)/
- VALUE_TITLE_CLASS_REG_EXP =
/^(value-title)/
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(element, html_class, string_value = nil, base = nil) ⇒ Foundation
Returns a new instance of Foundation.
10
11
12
13
14
15
|
# File 'lib/microformats2/property/foundation.rb', line 10
def initialize(element, html_class, string_value=nil, base=nil)
@element = element
@method_name = to_method_name(html_class)
@string_value = string_value
@base = base
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *arg, &block) ⇒ Object
53
54
55
56
57
58
59
60
61
|
# File 'lib/microformats2/property/foundation.rb', line 53
def method_missing(name, *arg, &block)
fmt = items.first
if fmt.respond_to?(name)
fmt.send(name)
else
super
end
end
|
Instance Attribute Details
#method_name ⇒ Object
Returns the value of attribute method_name.
8
9
10
|
# File 'lib/microformats2/property/foundation.rb', line 8
def method_name
@method_name
end
|
Instance Method Details
27
28
29
30
|
# File 'lib/microformats2/property/foundation.rb', line 27
def format
warn "[DEPRECATION] `format` is deprecated and will be removed in the next release. Try just leaving this function out completely (example author.format.name.to_s => author.name.to_s). You can also call `items.first` instead."
items.first
end
|
32
33
34
35
|
# File 'lib/microformats2/property/foundation.rb', line 32
def formats
warn "[DEPRECATION] `formats` is deprecated and will be removed in the next release. Please use `items` instead."
items
end
|
#items ⇒ Object
37
38
39
|
# File 'lib/microformats2/property/foundation.rb', line 37
def items
@formats ||= format_classes.length >=1 ? FormatParser.parse(@element, @base) : []
end
|
#parse ⇒ Object
17
18
19
20
21
|
# File 'lib/microformats2/property/foundation.rb', line 17
def parse
to_s
items
self
end
|
#to_hash ⇒ Object
41
42
43
44
45
46
47
|
# File 'lib/microformats2/property/foundation.rb', line 41
def to_hash
if items.empty?
to_s
else
{ value: to_s }.merge(items.first.to_hash)
end
end
|
#to_json ⇒ Object
49
50
51
|
# File 'lib/microformats2/property/foundation.rb', line 49
def to_json
to_hash.to_json
end
|
#to_s ⇒ Object
23
24
25
|
# File 'lib/microformats2/property/foundation.rb', line 23
def to_s
@to_s ||= string_value || value_class_pattern || element_value || text_value
end
|