module PropertyDataCalculator

Public Instance Methods

get_average_by_attribute(properties, attribute) click to toggle source
# File lib/cre_property_matcher/property_data_calculator.rb, line 20
def get_average_by_attribute(properties, attribute)
        values_array = get_attribute_from_properties(properties, attribute)
        float_average_of_array(values_array)
end
get_average_by_reference_property_state(properties, reference, attribute) click to toggle source
# File lib/cre_property_matcher/property_data_calculator.rb, line 4
def get_average_by_reference_property_state(properties, reference, attribute)
        state_properties = filter_properties_by_state(properties, reference.state)
        get_average_by_attribute(state_properties, attribute)
end
get_average_by_reference_property_state_and_property_type(properties, reference, attribute) click to toggle source
# File lib/cre_property_matcher/property_data_calculator.rb, line 9
def get_average_by_reference_property_state_and_property_type(properties, reference, attribute)
        state_properties = filter_properties_by_state(properties, reference.state)
        filtered_properties = filter_properties_by_property_type(state_properties, reference.general_property_type)
        get_average_by_attribute(filtered_properties, attribute)
end
get_average_for_all_by_property_type(properties, attribute, property_type) click to toggle source
# File lib/cre_property_matcher/property_data_calculator.rb, line 15
def get_average_for_all_by_property_type(properties, attribute, property_type)
        filtered_properties = filter_properties_by_property_type(properties, property_type)
        get_average_by_attribute(filtered_properties, attribute)
end

Private Instance Methods

filter_properties_by_property_type(properties, property_type) click to toggle source
# File lib/cre_property_matcher/property_data_calculator.rb, line 33
def filter_properties_by_property_type(properties, property_type)
        properties.select do |property|
                property.general_property_type == property_type
        end
end
filter_properties_by_state(properties, state) click to toggle source
# File lib/cre_property_matcher/property_data_calculator.rb, line 27
def filter_properties_by_state(properties, state)
        properties.select do |property|
                normalize_state(property.state) == state.strip.downcase
        end
end
float_average_of_array(array) click to toggle source
# File lib/cre_property_matcher/property_data_calculator.rb, line 60
def float_average_of_array(array)
        total = array.compact.reduce(:+)
        total.to_f / array.count
end
get_attribute_from_properties(properties, attribute) click to toggle source
# File lib/cre_property_matcher/property_data_calculator.rb, line 54
def get_attribute_from_properties(properties, attribute)
        properties.map do |property|
                property.instance_variable_get(:"@#{attribute}")
        end
end
normalize_state(state) click to toggle source
# File lib/cre_property_matcher/property_data_calculator.rb, line 39
def normalize_state(state)
        if state.nil?
                "nothing"    
        elsif state.length > 3
                result = StateHash.state_hash[state.strip.capitalize]
                if result.nil?
                        "nothing"
                else
                        result.downcase
                end
        else
                state.downcase
        end
end