Class: Microformats2::PropertySet

Inherits:
Object
  • Object
show all
Defined in:
lib/microformats2/results/property_set.rb

Overview

stub to get around the tests for now

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ PropertySet

Returns a new instance of PropertySet.



6
7
8
# File 'lib/microformats2/results/property_set.rb', line 6

def initialize(hash)
  @hash = hash
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(mname, *args, &block) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/microformats2/results/property_set.rb', line 31

def method_missing(mname, *args, &block)

  if respond_to? mname
    result_hash = get_val? mname
    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.is_a? Hash
      ParserResult.new(result_hash)
    else
      result_hash
    end
  else
     super(mname, *args, &block)
  end

end

Instance Method Details

#[](key) ⇒ Object



22
23
24
# File 'lib/microformats2/results/property_set.rb', line 22

def [](key)
  @hash[key]
end

#respond_to?(sym, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/microformats2/results/property_set.rb', line 26

def respond_to?(sym, include_private = false)
  has_key?(sym) || super(sym, include_private)
end

#to_hObject



10
11
12
# File 'lib/microformats2/results/property_set.rb', line 10

def to_h
  @hash
end

#to_hashObject



14
15
16
# File 'lib/microformats2/results/property_set.rb', line 14

def to_hash
  @hash.to_hash
end

#to_jsonObject



18
19
20
# File 'lib/microformats2/results/property_set.rb', line 18

def to_json
  @hash.to_hash.to_json
end