class Microformats::Collection
stub to get around the tests for now
Public Class Methods
new(hash)
click to toggle source
# File lib/microformats/results/collection.rb, line 4 def initialize(hash) @hash = hash end
Public Instance Methods
[](key)
click to toggle source
# File lib/microformats/results/collection.rb, line 24 def [](key) @hash[key] end
items()
click to toggle source
# File lib/microformats/results/collection.rb, line 28 def items @hash['items'].map do |item| ParserResult.new(item) end end
method_missing(sym, *args, &block)
click to toggle source
Calls superclass method
# 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] # will return nil for an empty array 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] # will return nil for an empty array end end ParserResult.new(result_hash) end
rel_urls()
click to toggle source
# File lib/microformats/results/collection.rb, line 38 def rel_urls @hash['rel-urls'] end
rels()
click to toggle source
# File lib/microformats/results/collection.rb, line 34 def rels @hash['rels'] end
respond_to?(sym, include_private = false)
click to toggle source
Calls superclass method
# File lib/microformats/results/collection.rb, line 42 def respond_to?(sym, include_private = false) item?(sym) || super(sym, include_private) end
to_h()
click to toggle source
# File lib/microformats/results/collection.rb, line 8 def to_h @hash end
to_hash()
click to toggle source
# File lib/microformats/results/collection.rb, line 12 def to_hash @hash end
to_json()
click to toggle source
# File lib/microformats/results/collection.rb, line 16 def to_json to_hash.to_json end
to_s()
click to toggle source
# File lib/microformats/results/collection.rb, line 20 def to_s @hash.to_s end
Private Instance Methods
item?(name)
click to toggle source
# File lib/microformats/results/collection.rb, line 83 def item?(name) name = name.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 !result_hash.empty? end