indie_bookstore_finder 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.learn +8 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +32 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +2 -0
- data/bin/console +13 -0
- data/bin/indie_bookstore_finder +5 -0
- data/bin/setup +8 -0
- data/config/environment.rb +11 -0
- data/indie_bookstore_finder.gemspec +38 -0
- data/lib/indie_bookstore_finder.rb +5 -0
- data/lib/indie_bookstore_finder/CLI.rb +178 -0
- data/lib/indie_bookstore_finder/city.rb +14 -0
- data/lib/indie_bookstore_finder/scraper.rb +57 -0
- data/lib/indie_bookstore_finder/scraper_test.rb +9 -0
- data/lib/indie_bookstore_finder/state.rb +14 -0
- data/lib/indie_bookstore_finder/store.rb +21 -0
- data/lib/indie_bookstore_finder/version.rb +3 -0
- data/spec.md +6 -0
- metadata +136 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 86692c4386af1c88774ed7ba63994c6dc6baa1956e61701a9ab80828c42e71eb
|
4
|
+
data.tar.gz: 314ab33b1f2ec8528c810a799c0be444bdf3f5ab4e7f7d0ba76d5ed3fc42b7ea
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c82366a8eff4438ede52b3e20cc7b3add7deb21f83b06642d8ebf67bac7e6639d3f4dde193470a930de08abf59deeaffc45f102151da9c19dd8d5a3b7319a204
|
7
|
+
data.tar.gz: de9624b7793488222dcc58230a6bac1930a41ed0e643702e3e34ecffb00de9628317eda91206f7b41d85ee0aaf7be20a228b1febc6d7ff06416a0855ccbeb355
|
data/.gitignore
ADDED
data/.learn
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 'faraday.elle@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/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
indie_bookstore_finder (0.1.0)
|
5
|
+
colorize
|
6
|
+
nokogiri
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
coderay (1.1.2)
|
12
|
+
colorize (0.8.1)
|
13
|
+
method_source (0.9.0)
|
14
|
+
mini_portile2 (2.3.0)
|
15
|
+
nokogiri (1.8.1)
|
16
|
+
mini_portile2 (~> 2.3.0)
|
17
|
+
pry (0.11.3)
|
18
|
+
coderay (~> 1.1.0)
|
19
|
+
method_source (~> 0.9.0)
|
20
|
+
rake (10.4.2)
|
21
|
+
|
22
|
+
PLATFORMS
|
23
|
+
ruby
|
24
|
+
|
25
|
+
DEPENDENCIES
|
26
|
+
bundler (~> 1.16)
|
27
|
+
indie_bookstore_finder!
|
28
|
+
pry
|
29
|
+
rake (~> 10.0)
|
30
|
+
|
31
|
+
BUNDLED WITH
|
32
|
+
1.16.0
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 'Elle Faraday'
|
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,43 @@
|
|
1
|
+
# IndieBookstoreFinder
|
2
|
+
|
3
|
+
Welcome to your Indie Bookstore Finder! This gem is a CLI app that finds independent stores organized by state and city. The data from this app is scraped from https://www.newpages.com/independent-bookstores.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'indie_bookstore_finder'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install indie_bookstore_finder
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Type the below and follow the on screen prompts.
|
24
|
+
|
25
|
+
$ indie_bookstore_finder
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
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](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/'ellefaraday'/indie_bookstore_finder. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
40
|
+
|
41
|
+
## Code of Conduct
|
42
|
+
|
43
|
+
Everyone interacting in the IndieBookstoreFinder project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/'ellefaraday'/indie_bookstore_finder/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
|
4
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
5
|
+
# with your gem easier. You can also use a different console, if you like.
|
6
|
+
|
7
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
8
|
+
# require "pry"
|
9
|
+
# Pry.start'
|
10
|
+
require "indie_bookstore_finder"
|
11
|
+
|
12
|
+
require "irb"
|
13
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require "bundler/setup"
|
2
|
+
require "indie_bookstore_finder"
|
3
|
+
require 'pry'
|
4
|
+
require 'nokogiri'
|
5
|
+
require 'open-uri'
|
6
|
+
require 'colorize'
|
7
|
+
require_relative "../lib/indie_bookstore_finder/city"
|
8
|
+
require_relative "../lib/indie_bookstore_finder/CLI"
|
9
|
+
require_relative "../lib/indie_bookstore_finder/scraper"
|
10
|
+
require_relative "../lib/indie_bookstore_finder/state"
|
11
|
+
require_relative "../lib/indie_bookstore_finder/store"
|
@@ -0,0 +1,38 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "indie_bookstore_finder/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "indie_bookstore_finder"
|
8
|
+
spec.version = IndieBookstoreFinder::VERSION
|
9
|
+
spec.authors = ["'Elle Faraday'"]
|
10
|
+
spec.email = ["'faraday.elle@gmail.com'"]
|
11
|
+
|
12
|
+
spec.summary = %q{Scraper CLI to find independent bookstores by state and city.}
|
13
|
+
spec.homepage = "https://github.com/ellefaraday/indie-bookstore-finder/"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
#if spec.respond_to?(:metadata)
|
19
|
+
# spec.metadata["allowed_push_host"] = "Set to 'http://mygemserver.com'"
|
20
|
+
#else
|
21
|
+
# raise "RubyGems 2.0 or newer is required to protect against " \
|
22
|
+
# "public gem pushes."
|
23
|
+
#end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
26
|
+
f.match(%r{^(test|spec|features)/})
|
27
|
+
end
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
33
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
34
|
+
spec.add_development_dependency "pry"
|
35
|
+
spec.add_dependency "nokogiri"
|
36
|
+
spec.add_dependency "colorize"
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,178 @@
|
|
1
|
+
class IndieBookstoreFinder::CLI
|
2
|
+
|
3
|
+
def call
|
4
|
+
@scraper = IndieBookstoreFinder::Scraper.new
|
5
|
+
@states = @scraper.scrape_index_page
|
6
|
+
puts "Welcome to Indie Bookstore Finder".cyan
|
7
|
+
puts "-----------------------"
|
8
|
+
puts "Shopping independent improves our communities!".magenta
|
9
|
+
puts "Hit return to get started finding an independent bookseller near you.".magenta
|
10
|
+
input = gets
|
11
|
+
state_page(@states)
|
12
|
+
end
|
13
|
+
|
14
|
+
def state_page(states)
|
15
|
+
print_states(states)
|
16
|
+
state_page_instructions(states)
|
17
|
+
end
|
18
|
+
|
19
|
+
def print_states(states)
|
20
|
+
states.each_with_index do |state, index|
|
21
|
+
puts "#{index + 1}. #{state.name}".blue
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def state_page_instructions(states)
|
26
|
+
puts "----------------------------------"
|
27
|
+
puts "Please select your state by entering the number from the list and pressing return.".red
|
28
|
+
puts "To exit enter 'exit'".red
|
29
|
+
state_number = gets.strip.downcase
|
30
|
+
if state_number == "exit"
|
31
|
+
exit_program
|
32
|
+
elsif state_number.to_i != 0 && states[state_number.to_i - 1] != nil
|
33
|
+
@selected_state = states[state_number.to_i - 1]
|
34
|
+
if @selected_state.cities == []
|
35
|
+
@scraper.scrape_state_page(@selected_state)
|
36
|
+
end
|
37
|
+
cities_page(@selected_state.cities)
|
38
|
+
else
|
39
|
+
input_error_message
|
40
|
+
state_page_instructions(states)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def cities_page(cities)
|
45
|
+
puts "We found independent bookstores in these cities in #{@selected_state.name}".cyan
|
46
|
+
print_cities(cities)
|
47
|
+
cities_page_instructions(cities)
|
48
|
+
end
|
49
|
+
|
50
|
+
def print_cities(cities)
|
51
|
+
cities.each_with_index do |city, index|
|
52
|
+
puts "#{index + 1}. #{city.name}".blue
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def cities_page_instructions(cities)
|
57
|
+
puts "----------------------------------"
|
58
|
+
puts "Please select a city by entering its number from the list and pressing return.".red
|
59
|
+
puts "To return to the list of states enter 'states'".red
|
60
|
+
puts "To exit enter 'exit'".red
|
61
|
+
city_number = gets.strip.downcase
|
62
|
+
if city_number == "exit"
|
63
|
+
exit_program
|
64
|
+
elsif city_number == "states"
|
65
|
+
state_page(@states)
|
66
|
+
elsif city_number.to_i != 0 && cities[city_number.to_i - 1] != nil
|
67
|
+
@selected_city = cities[city_number.to_i - 1]
|
68
|
+
store_list_page(@selected_city.stores)
|
69
|
+
else
|
70
|
+
input_error_message
|
71
|
+
cities_page_instructions(cities)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def store_list_page(stores)
|
76
|
+
puts "Here are the indie bookstores in #{@selected_city.name}, #{@selected_state.name}!".cyan
|
77
|
+
print_stores(stores)
|
78
|
+
store_list_page_instructions(stores)
|
79
|
+
end
|
80
|
+
|
81
|
+
def print_stores(stores)
|
82
|
+
stores.each_with_index do |store, index|
|
83
|
+
puts "#{index + 1}. #{store.name}".magenta
|
84
|
+
puts "#{store.address}"
|
85
|
+
puts ""
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def store_list_page_instructions(stores)
|
90
|
+
puts "----------------------------------"
|
91
|
+
puts "To see more information about a store by entering its number from the list and pressing return.".red
|
92
|
+
puts "To return to the list of cities in #{@selected_state.name} enter 'cities'".red
|
93
|
+
puts "To return to the list of states enter 'states'".red
|
94
|
+
puts "To exit enter 'exit'".red
|
95
|
+
store_number = gets.strip.downcase
|
96
|
+
if store_number == "exit"
|
97
|
+
exit_program
|
98
|
+
elsif store_number == "cities"
|
99
|
+
cities_page(@selected_state.cities)
|
100
|
+
elsif store_number == "states"
|
101
|
+
state_page(@states)
|
102
|
+
elsif store_number.to_i != 0 && stores[store_number.to_i - 1] != nil
|
103
|
+
@selected_store = stores[store_number.to_i - 1]
|
104
|
+
store_page(@selected_store)
|
105
|
+
else
|
106
|
+
input_error_message
|
107
|
+
store_list_page_instructions(stores)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def store_page(store)
|
112
|
+
print_store_details(store)
|
113
|
+
store_page_instructions(store)
|
114
|
+
end
|
115
|
+
|
116
|
+
def print_store_details(store)
|
117
|
+
puts "#{store.name}".underline.magenta
|
118
|
+
puts "#{store.address}"
|
119
|
+
if store.phone != nil
|
120
|
+
puts "Phone: #{store.phone}"
|
121
|
+
puts ""
|
122
|
+
end
|
123
|
+
if store.type != nil
|
124
|
+
puts "Type: #{store.type}".light_white
|
125
|
+
end
|
126
|
+
if store.specialty != nil
|
127
|
+
puts "Specialty: #{store.specialty}".light_white
|
128
|
+
end
|
129
|
+
if store.sidelines != nil
|
130
|
+
puts "Sidelines: #{store.sidelines}".light_white
|
131
|
+
end
|
132
|
+
if store.events != nil
|
133
|
+
puts "Events: #{store.events}".light_white
|
134
|
+
end
|
135
|
+
if store.website != nil
|
136
|
+
puts "Website: #{store.website}".light_white
|
137
|
+
end
|
138
|
+
if store.facebook != nil
|
139
|
+
puts "Facebook: #{store.facebook}".light_white
|
140
|
+
end
|
141
|
+
if store.twitter != nil
|
142
|
+
puts "Twitter: #{store.twitter}".light_white
|
143
|
+
end
|
144
|
+
if store.description != nil && store.description != ""
|
145
|
+
puts "Description: #{store.description}".light_white
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
def store_page_instructions(store)
|
150
|
+
puts "----------------------------------"
|
151
|
+
puts "To return to the list of stores in #{@selected_city.name} enter 'stores'".red
|
152
|
+
puts "To return to the list of cities in #{@selected_state.name} enter 'cities'".red
|
153
|
+
puts "To return to the list of states enter 'states'".red
|
154
|
+
puts "To exit enter 'exit'".red
|
155
|
+
input = gets.strip.downcase
|
156
|
+
if input == "exit"
|
157
|
+
exit_program
|
158
|
+
elsif input == "cities"
|
159
|
+
cities_page(@selected_state.cities)
|
160
|
+
elsif input == "states"
|
161
|
+
state_page(@states)
|
162
|
+
elsif input == "stores"
|
163
|
+
store_list_page(@selected_city.stores)
|
164
|
+
else
|
165
|
+
input_error_message
|
166
|
+
store_page(store)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
def exit_program
|
171
|
+
puts "Thank you for shopping independent! Happy Reading!".cyan
|
172
|
+
end
|
173
|
+
|
174
|
+
def input_error_message
|
175
|
+
puts "Sorry I don't recognize that input.".red
|
176
|
+
end
|
177
|
+
|
178
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
class IndieBookstoreFinder::Scraper
|
2
|
+
|
3
|
+
def get_index_page
|
4
|
+
Nokogiri::HTML(open("https://www.newpages.com/independent-bookstores"))
|
5
|
+
end
|
6
|
+
|
7
|
+
def scrape_index_page
|
8
|
+
self.get_index_page.css("div.np-span6.centered-list a").each do |state|
|
9
|
+
new_state = IndieBookstoreFinder::State.new
|
10
|
+
new_state.name = state.text.gsub(" Bookstores", "")
|
11
|
+
new_state.url = "https://www.newpages.com" + state.attribute("href").value
|
12
|
+
IndieBookstoreFinder::State.all << new_state
|
13
|
+
end
|
14
|
+
IndieBookstoreFinder::State.all
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_state_page(state)
|
18
|
+
Nokogiri::HTML(open("#{state.url}"))
|
19
|
+
end
|
20
|
+
|
21
|
+
def scrape_state_page(state)
|
22
|
+
@new_city = nil
|
23
|
+
self.get_state_page(state).css("div.catItemBody").each do |bookstore|
|
24
|
+
bookstore.css("ul li").each do |item|
|
25
|
+
if item.css("span:first-child").text == "City Title" && (@new_city == nil || @new_city.name != item.css("span:last-child").text)
|
26
|
+
@new_city = IndieBookstoreFinder::City.new
|
27
|
+
@new_city.name = item.css("span:last-child").text
|
28
|
+
state.cities << @new_city
|
29
|
+
IndieBookstoreFinder::City.all << @new_city
|
30
|
+
elsif item.css("span:first-child").text == "Title Link"
|
31
|
+
@new_store = IndieBookstoreFinder::Store.new
|
32
|
+
@new_store.name = item.css("span:last-child a").text
|
33
|
+
@new_store.website = item.css("span:last-child a").attribute("href").value
|
34
|
+
@new_store.city = @new_city
|
35
|
+
@new_city.stores << @new_store
|
36
|
+
elsif item.css("span:first-child").text == "Address 1"
|
37
|
+
@new_store.address = item.css("span:last-child").text
|
38
|
+
elsif item.css("span:first-child").text == "Phone"
|
39
|
+
@new_store.phone = item.css("span:last-child").text
|
40
|
+
elsif item.css("span:first-child").text == "Type"
|
41
|
+
@new_store.type = item.css("span:last-child").text
|
42
|
+
elsif item.css("span:first-child").text == "Specialty"
|
43
|
+
@new_store.specialty = item.css("span:last-child").text
|
44
|
+
elsif item.css("span:first-child").text == "Sidelines"
|
45
|
+
@new_store.sidelines = item.css("span:last-child").text
|
46
|
+
elsif item.css("span:first-child").text == "Events"
|
47
|
+
@new_store.events = item.css("span:last-child").text
|
48
|
+
elsif item.css("span:first-child").text == "Facebook"
|
49
|
+
@new_store.facebook = item.css("span:last-child a").attribute("href").value
|
50
|
+
elsif item.css("span:first-child").text == "Twitter"
|
51
|
+
@new_store.twitter = item.css("span:last-child a").attribute("href").value
|
52
|
+
end
|
53
|
+
end
|
54
|
+
@new_store.description = bookstore.css("catItemIntroText").text
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class IndieBookstoreFinder::Store
|
2
|
+
|
3
|
+
attr_accessor :name, :address, :phone, :type, :specialty, :sidelines, :events, :website, :facebook, :twitter, :description, :city
|
4
|
+
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@name = nil
|
8
|
+
@address = nil
|
9
|
+
@phone = nil
|
10
|
+
@type = nil
|
11
|
+
@specialty = nil
|
12
|
+
@sidelines = nil
|
13
|
+
@events = nil
|
14
|
+
@website = nil
|
15
|
+
@facebook = nil
|
16
|
+
@twitter = nil
|
17
|
+
@description = nil
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
end
|
data/spec.md
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
# Specifications for the CLI Assessment
|
2
|
+
|
3
|
+
Specs:
|
4
|
+
- [X] Have a CLI for interfacing with the application- CLI allows users to select a state, select a city, and select a bookstore.
|
5
|
+
- [X] Pull data from an external source- Data pulled from https://www.newpages.com/independent-bookstores
|
6
|
+
- [X] Implement both list and detail views- List views for state, city, and stores. Detail page for each store.
|
metadata
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: indie_bookstore_finder
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- "'Elle Faraday'"
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-12-20 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.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
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: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '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: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: colorize
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- "'faraday.elle@gmail.com'"
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".learn"
|
92
|
+
- CODE_OF_CONDUCT.md
|
93
|
+
- Gemfile
|
94
|
+
- Gemfile.lock
|
95
|
+
- LICENSE.txt
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- bin/console
|
99
|
+
- bin/indie_bookstore_finder
|
100
|
+
- bin/setup
|
101
|
+
- config/environment.rb
|
102
|
+
- indie_bookstore_finder.gemspec
|
103
|
+
- lib/indie_bookstore_finder.rb
|
104
|
+
- lib/indie_bookstore_finder/CLI.rb
|
105
|
+
- lib/indie_bookstore_finder/city.rb
|
106
|
+
- lib/indie_bookstore_finder/scraper.rb
|
107
|
+
- lib/indie_bookstore_finder/scraper_test.rb
|
108
|
+
- lib/indie_bookstore_finder/state.rb
|
109
|
+
- lib/indie_bookstore_finder/store.rb
|
110
|
+
- lib/indie_bookstore_finder/version.rb
|
111
|
+
- spec.md
|
112
|
+
homepage: https://github.com/ellefaraday/indie-bookstore-finder/
|
113
|
+
licenses:
|
114
|
+
- MIT
|
115
|
+
metadata: {}
|
116
|
+
post_install_message:
|
117
|
+
rdoc_options: []
|
118
|
+
require_paths:
|
119
|
+
- lib
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
requirements: []
|
131
|
+
rubyforge_project:
|
132
|
+
rubygems_version: 2.7.3
|
133
|
+
signing_key:
|
134
|
+
specification_version: 4
|
135
|
+
summary: Scraper CLI to find independent bookstores by state and city.
|
136
|
+
test_files: []
|