Class: Microformats::ParserResult
- Inherits:
-
Object
- Object
- Microformats::ParserResult
show all
- Defined in:
- lib/microformats/results/parser_result.rb
Overview
stub to get around the tests for now
Instance Method Summary
collapse
Constructor Details
Returns a new instance of ParserResult.
4
5
6
|
# File 'lib/microformats/results/parser_result.rb', line 4
def initialize(hash)
@hash = hash
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/microformats/results/parser_result.rb', line 42
def method_missing(sym, *args, &block)
name = sym.to_s
name_dash = name.tr('_', '-') if name.include?('_')
if !@hash[name].nil?
result_hash = @hash[name]
elsif !@hash['properties'].nil? && !@hash['properties'][name].nil?
result_hash = @hash['properties'][name]
elsif !name_dash.nil? && !@hash[name_dash].nil?
result_hash = @hash[name_dash]
elsif !name_dash.nil? && !@hash['properties'].nil? && !@hash['properties'][name_dash].nil?
result_hash = @hash['properties'][name_dash]
else
super(sym, *args, &block)
end
if result_hash.is_a?(Array)
if args[0].nil?
result_hash = result_hash[0] elsif args[0] == :all
return result_hash.map do |x|
ParserResult.new(x)
end
elsif args[0].to_i < result_hash.count
result_hash = result_hash[args[0].to_i]
else
result_hash = result_hash[0] end
end
if result_hash.nil? || result_hash.empty?
result_hash
elsif result_hash.is_a?(Hash)
ParserResult.new(result_hash)
else
result_hash
end
end
|
Instance Method Details
#[](key) ⇒ Object
26
27
28
|
# File 'lib/microformats/results/parser_result.rb', line 26
def [](key)
@hash[key]
end
|
#properties ⇒ Object
34
35
36
|
# File 'lib/microformats/results/parser_result.rb', line 34
def properties
PropertySet.new(@hash['properties'])
end
|
#respond_to?(sym, include_private = false) ⇒ Boolean
38
39
40
|
# File 'lib/microformats/results/parser_result.rb', line 38
def respond_to?(sym, include_private = false)
key?(sym) || property?(sym) || super(sym, include_private)
end
|
#to_h ⇒ Object
8
9
10
|
# File 'lib/microformats/results/parser_result.rb', line 8
def to_h
@hash
end
|
#to_hash ⇒ Object
12
13
14
|
# File 'lib/microformats/results/parser_result.rb', line 12
def to_hash
@hash
end
|
#to_json ⇒ Object
16
17
18
|
# File 'lib/microformats/results/parser_result.rb', line 16
def to_json
to_hash.to_json
end
|
#to_s ⇒ Object
20
21
22
23
24
|
# File 'lib/microformats/results/parser_result.rb', line 20
def to_s
return @hash['value'] if @hash['value']
@hash.to_s
end
|
#value ⇒ Object
30
31
32
|
# File 'lib/microformats/results/parser_result.rb', line 30
def value
@hash['value']
end
|