Class: Microformats::Collection
- Inherits:
-
Object
- Object
- Microformats::Collection
show all
- Defined in:
- lib/microformats/results/collection.rb
Overview
stub to get around the tests for now
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Collection.
4
5
6
|
# File 'lib/microformats/results/collection.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
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/collection.rb', line 46
def method_missing(sym, *args, &block)
name = sym.to_s
name_dash = name.tr('_', '-') if name.include?('_')
unless @hash['items'].nil?
result_hash = @hash['items'].select do |x|
x['type'].include?('h-' + name)
end
if result_hash.empty? && !name_dash.nil?
result_hash = @hash['items'].select do |x|
x['type'].include?('h-' + name_dash)
end
end
end
super(sym, *args, &block) if result_hash.empty?
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
ParserResult.new(result_hash)
end
|
Instance Method Details
#[](key) ⇒ Object
24
25
26
|
# File 'lib/microformats/results/collection.rb', line 24
def [](key)
@hash[key]
end
|
#items ⇒ Object
28
29
30
31
32
|
# File 'lib/microformats/results/collection.rb', line 28
def items
@hash['items'].map do |item|
ParserResult.new(item)
end
end
|
#rel_urls ⇒ Object
38
39
40
|
# File 'lib/microformats/results/collection.rb', line 38
def rel_urls
@hash['rel-urls']
end
|
#rels ⇒ Object
34
35
36
|
# File 'lib/microformats/results/collection.rb', line 34
def rels
@hash['rels']
end
|
#respond_to?(sym, include_private = false) ⇒ Boolean
42
43
44
|
# File 'lib/microformats/results/collection.rb', line 42
def respond_to?(sym, include_private = false)
item?(sym) || super(sym, include_private)
end
|
#to_h ⇒ Object
8
9
10
|
# File 'lib/microformats/results/collection.rb', line 8
def to_h
@hash
end
|
#to_hash ⇒ Object
12
13
14
|
# File 'lib/microformats/results/collection.rb', line 12
def to_hash
@hash
end
|
#to_json ⇒ Object
16
17
18
|
# File 'lib/microformats/results/collection.rb', line 16
def to_json
to_hash.to_json
end
|
#to_s ⇒ Object
20
21
22
|
# File 'lib/microformats/results/collection.rb', line 20
def to_s
@hash.to_s
end
|