class CommandLineInterface

Public Class Methods

new() click to toggle source
# File lib/command_line_interface.rb, line 6
def initialize
    Scraper.gardens_api
    Scraper.garden_hashes
end

Public Instance Methods

all_gardens_detail() click to toggle source
# File lib/command_line_interface.rb, line 188
def all_gardens_detail
    Garden.all.map {|g| index_card(g)}
end
borough_one_liner(input) click to toggle source
# File lib/command_line_interface.rb, line 207
def borough_one_liner(input)
    alphabatized_boroughs = Garden.filter_by_borough(input).sort_by {|g| g.gardenname}

    alphabatized_boroughs.each do |g|
        puts "~*~ #{"#{g.gardenname}".blue} - #{"#{g.parksid}".magenta}"
        puts " "
    end

end
citywide_garden_count_report() click to toggle source
# File lib/command_line_interface.rb, line 224
def citywide_garden_count_report
    puts " "
    puts "There are a total of #{"#{Garden.all.count} gardens".magenta} in New York City."
    puts " "
    puts "Bronx: #{"#{Garden.filter_by_borough("X").count}".magenta}"
    puts "Queens: #{"#{Garden.filter_by_borough("Q").count}".magenta}"
    puts "Manhattan: #{"#{Garden.filter_by_borough("M").count}".magenta}"
    puts "Brooklyn: #{"#{Garden.filter_by_borough("B").count}".magenta}"
    puts "Staten Island: #{"#{Garden.filter_by_borough("M").count}".magenta}"
    puts " "
    puts "The most vegetative ZIP codes are:" 
    puts " "
    Garden.print_top_zipcodes("all")
    puts " "
end
find_by_gardenname(input) click to toggle source
# File lib/command_line_interface.rb, line 244
def find_by_gardenname(input)
    Garden.all.detect {|g| g.gardenname == input}
end
find_by_parksid(input) click to toggle source
# File lib/command_line_interface.rb, line 240
def find_by_parksid(input)
    Garden.all.detect {|g| g.parksid == input}
end
index_card(garden) click to toggle source
# File lib/command_line_interface.rb, line 196
def index_card(garden)
    garden.tap do |g|
        puts "- - - - - - - - - - - - - - - - - - - - - - - - - - "
        puts ""
        puts "  ~*~ #{"#{g.gardenname}".blue} ~*~"
        puts "  #{"#{g.parksid}".magenta} (#{g.status})"
        puts "  #{Garden.translate_borough(g.borough)} - ZIP Code: #{"#{g.zipcode}".yellow}"
        puts ""
    end
end
menu() click to toggle source
random_garden() click to toggle source
# File lib/command_line_interface.rb, line 192
def random_garden
    index_card(Garden.all.sample)
end
run() click to toggle source
# File lib/command_line_interface.rb, line 11
def run
    menu
end
search_function(input) click to toggle source
# File lib/command_line_interface.rb, line 173
def search_function(input)
    if find_by_gardenname(input)
        found_garden = find_by_gardenname(input)
        index_card(found_garden)
    elsif find_by_parksid(input)
        found_garden = find_by_parksid(input)
        index_card(found_garden)
    else
        puts "Sorry, I can't find that park. Are you sure you're spelling it correctly? Try again:"
        input = gets.strip
        search_function(input)
    end
end
zip_one_liner(input) click to toggle source
# File lib/command_line_interface.rb, line 217
def zip_one_liner(input)
    Garden.filter_by_zip(input).map do |g|
        puts "~*~ #{"#{g.gardenname}".blue} - #{"#{g.parksid}".magenta}"
        puts " "
    end
end