Brew_Finder 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fcaa9f2cc367a46534ff08ea636feafa44065189
4
+ data.tar.gz: 14c5bd6dd95c26c6a119e7729e7007e118c309c8
5
+ SHA512:
6
+ metadata.gz: c4cc13d5ae97c9c309f5fe70052d268be57873c2e14ade6bb175d165e7cf07e28f24afe886783b4810e440b47720985687a2eac032dfad664dbee657c7dd70ae
7
+ data.tar.gz: 80806cb22c53f8ba1504fe3a051671b73eacfdf96de94246c67efc1ab8756536d7bc188c7e6f87a5d6c62169a9be8f8c42cf12b758b0d48a19088a71dd720c87
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ /.learn/
2
+ /.tinycli.rb/
3
+ /.spec.md/
4
+ /.api_query_tester.rb/
data/.gitmodules ADDED
@@ -0,0 +1,3 @@
1
+ [submodule "examples/now-playing-cli-gem"]
2
+ path = examples/now-playing-cli-gem
3
+ url = git@github.com:learn-co-curriculum/now-playing-cli-gem.git
data/.learn ADDED
@@ -0,0 +1,8 @@
1
+ tags:
2
+ - cli
3
+ - gem
4
+ - oo
5
+ languages:
6
+ - ruby
7
+ resources:
8
+ live_assessment: true
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,37 @@
1
+ # Contributing to Learn.co Curriculum
2
+
3
+ We're really exited that you're about to contribute to the [open curriculum](https://learn.co/content-license) on [Learn.co](https://learn.co). If this is your first time contributing, please continue reading to learn how to make the most meaningful and useful impact possible.
4
+
5
+ ## Raising an Issue to Encourage a Contribution
6
+
7
+ If you notice a problem with the curriculum that you believe needs improvement
8
+ but you're unable to make the change yourself, you should raise a Github issue
9
+ containing a clear description of the problem. Include relevant snippets of
10
+ the content and/or screenshots if applicable. Curriculum owners regularly review
11
+ issue lists and your issue will be prioritized and addressed as appropriate.
12
+
13
+ ## Submitting a Pull Request to Suggest an Improvement
14
+
15
+ If you see an opportunity for improvement and can make the change yourself go
16
+ ahead and use a typical git workflow to make it happen:
17
+
18
+ * Fork this curriculum repository
19
+ * Make the change on your fork, with descriptive commits in the standard format
20
+ * Open a Pull Request against this repo
21
+
22
+ A curriculum owner will review your change and approve or comment on it in due
23
+ course.
24
+
25
+ # Why Contribute?
26
+
27
+ Curriculum on Learn is publicly and freely available under Learn's
28
+ [Educational Content License](https://learn.co/content-license). By
29
+ embracing an open-source contribution model, our goal is for the curriculum
30
+ on Learn to become, in time, the best educational content the world has
31
+ ever seen.
32
+
33
+ We need help from the community of Learners to maintain and improve the
34
+ educational content. Everything from fixing typos, to correcting
35
+ out-dated information, to improving exposition, to adding better examples,
36
+ to fixing tests—all contributions to making the curriculum more effective are
37
+ welcome.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in brew_finder.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,26 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ Brew_Finder (0.1.0)
5
+ nokogiri
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ mini_portile2 (2.1.0)
11
+ nokogiri (1.6.8)
12
+ mini_portile2 (~> 2.1.0)
13
+ pkg-config (~> 1.1.7)
14
+ pkg-config (1.1.7)
15
+ rake (11.2.2)
16
+
17
+ PLATFORMS
18
+ ruby
19
+
20
+ DEPENDENCIES
21
+ Brew_Finder!
22
+ bundler (~> 1.5)
23
+ rake
24
+
25
+ BUNDLED WITH
26
+ 1.12.5
data/LICENSE.md ADDED
@@ -0,0 +1,7 @@
1
+ #Learn.co Educational Content License
2
+
3
+ Copyright (c) 2015 Flatiron School, Inc
4
+
5
+ The Flatiron School, Inc. owns this Educational Content. However, the Flatiron School supports the development and availability of educational materials in the public domain. Therefore, the Flatiron School grants Users of the Flatiron Educational Content set forth in this repository certain rights to reuse, build upon and share such Educational Content subject to the terms of the Educational Content License set forth [here](http://learn.co/content-license) (http://learn.co/content-license). You must read carefully the terms and conditions contained in the Educational Content License as such terms govern access to and use of the Educational Content.
6
+
7
+ Flatiron School is willing to allow you access to and use of the Educational Content only on the condition that you accept all of the terms and conditions contained in the Educational Content License set forth [here](http://learn.co/content-license) (http://learn.co/content-license). By accessing and/or using the Educational Content, you are agreeing to all of the terms and conditions contained in the Educational Content License. If you do not agree to any or all of the terms of the Educational Content License, you are prohibited from accessing, reviewing or using in any way the Educational Content.
data/README.md ADDED
@@ -0,0 +1,56 @@
1
+ #BrewFinder
2
+
3
+ The BrewFinder gem was built to fetch and display data on local breweries/brewpubs.
4
+
5
+
6
+ [![Gem Version](https://badge.fury.io/rb/brew_finder.svg)](https://badge.fury.io/rb/brew_finder)
7
+
8
+ SharksAhead cli gem was built to scrape and display information about living and extinct shark species.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'brew_finder'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install brew_finder
25
+
26
+ ## Usage
27
+
28
+ o©ºº©oo©oº°©
29
+ / \
30
+ |___________|____
31
+ | |____)
32
+ | WELCOME | | |
33
+ | | | |
34
+ | TO | | |
35
+ | | | |
36
+ | B R E W | | |
37
+ | |__|_|
38
+ | FINDER! |____)
39
+ |____________|
40
+ (______________)
41
+
42
+ This gem is intended to be used to find local breweries/brewpubs that have been submitted to the Beer Mapping Project. http://beermapping.com/
43
+ ## Development
44
+
45
+ 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.
46
+
47
+ 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).
48
+
49
+ ## Contributing
50
+
51
+ Bug reports and pull requests are welcome on GitHub at https://github.com/becky000/sharks_ahead. 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.
52
+
53
+
54
+ ## License
55
+
56
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,33 @@
1
+ require 'open-uri'
2
+ require 'nokogiri'
3
+
4
+ api_request = Nokogiri::XML(open("http://beermapping.com/webservice/loccity/21110efff66df69d91ec3909c0a38eed/providence,ri"))
5
+ breweries = []
6
+ #we gotta use something called xpath?
7
+ api_request.xpath("//location").each do |location|
8
+ brewery = {
9
+ :id => location.xpath("child::id").text.to_i,
10
+ :name => location.xpath("child::name").text,
11
+ :street_address => location.xpath("child::street").text,
12
+ :phone => location.xpath("child::phone").text
13
+ }
14
+ #add brewery to breweries
15
+ breweries << brewery
16
+ #puts "#{brewery}"
17
+ end
18
+
19
+ returned_scores = Nokogiri::HTML(open("http://beermapping.com/webservice/locscore/21110efff66df69d91ec3909c0a38eed/15566"))
20
+ #brewery score profile
21
+ score_location = returned_scores.xpath("//location")
22
+ score_profile = {
23
+ #overall_score, selection, service, atmosphere, food, review_count, fb_score, fb_count
24
+ :overall_score => score_location.xpath("child::overall").text.to_f,
25
+ :selection => score_location.xpath("child::selection").text.to_f,
26
+ :service => score_location.xpath("child::service").text.to_f,
27
+ :atmosphere => score_location.xpath("child::atmosphere").text.to_f,
28
+ :review_count => score_location.xpath("child::reviewcount").text.to_f,
29
+ :food=>score_location.xpath("child::food").text.to_f
30
+ }
31
+ puts "#{returned_scores}"
32
+ puts"#{score_location}"
33
+ puts "#{score_profile}"
data/bin/brew-finder ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #keep all this the same :)
4
+
5
+
6
+ require_relative "../lib/brew_finder"
7
+
8
+
9
+ BrewFinder::CommandLineInterface.new.welcome
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+
2
+ #!/usr/bin/env ruby
3
+
4
+ require "bundler/setup"
5
+ require "brew_finder"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,9 @@
1
+
2
+ #!/usr/bin/env bash
3
+ set -euo pipefail
4
+ IFS=$'\n\t'
5
+ set -vx
6
+
7
+ bundle install
8
+
9
+ # Do any other automated setup that you need to do here
data/blogpost.md ADDED
@@ -0,0 +1,37 @@
1
+ cli blog post
2
+
3
+ Step 1 Figure Out Topic
4
+ - browse programmable web
5
+ - notice beer as a category
6
+ - research various beer related apis -- there are a few of these, who knew???
7
+ - find one that works! -- and maybe not old, but I'll accept just working
8
+
9
+ Step 2 Figure Out Approach
10
+ - realize that student scraper functionality has everything we need
11
+ - it is so similar I'm recycling the whole thing
12
+
13
+ Step 3 Start Making Things happen
14
+ - copy entirety student scraper into cli assessment folder -- commit
15
+ - comment up all the student scraper code -- actually committed here
16
+ - copy over student scraper specs -- commit
17
+ - comment up all the student scraper specs! --commit
18
+ - change over student scraper specs to brewery fetcher specs -- commit
19
+ - create small tester file to refine api query requests -- commit
20
+ - do some testing, be wrong -- commit
21
+ - try and record some video -- get attacked by giant moth, get bothered by SO, accidentally stop recording
22
+ - while listening to myself, realize what I was doing wrong -- and that my voice sounds like I'm 10 years old
23
+ - record some more video
24
+ - pass first tests -- celebrate
25
+ - get more tests passing
26
+ - spend all day adjusting the CLI model
27
+ - get stuck on an obvious bug for 4 hours
28
+ - get final CLI logic up and running
29
+ - figure out the actual gem process...hint it's complicated maybe
30
+
31
+ Thoughts:
32
+ - a blank page is intimidating, drawing parallels between your model and an existing one is not
33
+ - reusing testing feels great too!
34
+ - start throwing spaghetti at the wall-something sticks, but don't stay here too long, you might be moving further from the solution
35
+ - when you find a stubborn bug write down what you try to fix it, that way you won't get stuck chasing your tail for hours
36
+ - sometimes at the end of it all, you picked an api that goes down right when you're ready to submit
37
+ - cry a little, hope it goes back up
@@ -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 'Brew_Finder/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "Brew_Finder"
8
+ spec.version = BrewFinder::VERSION
9
+ spec.authors = ["Kathleen DaSilva"]
10
+ spec.email = ["kayjsmith@cox.net"]
11
+ spec.summary = "Search for breweries/brewpubs using the Beer Mapping Project API"
12
+ spec.description = "Search by city/state to find local breweries/brewpubs, also view rating information for indiviual locations."
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_dependency "nokogiri"
24
+ end
data/config.rb ADDED
@@ -0,0 +1 @@
1
+ require 'nokogiri'
@@ -0,0 +1,46 @@
1
+ require 'open-uri'
2
+ require 'nokogiri'
3
+ require 'pry'
4
+
5
+ class Brewery_Fetcher
6
+
7
+ def self.query_api(api_query)
8
+ returned_request = Nokogiri::HTML(open(api_query))
9
+ puts "#{returned_request}"
10
+ breweries = []
11
+ #we gotta use something called xpath?
12
+ returned_request.xpath("//location").each do |location|
13
+ brewery = {
14
+ :id => location.xpath("child::id").text.to_i,
15
+ :name => location.xpath("child::name").text,
16
+ :street_address => location.xpath("child::street").text,
17
+ :phone => location.xpath("child::phone").text
18
+ }
19
+ #add brewery to breweries
20
+ breweries << brewery
21
+ end
22
+
23
+ return breweries
24
+ end
25
+
26
+ #change to self.fetch_score_info
27
+ def self.fetch_score_info(score_request)
28
+ returned_scores = Nokogiri::HTML(open(score_request))
29
+ #brewery score profile
30
+ score_location = returned_scores.xpath("//location")
31
+ score_profile = {
32
+ #overall_score, selection, service, atmosphere, food, review_count
33
+ :overall_score => score_location.xpath("child::overall").text.to_f.round(1),
34
+ :selection => score_location.xpath("child::selection").text.to_f.round(2),
35
+ :service => score_location.xpath("child::service").text.to_f.round(2),
36
+ :atmosphere => score_location.xpath("child::atmosphere").text.to_f.round(2),
37
+ :review_count => score_location.xpath("child::reviewcount").text.to_i,
38
+ :food=>score_location.xpath("child::food").text.to_f.round(2)
39
+ }
40
+
41
+ #return brewery score profile
42
+ return score_profile
43
+
44
+ end
45
+
46
+ end
@@ -0,0 +1,41 @@
1
+ #change to Brewery
2
+ class Brewery
3
+
4
+ #change to reflect all brewery attributes
5
+ attr_accessor :name, :street_address, :phone, :id, :overall_score, :selection, :service, :atmosphere, :review_count, :food
6
+
7
+ @@all = []
8
+
9
+ def initialize(brewery_hash)
10
+ #puts "#{brewery_hash}"
11
+ brewery_hash.each do |key, value|
12
+ #puts "#{key} #{value}"
13
+ self.send(("#{key}="), value)
14
+ #puts "#{self.phone}"
15
+
16
+ end
17
+ @@all << self
18
+ #puts "#{@@all}"
19
+ end
20
+
21
+ #change students_array to brewery_array
22
+ def self.create_from_collection(brewery_array)
23
+ #puts "#{brewery_array}"
24
+ brewery_array.each_with_index do |brewery_hash, index|
25
+ #Brewery.new
26
+ #puts "#{brewery_hash} #{index}"
27
+ Brewery.new(brewery_hash)
28
+ end
29
+ end
30
+
31
+ #change to add_brewery_info, score_hash
32
+ def add_score_info(score_hash)
33
+ score_hash.each do |key, value|
34
+ self.send(("#{key}="), value)
35
+ end
36
+ end
37
+
38
+ def self.all
39
+ @@all
40
+ end
41
+ end
@@ -0,0 +1,183 @@
1
+ require_relative "../lib/brewery_fetcher.rb"
2
+ require_relative "../lib/brewery_info.rb"
3
+ require 'nokogiri'
4
+ require 'colorize'
5
+
6
+ class CommandLineInterface
7
+ #change this to base api query
8
+ BASE_PATH = "http://beermapping.com/webservice/"
9
+ KEY = "21110efff66df69d91ec3909c0a38eed"
10
+
11
+ #define welcome
12
+ def welcome
13
+ #first welcome user
14
+ puts "\e[H\e[2J"
15
+ puts <<-DOC
16
+ o©ºº©oo©oº°©
17
+ / \
18
+ |___________|____
19
+ | |____)
20
+ | WELCOME | | |
21
+ | | | |
22
+ | TO | | |
23
+ | | | |
24
+ | B R E W | | |
25
+ | |__|_|
26
+ | FINDER! |____)
27
+ |____________|
28
+ (______________)
29
+ DOC
30
+ root_menu
31
+ end
32
+
33
+
34
+ def root_menu
35
+ puts "Type 'search' to look for breweries, or 'exit' to quit."
36
+ input = nil
37
+ while input != "exit"
38
+ input = gets.chomp
39
+ case input
40
+ when /search/
41
+ return_search
42
+ display_breweries
43
+ score_menu
44
+ when /exit/
45
+ puts "Goodbye!"
46
+ exit
47
+ else
48
+ puts "Sorry, what did you want to do?"
49
+ end
50
+ end
51
+ end
52
+
53
+ def return_search
54
+ user_location_query = get_location_query
55
+ #puts "#{user_location_query}"
56
+ formatted_query = format_location_query(user_location_query)
57
+ #puts "#{formatted_query}"
58
+ get_breweries(formatted_query)
59
+ end
60
+
61
+ def score_menu
62
+ puts "You can enter 'scores' if you would like to see how people have rated a brewery"
63
+ puts "You can also enter 'search' to start a new search, or enter 'exit' to quit."
64
+ input = nil
65
+ while input != "exit"
66
+ input = gets.chomp
67
+ case input
68
+ when /scores/
69
+ return_scores
70
+ end_menu
71
+ when /search/
72
+ return_search
73
+ scores_menu
74
+ when /exit/
75
+ puts "Goodbye!"
76
+ exit
77
+ else
78
+ puts "Sorry, what did you want to do?"
79
+ end
80
+ end
81
+ end
82
+
83
+ def end_menu
84
+ puts "Enter 'list' to show the previous search, 'search' to start a new search, or 'exit' to quit."
85
+ input = nil
86
+ while input != "exit"
87
+ input = gets.chomp
88
+ case input
89
+ when /list/
90
+ display_breweries
91
+ score_menu
92
+ when /search/
93
+ return_search
94
+ score_menu
95
+ when /exit/
96
+ puts "Goodbye!"
97
+ exit
98
+ else
99
+ puts "Sorry, what did you want to do?"
100
+ end
101
+ end
102
+ end
103
+
104
+ def return_scores
105
+ scores = get_brewery_score(formatted_score)
106
+ scored_brewery = add_scores_to_brewery(first_score_query, scores)
107
+ display_score(scored_brewery)
108
+ end
109
+
110
+ def get_location_query
111
+ puts "Please enter the initials of a state you would like to search in:"
112
+ begin
113
+ puts "A valid state abbreviation is two letters."
114
+ state = gets.chomp
115
+ end until state.match(/^(?:(A[KLRZ]|C[AOT]|D[CE]|FL|GA|HI|I[ADLN]|K[SY]|LA|M[ADEINOST]|N[CDEHJMVY]|O[HKR]|P[AR]|RI|S[CD]|T[NX]|UT|V[AIT]|W[AIVY]))$/)
116
+
117
+ puts "Now enter a city:"
118
+ begin
119
+ puts "Any city in #{state}"
120
+ city = gets.chomp.downcase
121
+ end until city.match(/^[a-zA-Z]+(?:[\s-][a-zA-Z]+)*$/)
122
+ city_state_formatted = '/' + city + ',' + state
123
+ end
124
+
125
+ def format_location_query(location)
126
+ location_query = BASE_PATH + 'loccity/' + KEY + location.downcase
127
+ location_query
128
+ end
129
+
130
+ def get_score_query
131
+ puts "Which brewery would you like to learn more about?"
132
+ begin
133
+ puts "A valid brewery id is between 4 and 6 digits:"
134
+ id = gets.chomp
135
+ end until id.match(/(\d{4,6})/)
136
+ id
137
+ end
138
+
139
+ def format_score_query(brewery_id)
140
+ score_query = BASE_PATH + 'locscore/' + KEY + '/' + brewery_id
141
+ end
142
+ #grab brewery objects from API
143
+ def get_breweries(formatted_location)
144
+ brewery_array = Brewery_Fetcher.query_api(formatted_location)
145
+ #create instances of breweries from each brewery fetched
146
+ Brewery.create_from_collection(brewery_array)
147
+ #puts "#{brewery_array}"
148
+ end
149
+
150
+ #take the requested brewery and add additional info
151
+ def get_brewery_score(formatted_score)
152
+ #take the brewery instance and give it more attributes
153
+ scores = Brewery_Fetcher.fetch_score_info(score_query)
154
+ scores
155
+ end
156
+
157
+ def add_scores_to_brewery(brewery_id, score_hash)
158
+ scored_brewery = Brewery.all.detect{|brewery| brewery.id = brewery_id}
159
+ scored_brewery.add_score_info(score_hash)
160
+ scored_brewery
161
+ end
162
+
163
+ def display_breweries
164
+ Brewery.all.each do |brewery|
165
+ puts "#{brewery.name}".colorize(:purple)
166
+ puts "#{brewery.id}".colorize(:green)
167
+ puts "#{brewery.street_address}".colorize(:blue)
168
+ puts "#{brewery.phone}".colorize(:orange)
169
+ end
170
+ end
171
+
172
+ #display additional requested brewery info
173
+ def display_score(scored_brewery)
174
+ puts "#{scored_brewery.name}".colorize(:purple)
175
+ puts "Overall score: #{scored_brewery.overall_score}".colorize(:red)
176
+ puts "Selection: #{scored_brewery.selection}"
177
+ puts "Service: #{scored_brewery.service}"
178
+ puts "Atmosphere: #{scored_brewery.atmosphere}"
179
+ puts "Number of reviews: #{scored_brewery.review_count}"
180
+ puts "Food: #{scored_brewery.food}"
181
+ end
182
+
183
+ end
@@ -0,0 +1,3 @@
1
+ module BrewFinder
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,7 @@
1
+ require 'nokogiri'
2
+ require 'open-uri'
3
+
4
+ require_relative './Brew_Finder/brewery_fetcher'
5
+ require_relative './Brew_Finder/brewery_info'
6
+ require_relative './Brew_Finder/command_line_interface'
7
+ require_relative './Brew_Finder/version'
data/spec.md ADDED
@@ -0,0 +1,7 @@
1
+ # Specifications for the CLI Assessment
2
+
3
+ Specs:
4
+ - [x] Have a CLI for interfacing with the application
5
+ - [ ] Pull data from an external source
6
+ - [ ] Implement both list and detail views
7
+
@@ -0,0 +1,66 @@
1
+ require_relative "spec_helper"
2
+
3
+ #change to Brewery_Fetcher
4
+ describe "Brewery_Fetcher" do
5
+
6
+ #make example brewery request array
7
+ let!(:brewery_query_array) {[{:id=>6580, :name=>"Spiritus Fermenti", :street_address=>"220 Meeting Street", :phone=>"(401) 273-1999"},
8
+ {:id=>1341, :name=>"Trinity Brewhouse", :street_address=>"186 Fountain Street", :phone=>"(401) 453-2337"},
9
+ {:id=>15566, :name=>"Narragansett Brewing Company", :street_address =>"60 Ship Street", :phone=>"(401) 437-8970"}]}
10
+
11
+ #make example brewery score hash
12
+ let!(:brewery_trinity_score) {
13
+ {
14
+ :overall_score=>82.9,
15
+ :selection=>4.31,
16
+ :service=>4.00,
17
+ :atmosphere=>4.13,
18
+ :review_count=>4,
19
+ :food=>3.94
20
+ }
21
+ }
22
+
23
+ #make example brewery without score hash?
24
+ let!(:gansett_score) {
25
+ {
26
+ :overall_score=>0.0,
27
+ :selection=>0.0,
28
+ :service=>0.0,
29
+ :atmosphere=>0.0,
30
+ :review_count=>0,
31
+ :food=>0.0
32
+ }
33
+ }
34
+
35
+ #describe #query_api
36
+ describe "#query_api" do
37
+ it "is a class method that sends a location query to the beer mapping API and a returns an array of hashes in which each hash represents one brewery" do
38
+ example_location_query = "http://beermapping.com/webservice/loccity/21110efff66df69d91ec3909c0a38eed/providence,ri"
39
+ fetched_breweries = Brewery_Fetcher.query_api(example_location_query)
40
+ expect(fetched_breweries).to be_a(Array)
41
+ expect(fetched_breweries.first).to have_key(:street_address)
42
+ expect(fetched_breweries.first).to have_key(:name)
43
+ expect(fetched_breweries).to include(brewery_query_array[0], brewery_query_array[1], brewery_query_array[2])
44
+ end
45
+ end
46
+
47
+ #describe #fetch_score_info
48
+ describe "#fetch_score_info" do
49
+ it "is a class method that scrapes sends a score query to the beer mapping API and returns a hash of rating scores given to an individual brewery" do
50
+ #FIND OUT ID FOR TRINITY
51
+ example_score_query = "http://beermapping.com/webservice/locscore/21110efff66df69d91ec3909c0a38eed/1341"
52
+ fetched_score = Brewery_Fetcher.fetch_score_info(example_score_query)
53
+ expect(fetched_score).to be_a(Hash)
54
+ expect(fetched_score).to match(brewery_trinity_score)
55
+ end
56
+ #it can handle a brewery with no score info?
57
+ it "can handle breweries with no scoring data" do
58
+ #FIND OUT ID FOR
59
+ no_score_example = "http://beermapping.com/webservice/locscore/21110efff66df69d91ec3909c0a38eed/15566"
60
+ no_score_brewery = Brewery_Fetcher.fetch_score_info(no_score_example)
61
+ #????maybe not a hash?
62
+ expect(no_score_brewery).to be_a(Hash)
63
+ expect(no_score_brewery).to match(gansett_score)
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,68 @@
1
+ require "spec_helper"
2
+
3
+ #describe Brewery
4
+ describe "Brewery" do
5
+ #make example brewery hash
6
+ let!(:example_brewery_array) {[{:name=>"Coastal Extreme Brewing Co.", :street_address=>"307 Oliphant Lane"},
7
+ {:name=>"Coddington Brewing Co.", :street_address=>"210 Coddington Highway"},
8
+ {:name=>"Sandy's Liquors", :street_address=>"717 Aquidneck Avenue"},
9
+ ]}
10
+
11
+ #make example score hash
12
+ let!(:example_score_hash) {
13
+ {
14
+ :overall_score=>82.9,
15
+ :selection=>4.31,
16
+ :service=>4.00,
17
+ :atmosphere=>4.13,
18
+ :review_count=>4,
19
+ :food=>3.94
20
+ }
21
+ }
22
+
23
+ #create example brewery
24
+ let!(:brewery) {Brewery.new({:name=>"Coastal Extreme Brewing Co.", :street_address=>"301 Oliphant Lane"})}
25
+
26
+ after(:each) do
27
+ Brewery.class_variable_set(:@@all, [])
28
+ end
29
+ describe "#new" do
30
+ it "takes in an argument of a hash and sets that new brewery's attributes using the key/value pairs of that hash." do
31
+ expect{Brewery.new({:name => "Coddington Brewing Co.", :street_address => "210 Coddington Highway"})}.to_not raise_error
32
+ expect(brewery.name).to eq("Coastal Extreme Brewing Co.")
33
+ expect(brewery.street_address).to eq("301 Oliphant Lane")
34
+ end
35
+
36
+ it "adds that new brewery to the Brewery class' collection of all existing breweries, stored in the `@@all` class variable." do
37
+ expect(Brewery.class_variable_get(:@@all).first.name).to eq("Coastal Extreme Brewing Co.")
38
+ end
39
+ end
40
+
41
+ describe ".create_from_collection" do
42
+ it "uses the Brewery_Fetcher class to create new breweries with the correct name and location." do
43
+ Brewery.class_variable_set(:@@all, [])
44
+ Brewery.create_from_collection(example_brewery_array)
45
+ expect(Brewery.class_variable_get(:@@all).first.name).to eq("Coastal Extreme Brewing Co.")
46
+ end
47
+ end
48
+ #describe add_brewery_info
49
+ describe "#add_score_info" do
50
+ it "uses the Brewery_Fetcher class to get a hash of a given brewery's attributes and uses that hash to set additional attributes for that brweery." do
51
+ brewery.add_score_info(example_score_hash)
52
+ expect(brewery.overall_score).to eq(82.9)
53
+ expect(brewery.selection).to eq(4.31)
54
+ expect(brewery.service).to eq(4.00)
55
+ expect(brewery.atmosphere).to eq(4.13)
56
+ expect(brewery.review_count).to eq(4)
57
+ expect(brewery.food).to eq(3.94)
58
+ end
59
+ end
60
+
61
+ #this can stay mostly the same, change Student to Brewery
62
+ describe '.all' do
63
+ it 'returns the class variable @@all' do
64
+ Brewery.class_variable_set(:@@all, [])
65
+ expect(Brewery.all).to match_array([])
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,82 @@
1
+ require_relative "../lib/brewery_fetcher.rb"
2
+ require_relative "../lib/brewery_info.rb"
3
+ require_relative "../config.rb"
4
+ RSpec.configure do |config|
5
+ # rspec-expectations config goes here. You can use an alternate
6
+
7
+ # assertion/expectation library such as wrong or the stdlib/minitest
8
+ # assertions if you prefer.
9
+ config.expect_with :rspec do |expectations|
10
+ # This option will default to `true` in RSpec 4. It makes the `description`
11
+ # and `failure_message` of custom matchers include text for helper methods
12
+ # defined using `chain`, e.g.:
13
+ # be_bigger_than(2).and_smaller_than(4).description
14
+ # # => "be bigger than 2 and smaller than 4"
15
+ # ...rather than:
16
+ # # => "be bigger than 2"
17
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
18
+ end
19
+
20
+ # rspec-mocks config goes here. You can use an alternate test double
21
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
22
+ config.mock_with :rspec do |mocks|
23
+ # Prevents you from mocking or stubbing a method that does not exist on
24
+ # a real object. This is generally recommended, and will default to
25
+ # `true` in RSpec 4.
26
+ mocks.verify_partial_doubles = true
27
+ end
28
+
29
+ # The settings below are suggested to provide a good initial experience
30
+ # with RSpec, but feel free to customize to your heart's content.
31
+ =begin
32
+ # These two settings work together to allow you to limit a spec run
33
+ # to individual examples or groups you care about by tagging them with
34
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
35
+ # get run.
36
+ config.filter_run :focus
37
+ config.run_all_when_everything_filtered = true
38
+
39
+ # Allows RSpec to persist some state between runs in order to support
40
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
41
+ # you configure your source control system to ignore this file.
42
+ config.example_status_persistence_file_path = "spec/examples.txt"
43
+
44
+ # Limits the available syntax to the non-monkey patched syntax that is
45
+ # recommended. For more details, see:
46
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
47
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
48
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
49
+ config.disable_monkey_patching!
50
+
51
+ # This setting enables warnings. It's recommended, but in some cases may
52
+ # be too noisy due to issues in dependencies.
53
+ config.warnings = true
54
+
55
+ # Many RSpec users commonly either run the entire suite or an individual
56
+ # file, and it's useful to allow more verbose output when running an
57
+ # individual spec file.
58
+ if config.files_to_run.one?
59
+ # Use the documentation formatter for detailed output,
60
+ # unless a formatter has already been configured
61
+ # (e.g. via a command-line flag).
62
+ config.default_formatter = 'doc'
63
+ end
64
+
65
+ # Print the 10 slowest examples and example groups at the
66
+ # end of the spec run, to help surface which specs are running
67
+ # particularly slow.
68
+ config.profile_examples = 10
69
+
70
+ # Run specs in random order to surface order dependencies. If you find an
71
+ # order dependency and want to debug it, you can fix the order by providing
72
+ # the seed, which is printed after each run.
73
+ # --seed 1234
74
+ config.order = :random
75
+
76
+ # Seed global randomization in this process using the `--seed` CLI option.
77
+ # Setting this allows you to use `--seed` to deterministically reproduce
78
+ # test failures related to randomization by passing the same `--seed` value
79
+ # as the one that triggered the failure.
80
+ Kernel.srand config.seed
81
+ =end
82
+ end
data/tinycli.rb ADDED
@@ -0,0 +1,114 @@
1
+ require_relative "lib/brewery_fetcher.rb"
2
+ require_relative "lib/brewery_info.rb"
3
+ require 'nokogiri'
4
+ require 'colorize'
5
+
6
+ class CommandLineInterface
7
+ #change this to base api query
8
+ BASE_PATH = "http://beermapping.com/webservice/"
9
+ KEY = "21110efff66df69d91ec3909c0a38eed"
10
+
11
+ def get_location_query
12
+ puts "Please enter the initials of a state you would like to search in:"
13
+ begin
14
+ puts "A valid state abbreviation is two letters."
15
+ state = gets.chomp
16
+ end until state.match(/^(?:(A[KLRZ]|C[AOT]|D[CE]|FL|GA|HI|I[ADLN]|K[SY]|LA|M[ADEINOST]|N[CDEHJMVY]|O[HKR]|P[AR]|RI|S[CD]|T[NX]|UT|V[AIT]|W[AIVY]))$/)
17
+ #hey we can match states why not
18
+ puts "Now enter a city:"
19
+ begin
20
+ puts "any city in #{state}"
21
+ city = gets.chomp.downcase
22
+ end until city.match(/^[a-zA-Z]+(?:[\s-][a-zA-Z]+)*$/)
23
+
24
+ city_state_formatted = '/' + city + ',' + state.downcase
25
+ #puts "#{city_state_formatted}"
26
+ end
27
+ #what do we want to happen?
28
+ def run
29
+ #first welcome user
30
+ puts "\e[H\e[2J"
31
+ puts <<-DOC
32
+ o©ºº©oo©oº°º©o
33
+ | ___________|____
34
+ | |____)
35
+ | WELCOME | | |
36
+ | | | |
37
+ | TO | | |
38
+ | | | |
39
+ | B R E W | | |
40
+ | |__|_|
41
+ | FINDER! |____)
42
+ |____________|
43
+ (______________)
44
+ DOC
45
+ #first ask user for location query
46
+ #get_location_query
47
+ first_location_query = get_location_query
48
+ formatted_query = format_location_query(first_location_query)
49
+ #use results from get_query to get matching breweries
50
+ #change to get_breweries
51
+ get_breweries(formatted_query)
52
+ #display_matching_breweries
53
+ display_breweries
54
+ first_score_query = get_score_query
55
+ formatted_score = format_score_query(first_score_query)
56
+ scores = get_brewery_score(formatted_query)
57
+ bullshit
58
+ end
59
+
60
+ def format_location_query(location)
61
+ location_query = BASE_PATH + 'loccity/' + KEY + location
62
+ #puts "#{location_query}"
63
+ end
64
+
65
+ #grab brewery objects from API
66
+ def get_breweries(location_query)
67
+ brewery_array = Brewery_Fetcher.query_api(location_query)
68
+ #puts "#{brewery_array}"
69
+ #create instances of breweries from each brewery fetched
70
+ Brewery.create_from_collection(brewery_array)
71
+ end
72
+
73
+ def display_breweries
74
+ #puts "#{Brewery.all}"
75
+ Brewery.all.each do |brewery|
76
+ puts "#{brewery.name}".colorize(:magenta)
77
+ puts "Brewery ID no.#{brewery.id}"
78
+ puts "#{brewery.street_address}".colorize(:blue)
79
+ puts "#{brewery.phone}".colorize(:yellow)
80
+ end
81
+ end
82
+
83
+
84
+ def get_score_query
85
+ puts "Which brewery would you like to learn more about?"
86
+ begin
87
+ puts "A valid brewery id is between 4 and 6 digits:"
88
+ id = gets.chomp
89
+ end until id.match(/(\d{4,6})/)
90
+ id
91
+ end
92
+ def format_location_query(location)
93
+ location_query = BASE_PATH + 'loccity/' + KEY + location
94
+ location_query
95
+ end
96
+
97
+ def format_score_query(brewery_id)
98
+ score_query = BASE_PATH + 'locscore/' + KEY + '/' + brewery_id
99
+ score_query
100
+ end
101
+
102
+ def get_brewery_score(score_query)
103
+ #take the brewery instance and give it more attributes
104
+ scores = Brewery_Fetcher.fetch_score_info(score_query)
105
+ scores
106
+ end
107
+
108
+ def bullshit
109
+ puts "this is some bullshit"
110
+ end
111
+
112
+ end
113
+
114
+ CommandLineInterface.new.run
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: Brew_Finder
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kathleen DaSilva
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-08-11 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.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: nokogiri
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Search by city/state to find local breweries/brewpubs, also view rating
56
+ information for indiviual locations.
57
+ email:
58
+ - kayjsmith@cox.net
59
+ executables:
60
+ - brew-finder
61
+ - console
62
+ - setup
63
+ extensions: []
64
+ extra_rdoc_files: []
65
+ files:
66
+ - ".gitignore"
67
+ - ".gitmodules"
68
+ - ".learn"
69
+ - CONTRIBUTING.md
70
+ - Gemfile
71
+ - Gemfile.lock
72
+ - LICENSE.md
73
+ - README.md
74
+ - api_query_tester.rb
75
+ - bin/brew-finder
76
+ - bin/console
77
+ - bin/setup
78
+ - blogpost.md
79
+ - brew_finder.gemspec
80
+ - config.rb
81
+ - lib/Brew_Finder/brewery_fetcher.rb
82
+ - lib/Brew_Finder/brewery_info.rb
83
+ - lib/Brew_Finder/command_line_interface.rb
84
+ - lib/Brew_Finder/version.rb
85
+ - lib/brew_finder.rb
86
+ - spec.md
87
+ - spec/brewery_fetcher_spec.rb
88
+ - spec/brewery_spec.rb
89
+ - spec/spec_helper.rb
90
+ - tinycli.rb
91
+ homepage: ''
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.6.6
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Search for breweries/brewpubs using the Beer Mapping Project API
115
+ test_files:
116
+ - spec/brewery_fetcher_spec.rb
117
+ - spec/brewery_spec.rb
118
+ - spec/spec_helper.rb