Module: GeoPack::RillowHelper

Defined in:
lib/geo_pack/rillow_helper.rb

Instance Method Summary collapse

Instance Method Details

#find_attribute(key, obj = nil) ⇒ Object

The find_attribute helper method is to provide a easy eay to find a attribute within the hash and array Examples: rillow = Rillow.new (‘your-zillow-service identifier’) result = rillow.get_search_results(‘2114 Bigelow Ave’,‘Seattle, WA’) valuationRange = result.find_attribute ‘valuationRange’



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/geo_pack/rillow_helper.rb', line 8

def find_attribute(key,obj=nil)
  if obj==nil then 
    obj=self
  end
  if obj.is_a? Hash then
    obj.each { |k,v|
      if k==key then
        return v
      else
        result = find_attribute(key,v)
        if result != nil then
          return result
        end
      end
    }
  elsif obj.is_a? Array then
    obj.each {|o| 
      result  = find_attribute(key,o)
      if result !=  nil then
        return result       
      end 
    }
  end
  return nil
end