Back to Parent

def determine_PD x
    
    #this is the answer to the question "Which neighborhood do you live in?"
    csv_SF_Neighborhood = 'SF_Neighborhood.csv'
    search_criteria_neighborhood = { 'Neighborhood_AW' => x}

    options = { :headers => :first_row,
                :converters => [ :numeric ]}

    neighborhood_matches = nil

    CSV.open(csv_SF_Neighborhood, "r", options) do |csv|

        neighborhood_matches = csv.find_all do |row|
            match = true
            search_criteria_neighborhood.keys.each do |key|
               match = match && ( row[key] == search_criteria_neighborhood[key]) 
            end
            match
        end    
    end
    
    

    # if more than one PD match (Outer Mission, Castro, West of Twin Peaks, Sunset)
    if neighborhood_matches.length >=2
        if x == "Outer Mission"
            "2PD - Outer Mission"
        elsif x == "Castro"
            "2PD - Castro"    
        elsif x == "West of Twin Peaks"
            "2PD - West of Twin Peaks"
        elsif x == "Sunset"
            "2PD - Sunset"
        else
            "no match"
        end 
    # if one match - perfect!    
    elsif neighborhood_matches.length == 1
        # based on the data there is no project in Presidio
        if x == "Presidio"
            "no project"
        else
            # ================= print result – start =================
            (neighborhood_matches[0])[0]                        
            # ================= print result – end =================
            session["PD"] = (neighborhood_matches[0])[0]        #only one item [0], and PD is column 0 (the "1 - Richmond" format)
            session["PD_SIMP"] = (neighborhood_matches[0])[1]     #only one item [0], and PD_SIMP is column 1 (the "Richmond" format)
        end
    # if no match 
    else
        "no match"
    end
    
    
end
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0