class Microformats::ParserResult

stub to get around the tests for now

Public Class Methods

new(hash) click to toggle source
# File lib/microformats/results/parser_result.rb, line 4
def initialize(hash)
  @hash = hash
end

Public Instance Methods

[](key) click to toggle source
# File lib/microformats/results/parser_result.rb, line 26
def [](key)
  @hash[key]
end
method_missing(sym, *args, &block) click to toggle source
Calls superclass method
# 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] # 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

  if result_hash.nil? || result_hash.empty?
    result_hash
  elsif result_hash.is_a?(Hash)
    ParserResult.new(result_hash)
  else
    result_hash
  end
end
properties() click to toggle source
# File lib/microformats/results/parser_result.rb, line 34
def properties
  PropertySet.new(@hash['properties'])
end
respond_to?(sym, include_private = false) click to toggle source
Calls superclass method
# 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() click to toggle source
# File lib/microformats/results/parser_result.rb, line 8
def to_h
  @hash
end
to_hash() click to toggle source
# File lib/microformats/results/parser_result.rb, line 12
def to_hash
  @hash
end
to_json() click to toggle source
# File lib/microformats/results/parser_result.rb, line 16
def to_json
  to_hash.to_json
end
to_s() click to toggle source
# File lib/microformats/results/parser_result.rb, line 20
def to_s
  return @hash['value'] if @hash['value']

  @hash.to_s
end
value() click to toggle source
# File lib/microformats/results/parser_result.rb, line 30
def value
  @hash['value']
end

Private Instance Methods

key?(name) click to toggle source
# File lib/microformats/results/parser_result.rb, line 83
def key?(name)
  name = name.to_s
  name_dash = name.tr('_', '-') if name.include?('_')

  !@hash[name].nil? || !@hash[name_dash].nil?
end
property?(name) click to toggle source
# File lib/microformats/results/parser_result.rb, line 90
def property?(name)
  name = name.to_s
  name_dash = name.tr('_', '-') if name.include?('_')

  return false if @hash['properties'].nil?

  !@hash['properties'][name].nil? || !@hash['properties'][name_dash].nil?
end