class NSWParks::Nsw_regions

Attributes

region_name[RW]
region_url[RW]

Public Class Methods

all() click to toggle source
# File lib/nswparks/nsw_regions.rb, line 14
def self.all
        @@all  # Access all created NSW National Parks Regions instances
end
create_region() click to toggle source

Create new NSW National Parks Regions from the National Parks website

# File lib/nswparks/nsw_regions.rb, line 19
def self.create_region
        page = Nokogiri::HTML(open("http://www.nationalparks.nsw.gov.au/visit-a-park/"))
        puts region = page.css("#mainParkNavJump .wrapper ul li a")
    region.collect {|a| new(a.text.strip, "http://www.nationalparks.nsw.gov.au#{a.attribute("href").value}")}
end
new(region_name, region_url) click to toggle source

Initialize each Nsw_regions instance with a region_name and region_url attribute, no default

# File lib/nswparks/nsw_regions.rb, line 8
def initialize(region_name, region_url)
        @region_name = region_name
        @region_url = region_url
        @@all << self
end
nsw_regions() click to toggle source

Show the Regions that NSW National Parks are listed within

# File lib/nswparks/nsw_regions.rb, line 26
    def self.nsw_regions
            array = []
            # Put out the list of Regions numerically
            @@all.collect.with_index(1) do |a,i| 
                    puts "#{i}. #{a.region_name}"
                    array << a.region_name
            end   
            array
end
park_region(region_no) click to toggle source

Output the National Parks for each region as requested

# File lib/nswparks/nsw_regions.rb, line 37
def self.park_region(region_no)
        region = @@all[region_no.to_i - 1]  # Select the region from the @@all array
        page = Nokogiri::HTML(open("#{region.region_url}"))
        link = page.css("#content__inner ul.detailRightColumn__linkList a")
        array = region_sort(link) # Remove areas that are not National Parks
        array
end
region_sort(link) click to toggle source

Removes areas that are not National Parks from the returned array

# File lib/nswparks/nsw_regions.rb, line 46
def self.region_sort(link)
             array = []
             clean = []
             link.collect {|a| array << a.children.text}
             array.select! {|a| a.include?("National")}
             # Remove leading and trailing white space from the park names
             clean = array.collect {|a| a.strip}
             clean
end