Module: Zillow4r::XmlSearchHelper::ClassMethods
- Defined in:
- lib/zillow4r/models.rb
Instance Method Summary collapse
- #array_point(method_name, definition, source, klass) ⇒ Object
- #attribute_point(method_name, definition, source, attribute_name) ⇒ Object
- #data_point(method_name, definition, source, post_value = nil) ⇒ Object
- #float_point(method_name, definition, source) ⇒ Object
- #int_point(method_name, definition, source) ⇒ Object
- #object_point(method_name, definition, source, klass) ⇒ Object
- #text_point(method_name, definition, source) ⇒ Object
Instance Method Details
#array_point(method_name, definition, source, klass) ⇒ Object
44 45 46 |
# File 'lib/zillow4r/models.rb', line 44 def array_point(method_name, definition, source, klass) data_point method_name, definition, source, lambda{|e| e.children.map{|c| klass.new(c)}} end |
#attribute_point(method_name, definition, source, attribute_name) ⇒ Object
40 41 42 |
# File 'lib/zillow4r/models.rb', line 40 def attribute_point(method_name, definition, source, attribute_name) data_point method_name, definition, source, lambda{|e| attr = e.attribute(attribute_name.to_s).value} end |
#data_point(method_name, definition, source, post_value = nil) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/zillow4r/models.rb', line 4 def data_point(method_name, definition, source, post_value = nil) definition = Array(definition) send(:define_method, method_name) do value = instance_variable_get("@#{method_name}") return value unless value.nil? data = send(source) return nil if data.nil? value = find_attribute(definition, data) return nil if value.nil? || value.empty? if post_value if post_value.respond_to?(:call) value = post_value.call(value) else value = value.send(post_value).strip end end instance_variable_set("@#{method_name}", value) value end end |
#float_point(method_name, definition, source) ⇒ Object
32 33 34 |
# File 'lib/zillow4r/models.rb', line 32 def float_point(method_name, definition, source) data_point method_name, definition, source, lambda{|e| e.inner_text.to_f} end |
#int_point(method_name, definition, source) ⇒ Object
28 29 30 |
# File 'lib/zillow4r/models.rb', line 28 def int_point(method_name, definition, source) data_point method_name, definition, source, lambda{|e| e.inner_text.to_i} end |
#object_point(method_name, definition, source, klass) ⇒ Object
48 49 50 |
# File 'lib/zillow4r/models.rb', line 48 def object_point(method_name, definition, source, klass) data_point method_name, definition, source, lambda{|e| klass.new(e)} end |
#text_point(method_name, definition, source) ⇒ Object
36 37 38 |
# File 'lib/zillow4r/models.rb', line 36 def text_point(method_name, definition, source) data_point method_name, definition, source, :inner_text end |