nswparks 1.0.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 +7 -0
- data/.rspec +2 -0
- data/.rspec_status +8 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +39 -0
- data/License.txt +21 -0
- data/README.md +61 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/nswparks +11 -0
- data/bin/setup +8 -0
- data/code_of_conduct.md +74 -0
- data/lib/nswparks.rb +14 -0
- data/lib/nswparks/cli.rb +144 -0
- data/lib/nswparks/nsw_parks.rb +170 -0
- data/lib/nswparks/version.rb +3 -0
- data/nswparks.gemspec +24 -0
- data/spec.md +8 -0
- data/spec/nswparks_spec.rb +28 -0
- data/spec/spec_helper.rb +11 -0
- metadata +122 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 525bc1aca1308de0f3d4318941237c89012f1b2a
|
4
|
+
data.tar.gz: 49bb75b21ac026197465df8cf2969c24ea8a2a03
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1dbc4de67a6f37a8ea0df9c10238341325f43ae8fa55f252618c64c3b0b2b98646fb9a4a5c10d28f0ee88bc7f41288f116c21b596de7d55acc0a24c38a6d5f90
|
7
|
+
data.tar.gz: 279fb23b1d36cbf5cc2dbfdfe5a26dea040f942ed27b4527f7937da45089e74fab56f001d8c794fa479f67583756e0653ebc0490581f6ed7fec5ea60de5a9121
|
data/.rspec
ADDED
data/.rspec_status
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
example_id | status | run_time |
|
2
|
+
------------------------------ | ------ | --------------- |
|
3
|
+
./spec/NSWParks_spec.rb[1:1] | passed | 0.00147 seconds |
|
4
|
+
./spec/NSWParks_spec.rb[2:1:1] | passed | 0.00288 seconds |
|
5
|
+
./spec/NSWParks_spec.rb[3:1] | passed | 1.69 seconds |
|
6
|
+
./spec/nswparks_spec.rb[1:1] | passed | 0.00605 seconds |
|
7
|
+
./spec/nswparks_spec.rb[2:1:1] | passed | 0.01128 seconds |
|
8
|
+
./spec/nswparks_spec.rb[3:1] | passed | 1.55 seconds |
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
nswparks (1.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.3)
|
10
|
+
mini_portile2 (2.1.0)
|
11
|
+
nokogiri (1.7.0.1)
|
12
|
+
mini_portile2 (~> 2.1.0)
|
13
|
+
rake (10.4.2)
|
14
|
+
rspec (3.5.0)
|
15
|
+
rspec-core (~> 3.5.0)
|
16
|
+
rspec-expectations (~> 3.5.0)
|
17
|
+
rspec-mocks (~> 3.5.0)
|
18
|
+
rspec-core (3.5.4)
|
19
|
+
rspec-support (~> 3.5.0)
|
20
|
+
rspec-expectations (3.5.0)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.5.0)
|
23
|
+
rspec-mocks (3.5.0)
|
24
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
25
|
+
rspec-support (~> 3.5.0)
|
26
|
+
rspec-support (3.5.0)
|
27
|
+
|
28
|
+
PLATFORMS
|
29
|
+
ruby
|
30
|
+
|
31
|
+
DEPENDENCIES
|
32
|
+
bundler (~> 1.14)
|
33
|
+
nokogiri (~> 1.7)
|
34
|
+
nswparks!
|
35
|
+
rake (~> 10.0)
|
36
|
+
rspec (~> 3.0)
|
37
|
+
|
38
|
+
BUNDLED WITH
|
39
|
+
1.14.6
|
data/License.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 adrapalski
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# nsw-national-parks-cli-app
|
2
|
+
|
3
|
+
CLI application for accessing information on National Parks in NSW Australia
|
4
|
+
## Table of Contents
|
5
|
+
* Introduction
|
6
|
+
* Included Features
|
7
|
+
* Installation
|
8
|
+
* Usage
|
9
|
+
* Development
|
10
|
+
* Contributing
|
11
|
+
* License
|
12
|
+
## Introduction
|
13
|
+
|
14
|
+
This is a Ruby Gem to provide the user with information on all
|
15
|
+
Australian National Parks overseen by the New South Wales (NSW)
|
16
|
+
State Government.
|
17
|
+
|
18
|
+
## Included Features
|
19
|
+
|
20
|
+
* It has a command line interface
|
21
|
+
* It interacts with the NSW National Parks website
|
22
|
+
* It returns a list of all National Parks in NSW
|
23
|
+
* It provides a url for each National Park in NSW
|
24
|
+
* It provides information on each National Park in NSW
|
25
|
+
* It provides the region for each National Park in NSW
|
26
|
+
* It provides the website for an interactive map of all National Parks in NSW
|
27
|
+
* It provides the website for downloading free pocket guides to each region in NSW
|
28
|
+
* It allows you to request information on each national park from the main list
|
29
|
+
and from the region list
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
## Installation
|
34
|
+
|
35
|
+
You can install this gem via gem install NSWParks. The NSWParks CLI will be installed and you can run NSWParks to get a list and information on NSW National Parks right in your command line.
|
36
|
+
|
37
|
+
## Usage
|
38
|
+
|
39
|
+
Run: NSWParks after installing the gem.
|
40
|
+
|
41
|
+
## Development
|
42
|
+
|
43
|
+
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.
|
44
|
+
|
45
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to rubygems.org.
|
46
|
+
|
47
|
+
To run the development version of the CLI run `bundle exec bin/NSWParks`.
|
48
|
+
|
49
|
+
## Contributing
|
50
|
+
|
51
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/apalski/nsw-national-parks-cli-app. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
|
52
|
+
|
53
|
+
## License
|
54
|
+
|
55
|
+
The gem is available as open source under the terms of the MIT License.
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "nswparks"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/nswparks
ADDED
data/bin/setup
ADDED
data/code_of_conduct.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at annette.drapalski@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/lib/nswparks.rb
ADDED
data/lib/nswparks/cli.rb
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
|
2
|
+
class NSWParks::CLI
|
3
|
+
|
4
|
+
# Loads all the NSW National Parks, puts out welcome message and starts the app
|
5
|
+
def call
|
6
|
+
NSWParks::Nsw_parks.new_park
|
7
|
+
puts ""
|
8
|
+
puts ""
|
9
|
+
puts " >------------------------------------------------<"
|
10
|
+
puts "{ Welcome to the Unofficial NSW National Parks App }"
|
11
|
+
puts " >------------------------------------------------<"
|
12
|
+
start
|
13
|
+
end
|
14
|
+
|
15
|
+
# Puts out a numerical list of all NSW National Parks
|
16
|
+
def park_list
|
17
|
+
NSWParks::Nsw_parks.all.each.with_index(1) {|a,i| puts "#{i}. #{a.name}"} # Start array index from 1 not 0
|
18
|
+
end
|
19
|
+
|
20
|
+
# Puts out information on a selected NSW National Park using #park_list
|
21
|
+
def park_info
|
22
|
+
park_list
|
23
|
+
park_no = 0
|
24
|
+
puts ""
|
25
|
+
puts "Enter the number for the park you are interested in:"
|
26
|
+
park_no = gets.strip.to_i
|
27
|
+
# Validate user input - input must be an integer and exist in the list
|
28
|
+
while !(park_no.is_a? Integer) || park_no < 1 || park_no > NSWParks::Nsw_parks.all.length
|
29
|
+
park_list
|
30
|
+
puts ""
|
31
|
+
puts "-----------------------------------------------"
|
32
|
+
puts "Please enter a park number from the list above:" # Prompt user to enter again
|
33
|
+
puts "-----------------------------------------------"
|
34
|
+
park_no = gets.strip.to_i
|
35
|
+
end
|
36
|
+
puts ""
|
37
|
+
puts NSWParks::Nsw_parks.all[park_no - 1].name # Gives returned park info a heading of the park name
|
38
|
+
puts ""
|
39
|
+
puts "----------------------------------------------------------------------------------------"
|
40
|
+
NSWParks::Nsw_parks.park_overview(park_no) # Puts out park info using Nsw_parks #park_overview
|
41
|
+
end
|
42
|
+
|
43
|
+
# Puts out a list of the NSW Regions that contain National Parks using Nsw_parks #nsw_areas
|
44
|
+
def park_area
|
45
|
+
puts ""
|
46
|
+
NSWParks::Nsw_parks.nsw_areas
|
47
|
+
end
|
48
|
+
|
49
|
+
# Puts out a list of National Parks in a selected NSW Region
|
50
|
+
def park_region
|
51
|
+
region_no = 0
|
52
|
+
input = 0
|
53
|
+
areas = park_area # Use #park_area to output list of NSW Regions
|
54
|
+
puts "Enter the number for the region you are interested in:"
|
55
|
+
region_no = gets.strip.to_i
|
56
|
+
# Validate user input - input must be numerical and exist in the list
|
57
|
+
while !(region_no.is_a? Integer) || region_no < 1 || region_no > areas.length
|
58
|
+
park_area
|
59
|
+
puts ""
|
60
|
+
puts "--------------------------------------------------"
|
61
|
+
puts "Please enter one of the regions in the list above:" # Prompt user to enter again
|
62
|
+
puts "--------------------------------------------------"
|
63
|
+
region_no = gets.strip.to_i
|
64
|
+
end
|
65
|
+
puts ""
|
66
|
+
puts "The parks in the #{areas[region_no.to_i - 1]} region are:"
|
67
|
+
array = NSWParks::Nsw_parks.park_region(region_no.to_s)
|
68
|
+
array.each.with_index(1) {|a,i| puts "#{i}. #{a}"} # Puts parks in region using Nsw_parks
|
69
|
+
puts ""
|
70
|
+
puts "Enter your park number from this list for more information:"
|
71
|
+
input = gets.strip.to_i
|
72
|
+
# Validate user input - input must be numerical and exist in the list
|
73
|
+
while !(input.is_a? Integer) || input < 1 || input > array.length
|
74
|
+
array = NSWParks::Nsw_parks.park_region(region_no.to_s)
|
75
|
+
array.each.with_index(1) {|a,i| puts "#{i}. #{a}"}
|
76
|
+
puts ""
|
77
|
+
puts "---------------------------------------------------------"
|
78
|
+
puts "Please enter one of the park numbers from the list above:" # Prompt user to enter again
|
79
|
+
puts "---------------------------------------------------------"
|
80
|
+
input = gets.strip.to_i
|
81
|
+
end
|
82
|
+
puts ""
|
83
|
+
puts "Information for #{array[input - 1]}:" # Puts out heading of park name
|
84
|
+
puts "----------------------------------------------------------------------------------------"
|
85
|
+
# Puts out parks info using Nsw_parks #park_from_region to locate park in @@all
|
86
|
+
NSWParks::Nsw_parks.park_from_region(array[input - 1])
|
87
|
+
end
|
88
|
+
|
89
|
+
# Accesses the website information for a selected NSW National Park using Nsw_parks #park_url
|
90
|
+
def park_url
|
91
|
+
puts ""
|
92
|
+
NSWParks::Nsw_parks.park_url
|
93
|
+
end
|
94
|
+
|
95
|
+
# Accesses the website information for an interactive map of all parks using Nsw_parks #park_map
|
96
|
+
def park_map
|
97
|
+
puts ""
|
98
|
+
NSWParks::Nsw_parks.park_map
|
99
|
+
end
|
100
|
+
|
101
|
+
# Accesses the website information for free park guide downloads using Nsw_parks #park_guide
|
102
|
+
def park_guide
|
103
|
+
puts ""
|
104
|
+
NSWParks::Nsw_parks.park_guide
|
105
|
+
end
|
106
|
+
|
107
|
+
# Starts the app and gives users the available options for the app
|
108
|
+
def start
|
109
|
+
answer = 0
|
110
|
+
while answer != "exit"
|
111
|
+
puts ""
|
112
|
+
puts "For a list of NSW National Parks and information on a park enter 'info"
|
113
|
+
puts "To exit the program enter 'exit'"
|
114
|
+
puts "To see the National Park regions in NSW and choose a park by its region enter 'region'"
|
115
|
+
puts "To access a interactive map of all National Parks in NSW enter 'map'"
|
116
|
+
puts "To download a free pocket guide for NSW National Park Regions enter 'guide'"
|
117
|
+
puts "To visit the website for a National Park enter 'url'"
|
118
|
+
puts ""
|
119
|
+
answer = gets.strip
|
120
|
+
if answer == "info"
|
121
|
+
park_info
|
122
|
+
elsif answer == "region"
|
123
|
+
park_region
|
124
|
+
elsif answer == "url"
|
125
|
+
park_url
|
126
|
+
elsif answer == "map"
|
127
|
+
park_map
|
128
|
+
elsif answer == "guide"
|
129
|
+
park_guide
|
130
|
+
# Validates the user input
|
131
|
+
elsif answer != "exit"
|
132
|
+
puts ""
|
133
|
+
puts "---------------------------------------------"
|
134
|
+
puts "Please enter one of the options from the list" # Prompt user to enter again
|
135
|
+
puts "---------------------------------------------"
|
136
|
+
end
|
137
|
+
end
|
138
|
+
puts ""
|
139
|
+
puts "---------------------------------------------------------"
|
140
|
+
puts "Thank you for using the Unofficial NSW National Parks App"
|
141
|
+
puts "---------------------------------------------------------"
|
142
|
+
puts ""
|
143
|
+
end
|
144
|
+
end
|
@@ -0,0 +1,170 @@
|
|
1
|
+
|
2
|
+
class NSWParks::Nsw_parks
|
3
|
+
|
4
|
+
attr_accessor :name, :park_url, :park_region
|
5
|
+
|
6
|
+
@@all = [] # Collects all NSW National Parks
|
7
|
+
|
8
|
+
# Initialize each Nsw_parks instance with a name and park_url attribute, no default
|
9
|
+
def initialize (name, park_url)
|
10
|
+
@name = name
|
11
|
+
@park_url = park_url
|
12
|
+
@@all << self # Add each new NSW National Park instance to the collection as it is created
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.all
|
16
|
+
@@all # Access all created NSW National Parks instances
|
17
|
+
end
|
18
|
+
|
19
|
+
# Create new NSW National Parks from the National Parks webstie
|
20
|
+
def self.new_park
|
21
|
+
page = Nokogiri::HTML(open("http://www.nationalparks.nsw.gov.au/conservation-and-heritage/national-parks"))
|
22
|
+
park = page.css("#content__inner .dynamicListing li a")
|
23
|
+
park.collect {|a| new(a.text.strip, a.attribute("href").value)}
|
24
|
+
end
|
25
|
+
|
26
|
+
# Instructions to the user on how to use the provided website links
|
27
|
+
def self.url_use
|
28
|
+
puts "<------------------------------------------------------------------------------->"
|
29
|
+
puts " Right-click or Control-click on the website address above and select 'open url'"
|
30
|
+
puts " from the dropdown menu!! This will open the website in your default browser "
|
31
|
+
puts "<------------------------------------------------------------------------------->"
|
32
|
+
end
|
33
|
+
|
34
|
+
# Allow users to access information on any NSW National Park
|
35
|
+
def self.park_overview(park_no)
|
36
|
+
check = ""
|
37
|
+
# Select the park from the list in @@all using the park's park_url attribute
|
38
|
+
park = Nokogiri::HTML(open("#{@@all[park_no - 1].park_url}"))
|
39
|
+
# Description of the park and its attractions
|
40
|
+
check = park.css("#content__inner div.overviewIntro div.overviewIntro__readMoreText p")
|
41
|
+
# If there is no overview available display alternative text for the park
|
42
|
+
if check.empty?
|
43
|
+
puts park.css("#content__inner div.overviewIntro p").text
|
44
|
+
link = park.css("#content__inner div.overviewIntro a")
|
45
|
+
puts "The OEH website can be found at #{link.attribute("href").value}"
|
46
|
+
url_use # Instructions to the user on how to use the provided website links
|
47
|
+
else # If overview available put that out to the user
|
48
|
+
puts park.css("#content__inner div.overviewIntro div.overviewIntro__readMoreText p").text
|
49
|
+
end
|
50
|
+
puts "----------------------------------------------------------------------------------------"
|
51
|
+
end
|
52
|
+
|
53
|
+
# Show the Regions that NSW National Parks are listed within
|
54
|
+
def self.nsw_areas
|
55
|
+
array = []
|
56
|
+
regions = Nokogiri::HTML(open("http://www.nationalparks.nsw.gov.au/visit-a-park"))
|
57
|
+
list = regions.css("#mainParkNavJump ul li")
|
58
|
+
# Put out the list of Regions numerically
|
59
|
+
list.collect.with_index(1) do |a,i|
|
60
|
+
puts "#{i}. #{a.children.text}"
|
61
|
+
array << a.children.text
|
62
|
+
end
|
63
|
+
array
|
64
|
+
end
|
65
|
+
|
66
|
+
# Output the National Parks for each of the seven NSW Regions from the individual region websites
|
67
|
+
def self.park_region(region_no)
|
68
|
+
array = []
|
69
|
+
case region_no
|
70
|
+
when "1" # Outback Region
|
71
|
+
region = Nokogiri::HTML(open("http://www.nationalparks.nsw.gov.au/visit-a-park/regions/outback"))
|
72
|
+
links = region.css("#content__inner ul.detailRightColumn__linkList a")
|
73
|
+
array = region_sort(links) # Remove areas that are not National Parks
|
74
|
+
array
|
75
|
+
when "2" # Country NSW Region
|
76
|
+
region = Nokogiri::HTML(open("http://www.nationalparks.nsw.gov.au/visit-a-park/regions/country-nsw"))
|
77
|
+
links = region.css("#content__inner ul.detailRightColumn__linkList a")
|
78
|
+
array = region_sort(links) # Remove areas that are not National Parks
|
79
|
+
array
|
80
|
+
when "3" # Murray Riverina Region
|
81
|
+
region = Nokogiri::HTML(open("http://www.nationalparks.nsw.gov.au/visit-a-park/regions/murray-riverina"))
|
82
|
+
links = region.css("#content__inner ul.detailRightColumn__linkList a")
|
83
|
+
array = region_sort(links) # Remove areas that are not National Parks
|
84
|
+
array
|
85
|
+
when "4" # North Coast Region
|
86
|
+
region = Nokogiri::HTML(open("http://www.nationalparks.nsw.gov.au/visit-a-park/regions/north-coast"))
|
87
|
+
links = region.css("#content__inner ul.detailRightColumn__linkList a")
|
88
|
+
array = region_sort(links) # Remove areas that are not National Parks
|
89
|
+
array
|
90
|
+
when "5" # South Coast Region
|
91
|
+
region = Nokogiri::HTML(open("http://www.nationalparks.nsw.gov.au/visit-a-park/regions/south-coast"))
|
92
|
+
links = region.css("#content__inner ul.detailRightColumn__linkList a")
|
93
|
+
array = region_sort(links) # Remove areas that are not National Parks
|
94
|
+
array
|
95
|
+
when "6" # Sydney and Surrounds Region
|
96
|
+
region = Nokogiri::HTML(open("http://www.nationalparks.nsw.gov.au/visit-a-park/regions/sydney-and-surrounds"))
|
97
|
+
links = region.css("#content__inner ul.detailRightColumn__linkList a")
|
98
|
+
array = region_sort(links) # Remove areas that are not National Parks
|
99
|
+
array
|
100
|
+
when "7" # Snowy Mountains Region
|
101
|
+
region = Nokogiri::HTML(open("http://www.nationalparks.nsw.gov.au/visit-a-park/regions/snowy-mountains"))
|
102
|
+
links = region.css("#content__inner ul.detailRightColumn__linkList a")
|
103
|
+
array = region_sort(links) # Remove areas that are not National Parks
|
104
|
+
array
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
# Removes areas that are not National Parks from the returned array
|
109
|
+
def self.region_sort(links)
|
110
|
+
array = []
|
111
|
+
clean = []
|
112
|
+
links.collect {|a| array << a.children.text}
|
113
|
+
array.select! {|a| a.include?("National")}
|
114
|
+
# Remove leading and trailing white space from the park names
|
115
|
+
clean = array.collect {|a| a.strip}
|
116
|
+
clean
|
117
|
+
end
|
118
|
+
|
119
|
+
# Return overview for a park using its listing under its region
|
120
|
+
def self.park_from_region(park)
|
121
|
+
@@all.each.with_index do |a,i|
|
122
|
+
# Find the park in region in the @@all array and return its overview
|
123
|
+
if a.name == park
|
124
|
+
park_overview(i + 1)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
# Accesses the website information for a selected NSW National Park
|
130
|
+
def self.park_url
|
131
|
+
input = 0
|
132
|
+
array = 0
|
133
|
+
@@all.each.with_index(1) {|a,i| puts "#{i}. #{a.name}"} # Puts outs list of National Parks
|
134
|
+
puts ""
|
135
|
+
puts "Select the park number from above and enter the number to access the website address"
|
136
|
+
input = gets.strip.to_i
|
137
|
+
# Validate user input - input must be numerical and exist in the list
|
138
|
+
while !(input.is_a? Integer) || input < 1 || input > @@all.length
|
139
|
+
@@all.each.with_index(1) {|a,i| puts "#{i}. #{a.name}"} # Puts outs list of National Parks
|
140
|
+
puts ""
|
141
|
+
puts "----------------------------------------------"
|
142
|
+
puts "Please enter a park number from the list above:" # Prompt user to enter again
|
143
|
+
puts "----------------------------------------------"
|
144
|
+
input = gets.strip.to_i
|
145
|
+
end
|
146
|
+
puts ""
|
147
|
+
puts "The website address for #{@@all[input - 1].name} is:" # Puts a heading of the park name
|
148
|
+
puts ""
|
149
|
+
puts @@all[input - 1].park_url # Puts out the park website address
|
150
|
+
puts ""
|
151
|
+
url_use # Instructions to the user on how to use the provided website links
|
152
|
+
end
|
153
|
+
|
154
|
+
# Provides user with a link to the map and instructions to open the link in their browser
|
155
|
+
def self.park_map
|
156
|
+
puts "http://www.nationalparks.nsw.gov.au/nsw-state-map" # No url to scrape - hidden
|
157
|
+
puts ""
|
158
|
+
url_use # Instructions to the user on how to use the provided website links
|
159
|
+
end
|
160
|
+
|
161
|
+
# Provides user with a link to guides and instructions to open the link in their browser
|
162
|
+
def self.park_guide
|
163
|
+
page = Nokogiri::HTML(open("http://www.nationalparks.nsw.gov.au"))
|
164
|
+
link = page.css("#headerNavBottom nav ul li#mainNav__about .box ul li[5] a")
|
165
|
+
puts link.attribute("href").value # Puts out the website address forthe park guides
|
166
|
+
puts ""
|
167
|
+
url_use # Instructions to the user on how to use the provided website links
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
data/nswparks.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'nswparks/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "nswparks"
|
8
|
+
spec.version = NSWParks::VERSION
|
9
|
+
spec.authors = ["Annette Drapalski"]
|
10
|
+
spec.email = ["annette.drapalski@gmail.com"]
|
11
|
+
spec.summary = %q{Supply information on NSW National Parks}
|
12
|
+
spec.description = %q{Access to information on National Parks in the Australian State of New South Wales}
|
13
|
+
spec.homepage = "http://rubygems.org/gems/nswparks"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($\)
|
17
|
+
spec.executables = ["nswparks"]
|
18
|
+
spec.require_paths = ["lib", "lib/nswparks"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
21
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
23
|
+
spec.add_development_dependency "nokogiri", "~> 1.7"
|
24
|
+
end
|
data/spec.md
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
# Specifications for the CLI Assessment
|
2
|
+
|
3
|
+
Specs:
|
4
|
+
- [X] Have a CLI for interfacing with the application - /lib contains cli.rb and nsw_parks.rb - cli.rb
|
5
|
+
controls the majority of the interfacing with the user
|
6
|
+
- [X] Pull data from an external source - data is pulled from http://www.nationalparks.nsw.gov.au/
|
7
|
+
- [X] Implement both list and detail views - the user is supplied with park and region lists and can select a detail view for more information on each NSW National Park
|
8
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
describe NSWParks do
|
3
|
+
it "has a version number" do
|
4
|
+
expect(NSWParks::VERSION).not_to be nil
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
describe 'NSWPark' do
|
9
|
+
describe '#initialize' do
|
10
|
+
it 'sets the name of the park in @name and sets the url in @park_url and adds the park instance to @@all' do
|
11
|
+
park = NSWParks::Nsw_parks.new("Ben Boyd National Park", "http://www.nationalparks.nsw.gov.au/visit-a-park/parks/ben-boyd-national-park")
|
12
|
+
|
13
|
+
expect(park.instance_variable_get(:@name)).to eq("Ben Boyd National Park")
|
14
|
+
expect(park.instance_variable_get(:@park_url)).to eq("http://www.nationalparks.nsw.gov.au/visit-a-park/parks/ben-boyd-national-park")
|
15
|
+
expect(NSWParks::Nsw_parks.all).to include(park)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#new_park" do
|
21
|
+
it "uses Nokogiri to get the HTML from a web page" do
|
22
|
+
page = Nokogiri::HTML(open("http://www.nationalparks.nsw.gov.au/conservation-and-heritage/national-parks"))
|
23
|
+
expect{NSWParks::Nsw_parks.new_park}.to_not raise_error
|
24
|
+
expect(page).to be_a(Nokogiri::HTML::Document)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require "bundler/setup"
|
2
|
+
require "nswparks"
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
# Enable flags like --only-failures and --next-failure
|
6
|
+
config.example_status_persistence_file_path = ".rspec_status"
|
7
|
+
|
8
|
+
config.expect_with :rspec do |c|
|
9
|
+
c.syntax = :expect
|
10
|
+
end
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nswparks
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Annette Drapalski
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: nokogiri
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.7'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.7'
|
69
|
+
description: Access to information on National Parks in the Australian State of New
|
70
|
+
South Wales
|
71
|
+
email:
|
72
|
+
- annette.drapalski@gmail.com
|
73
|
+
executables:
|
74
|
+
- nswparks
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- ".rspec"
|
79
|
+
- ".rspec_status"
|
80
|
+
- Gemfile
|
81
|
+
- Gemfile.lock
|
82
|
+
- License.txt
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- bin/console
|
86
|
+
- bin/nswparks
|
87
|
+
- bin/setup
|
88
|
+
- code_of_conduct.md
|
89
|
+
- lib/nswparks.rb
|
90
|
+
- lib/nswparks/cli.rb
|
91
|
+
- lib/nswparks/nsw_parks.rb
|
92
|
+
- lib/nswparks/version.rb
|
93
|
+
- nswparks.gemspec
|
94
|
+
- spec.md
|
95
|
+
- spec/nswparks_spec.rb
|
96
|
+
- spec/spec_helper.rb
|
97
|
+
homepage: http://rubygems.org/gems/nswparks
|
98
|
+
licenses:
|
99
|
+
- MIT
|
100
|
+
metadata: {}
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
- lib/nswparks
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
requirements: []
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 2.6.11
|
119
|
+
signing_key:
|
120
|
+
specification_version: 4
|
121
|
+
summary: Supply information on NSW National Parks
|
122
|
+
test_files: []
|