nswparks 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +5 -0
- data/bin/nswparks +1 -0
- data/lib/nswparks.rb +1 -2
- data/lib/nswparks/cli.rb +4 -3
- data/lib/nswparks/nsw_parks.rb +25 -90
- data/lib/nswparks/nsw_regions.rb +56 -0
- data/lib/nswparks/version.rb +1 -1
- data/pkg/nswparks-1.1.0.gem +0 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 78087eb45b071ab0358298f1e3bbd1cc10ec23f1
|
4
|
+
data.tar.gz: 1a13baf9ec13949ec590158874a4e48421ff51f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa4af3b093853c6bdc9063a1821cc9ce40751b6d3b7a875ae0820ef9a605aa8815feed8f474f43eed67f92227d18c7b47e5d7f5919298ff35ee5f3001f1104cb
|
7
|
+
data.tar.gz: 979f8b7c258bd1861c01ffac241f33130a928bb842267bede8d572c215191a146a02c922012684d1b8dc528e9d111021de9e7861869d30d046858559711c57e9
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -40,6 +40,11 @@ Run: `nswparks` after installing the gem.
|
|
40
40
|
|
41
41
|
Malki Davis for the hint to use system open
|
42
42
|
|
43
|
+
## Versions
|
44
|
+
* 1.0.0 - yanked as README.md incomplete
|
45
|
+
* 1.1.0 - added ability to auto open websites for the user
|
46
|
+
* 1.1.1 - added new class to simplify access to park regions
|
47
|
+
|
43
48
|
## Development
|
44
49
|
|
45
50
|
After checking out the repo, run `bundle exec bin/setup` to install dependencies. Then, run `bundle exec rake spec` to run the tests. You can also run `bundle exec bin/console` for an interactive prompt that will allow you to experiment.
|
data/bin/nswparks
CHANGED
data/lib/nswparks.rb
CHANGED
data/lib/nswparks/cli.rb
CHANGED
@@ -4,6 +4,7 @@ class NSWParks::CLI
|
|
4
4
|
# Loads all the NSW National Parks, puts out welcome message and starts the app
|
5
5
|
def call
|
6
6
|
NSWParks::Nsw_parks.new_park
|
7
|
+
NSWParks::Nsw_regions.create_region
|
7
8
|
puts ""
|
8
9
|
puts ""
|
9
10
|
puts " >------------------------------------------------<"
|
@@ -39,7 +40,7 @@ class NSWParks::CLI
|
|
39
40
|
# Puts out a list of the NSW Regions that contain National Parks using Nsw_parks #nsw_areas
|
40
41
|
def park_area
|
41
42
|
puts ""
|
42
|
-
NSWParks::
|
43
|
+
NSWParks::Nsw_regions.nsw_regions
|
43
44
|
end
|
44
45
|
|
45
46
|
# Puts out a list of National Parks in a selected NSW Region
|
@@ -56,14 +57,14 @@ class NSWParks::CLI
|
|
56
57
|
end
|
57
58
|
puts ""
|
58
59
|
puts "The parks in the #{areas[region_no.to_i - 1]} region are:"
|
59
|
-
array = NSWParks::
|
60
|
+
array = NSWParks::Nsw_regions.park_region(region_no.to_s)
|
60
61
|
array.each.with_index(1) {|a,i| puts "#{i}. #{a}"} # Puts parks in region using Nsw_parks
|
61
62
|
puts ""
|
62
63
|
puts "Enter your park number from this list for more information:"
|
63
64
|
input = gets.strip.to_i
|
64
65
|
# Validate user input - input must be numerical and exist in the list
|
65
66
|
while !(input.is_a? Integer) || input < 1 || input > array.length
|
66
|
-
array = NSWParks::
|
67
|
+
array = NSWParks::Nsw_regions.park_region(region_no.to_s)
|
67
68
|
array.each.with_index(1) {|a,i| puts "#{i}. #{a}"}
|
68
69
|
input = NSWParks::Nsw_parks.valid_input
|
69
70
|
end
|
data/lib/nswparks/nsw_parks.rb
CHANGED
@@ -16,7 +16,7 @@ class NSWParks::Nsw_parks
|
|
16
16
|
@@all # Access all created NSW National Parks instances
|
17
17
|
end
|
18
18
|
|
19
|
-
# Create new NSW National Parks from the National Parks
|
19
|
+
# Create new NSW National Parks from the National Parks website
|
20
20
|
def self.new_park
|
21
21
|
page = Nokogiri::HTML(open("http://www.nationalparks.nsw.gov.au/conservation-and-heritage/national-parks"))
|
22
22
|
park = page.css("#content__inner .dynamicListing li a")
|
@@ -41,93 +41,18 @@ class NSWParks::Nsw_parks
|
|
41
41
|
end
|
42
42
|
puts "----------------------------------------------------------------------------------------"
|
43
43
|
end
|
44
|
-
|
45
|
-
# Show the Regions that NSW National Parks are listed within
|
46
|
-
def self.nsw_areas
|
47
|
-
array = []
|
48
|
-
regions = Nokogiri::HTML(open("http://www.nationalparks.nsw.gov.au/visit-a-park"))
|
49
|
-
list = regions.css("#mainParkNavJump ul li")
|
50
|
-
# Put out the list of Regions numerically
|
51
|
-
list.collect.with_index(1) do |a,i|
|
52
|
-
puts "#{i}. #{a.children.text}"
|
53
|
-
array << a.children.text
|
54
|
-
end
|
55
|
-
array
|
56
|
-
end
|
57
|
-
|
58
|
-
# Output the National Parks for each of the seven NSW Regions from the individual region websites
|
59
|
-
def self.park_region(region_no)
|
60
|
-
array = []
|
61
|
-
case region_no
|
62
|
-
when "1" # Outback Region
|
63
|
-
region = Nokogiri::HTML(open("http://www.nationalparks.nsw.gov.au/visit-a-park/regions/outback"))
|
64
|
-
links = region.css("#content__inner ul.detailRightColumn__linkList a")
|
65
|
-
array = region_sort(links) # Remove areas that are not National Parks
|
66
|
-
array
|
67
|
-
when "2" # Country NSW Region
|
68
|
-
region = Nokogiri::HTML(open("http://www.nationalparks.nsw.gov.au/visit-a-park/regions/country-nsw"))
|
69
|
-
links = region.css("#content__inner ul.detailRightColumn__linkList a")
|
70
|
-
array = region_sort(links) # Remove areas that are not National Parks
|
71
|
-
array
|
72
|
-
when "3" # Murray Riverina Region
|
73
|
-
region = Nokogiri::HTML(open("http://www.nationalparks.nsw.gov.au/visit-a-park/regions/murray-riverina"))
|
74
|
-
links = region.css("#content__inner ul.detailRightColumn__linkList a")
|
75
|
-
array = region_sort(links) # Remove areas that are not National Parks
|
76
|
-
array
|
77
|
-
when "4" # North Coast Region
|
78
|
-
region = Nokogiri::HTML(open("http://www.nationalparks.nsw.gov.au/visit-a-park/regions/north-coast"))
|
79
|
-
links = region.css("#content__inner ul.detailRightColumn__linkList a")
|
80
|
-
array = region_sort(links) # Remove areas that are not National Parks
|
81
|
-
array
|
82
|
-
when "5" # South Coast Region
|
83
|
-
region = Nokogiri::HTML(open("http://www.nationalparks.nsw.gov.au/visit-a-park/regions/south-coast"))
|
84
|
-
links = region.css("#content__inner ul.detailRightColumn__linkList a")
|
85
|
-
array = region_sort(links) # Remove areas that are not National Parks
|
86
|
-
array
|
87
|
-
when "6" # Sydney and Surrounds Region
|
88
|
-
region = Nokogiri::HTML(open("http://www.nationalparks.nsw.gov.au/visit-a-park/regions/sydney-and-surrounds"))
|
89
|
-
links = region.css("#content__inner ul.detailRightColumn__linkList a")
|
90
|
-
array = region_sort(links) # Remove areas that are not National Parks
|
91
|
-
array
|
92
|
-
when "7" # Snowy Mountains Region
|
93
|
-
region = Nokogiri::HTML(open("http://www.nationalparks.nsw.gov.au/visit-a-park/regions/snowy-mountains"))
|
94
|
-
links = region.css("#content__inner ul.detailRightColumn__linkList a")
|
95
|
-
array = region_sort(links) # Remove areas that are not National Parks
|
96
|
-
array
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
# Removes areas that are not National Parks from the returned array
|
101
|
-
def self.region_sort(links)
|
102
|
-
array = []
|
103
|
-
clean = []
|
104
|
-
links.collect {|a| array << a.children.text}
|
105
|
-
array.select! {|a| a.include?("National")}
|
106
|
-
# Remove leading and trailing white space from the park names
|
107
|
-
clean = array.collect {|a| a.strip}
|
108
|
-
clean
|
109
|
-
end
|
110
44
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
# Find the park in region in the @@all array and return its overview
|
115
|
-
if a.name == park
|
116
|
-
park_overview(i + 1)
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
def self.valid_input
|
122
|
-
puts ""
|
45
|
+
# Validates the user input for all numerical user inputs
|
46
|
+
def self.valid_input
|
47
|
+
puts ""
|
123
48
|
puts "---------------------------------------------------------"
|
124
49
|
puts "Please enter one of the numbers from the list above:" # Prompt user to enter again
|
125
50
|
puts "---------------------------------------------------------"
|
126
51
|
gets.strip.to_i
|
127
|
-
|
52
|
+
end
|
128
53
|
|
129
|
-
|
130
|
-
|
54
|
+
# Accesses the website information for a selected NSW National Park
|
55
|
+
def self.park_url
|
131
56
|
input = 0
|
132
57
|
@@all.each.with_index(1) {|a,i| puts "#{i}. #{a.name}"} # Puts outs list of National Parks
|
133
58
|
puts ""
|
@@ -139,18 +64,28 @@ class NSWParks::Nsw_parks
|
|
139
64
|
input = valid_input
|
140
65
|
end
|
141
66
|
system("open #{@@all[input - 1].park_url}") # Puts out the park website address
|
142
|
-
|
67
|
+
end
|
68
|
+
|
69
|
+
# Return overview for a park using its listing under its region
|
70
|
+
def self.park_from_region(park)
|
71
|
+
@@all.each.with_index do |a,i|
|
72
|
+
# Find the park in region in the @@all array and return its overview
|
73
|
+
if a.name == park
|
74
|
+
park_overview(i + 1)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
143
78
|
|
144
|
-
|
145
|
-
|
146
|
-
system("open http://www.nationalparks.nsw.gov.au/nsw-state-map") #
|
147
|
-
|
79
|
+
# Provides user with a link to the map and instructions to open the link in their browser
|
80
|
+
def self.park_map
|
81
|
+
system("open http://www.nationalparks.nsw.gov.au/nsw-state-map") # Cannot scrape - hidden content
|
82
|
+
end
|
148
83
|
|
149
|
-
|
150
|
-
|
84
|
+
# Provides user with a link to guides and instructions to open the link in their browser
|
85
|
+
def self.park_guide
|
151
86
|
page = Nokogiri::HTML(open("http://www.nationalparks.nsw.gov.au"))
|
152
87
|
link = page.css("#headerNavBottom nav ul li#mainNav__about .box ul li[5] a")
|
153
|
-
system("open #{link.attribute("href").value}") # Puts out the website address
|
88
|
+
system("open #{link.attribute("href").value}") # Puts out the website address for the park guides
|
154
89
|
end
|
155
90
|
end
|
156
91
|
|
@@ -0,0 +1,56 @@
|
|
1
|
+
class NSWParks::Nsw_regions
|
2
|
+
|
3
|
+
attr_accessor :region_name, :region_url
|
4
|
+
|
5
|
+
@@all = [] # Collects all NSW National Parks Regions
|
6
|
+
|
7
|
+
# Initialize each Nsw_regions instance with a region_name and region_url attribute, no default
|
8
|
+
def initialize(region_name, region_url)
|
9
|
+
@region_name = region_name
|
10
|
+
@region_url = region_url
|
11
|
+
@@all << self
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.all
|
15
|
+
@@all # Access all created NSW National Parks Regions instances
|
16
|
+
end
|
17
|
+
|
18
|
+
# Create new NSW National Parks Regions from the National Parks website
|
19
|
+
def self.create_region
|
20
|
+
page = Nokogiri::HTML(open("http://www.nationalparks.nsw.gov.au/visit-a-park/"))
|
21
|
+
puts region = page.css("#mainParkNavJump .wrapper ul li a")
|
22
|
+
region.collect {|a| new(a.text.strip, "http://www.nationalparks.nsw.gov.au#{a.attribute("href").value}")}
|
23
|
+
end
|
24
|
+
|
25
|
+
# Show the Regions that NSW National Parks are listed within
|
26
|
+
def self.nsw_regions
|
27
|
+
array = []
|
28
|
+
# Put out the list of Regions numerically
|
29
|
+
@@all.collect.with_index(1) do |a,i|
|
30
|
+
puts "#{i}. #{a.region_name}"
|
31
|
+
array << a.region_name
|
32
|
+
end
|
33
|
+
array
|
34
|
+
end
|
35
|
+
|
36
|
+
# Output the National Parks for each region as requested
|
37
|
+
def self.park_region(region_no)
|
38
|
+
region = @@all[region_no.to_i - 1] # Select the region from the @@all array
|
39
|
+
page = Nokogiri::HTML(open("#{region.region_url}"))
|
40
|
+
link = page.css("#content__inner ul.detailRightColumn__linkList a")
|
41
|
+
array = region_sort(link) # Remove areas that are not National Parks
|
42
|
+
array
|
43
|
+
end
|
44
|
+
|
45
|
+
# Removes areas that are not National Parks from the returned array
|
46
|
+
def self.region_sort(link)
|
47
|
+
array = []
|
48
|
+
clean = []
|
49
|
+
link.collect {|a| array << a.children.text}
|
50
|
+
array.select! {|a| a.include?("National")}
|
51
|
+
# Remove leading and trailing white space from the park names
|
52
|
+
clean = array.collect {|a| a.strip}
|
53
|
+
clean
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
data/lib/nswparks/version.rb
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nswparks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Annette Drapalski
|
@@ -89,8 +89,10 @@ files:
|
|
89
89
|
- lib/nswparks.rb
|
90
90
|
- lib/nswparks/cli.rb
|
91
91
|
- lib/nswparks/nsw_parks.rb
|
92
|
+
- lib/nswparks/nsw_regions.rb
|
92
93
|
- lib/nswparks/version.rb
|
93
94
|
- nswparks.gemspec
|
95
|
+
- pkg/nswparks-1.1.0.gem
|
94
96
|
- spec.md
|
95
97
|
- spec/nswparks_spec.rb
|
96
98
|
- spec/spec_helper.rb
|