on_tap_ibc 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6efc2aef34bdccbb61c0d8c37eadd6e4021c99562a5f21168e0c9f36e8b69350
4
+ data.tar.gz: b2aa58aeb86e9ed004006668bd601e3a72d748cdf2efc768e59bc7cec7784e45
5
+ SHA512:
6
+ metadata.gz: a2d791710ab5edf361b5c22d42ebfae2e28a614b85de133e1b78fc193c3639d0c040e55592df5455c2af9b8cb3c399a8407a30e049f79a86a7edcc6e16100dee
7
+ data.tar.gz: f30257853a8329c95b403130e00c572ce6773a8480bf059878ce2deacc120c27a504baaf172e8f6aacf5210ba6bd197308ba879e9f3c3213380a223f74ba3535
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
@@ -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 'laura@polyporedesign.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
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{lauradarlak/on_tap_ibc}" }
4
+
5
+ # Specify your gem's dependencies in on_tap_ibc.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,30 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ on_tap_ibc (0.1.0)
5
+ nokogiri
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ coderay (1.1.2)
11
+ method_source (0.9.0)
12
+ mini_portile2 (2.3.0)
13
+ nokogiri (1.8.4)
14
+ mini_portile2 (~> 2.3.0)
15
+ pry (0.11.3)
16
+ coderay (~> 1.1.0)
17
+ method_source (~> 0.9.0)
18
+ rake (10.4.2)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ bundler (~> 1.16)
25
+ on_tap_ibc!
26
+ pry
27
+ rake (~> 10.0)
28
+
29
+ BUNDLED WITH
30
+ 1.16.5
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 'Laura Darlak'
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,37 @@
1
+ # OnTapIbc
2
+
3
+ This gem provides a CLI to view beers currently on tap at Ithaca Beer Company. Users can select a taps to read a description of each beer and, when available, an ingredient list.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'on_tap_ibc'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install on_tap_ibc
20
+
21
+ ## Usage
22
+
23
+ Run: ```./bin/on_tap``` after installing the gem.
24
+
25
+ ## Development
26
+
27
+ 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.
28
+
29
+ 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).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/'lauradarlak'/on_tap_ibc. 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.
34
+
35
+ ## License
36
+
37
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "on_tap_ibc"
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/on_tap ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require 'on_tap_ibc'
5
+
6
+
7
+ OnTapIbc::CLI.new.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/on_tap_ibc.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'open-uri'
2
+ require 'nokogiri'
3
+ require 'pry'
4
+
5
+ require 'on_tap_ibc/version'
6
+ require 'on_tap_ibc/cli'
7
+ require 'on_tap_ibc/scraper'
8
+ require 'on_tap_ibc/beer'
@@ -0,0 +1,32 @@
1
+ class OnTapIbc::Beer
2
+ attr_accessor :name, :abv, :short_desc, :style, :long_desc, :addl1
3
+
4
+ @@all = []
5
+
6
+ def initialize(beer_hash)
7
+ beer_hash.each {|key, value| self.send(("#{key}="), value)}
8
+ @@all << self
9
+ end
10
+
11
+ def self.create_from_menu(current_beers)
12
+ current_beers.each {|beer| self.new(beer)}
13
+ end
14
+
15
+ def self.assign_beer(selected_tap)
16
+ @beer_detail_hash = OnTapIbc::Scraper.beer_details.find{|k, v| k == selected_tap.name.upcase }
17
+ if @beer_detail_hash != nil
18
+ @beer_detail_hash[1].each do |attribute, data|
19
+ selected_tap.send(("#{attribute}="), data)
20
+ end
21
+ end
22
+ end
23
+
24
+ def addl1=(addl1)
25
+ @addl1 = addl1.split(/(?<=[a-z])(?=[A-Z])/)
26
+ end
27
+
28
+ def self.all
29
+ @@all
30
+ end
31
+
32
+ end
@@ -0,0 +1,102 @@
1
+ class OnTapIbc::CLI
2
+
3
+ @@five = []
4
+ @@nofive = []
5
+
6
+ def start
7
+ welcome
8
+ make_beers
9
+ sort_beers
10
+ list_beers
11
+ goodbye
12
+ end
13
+
14
+ def welcome
15
+ puts "-----------------------------------------"
16
+ puts "What's on tap at Ithaca Beer Company"
17
+ puts "#{OnTapIbc::Scraper.updated_last}"
18
+ puts "-----------------------------------------"
19
+ end
20
+
21
+ def make_beers
22
+ current_beers = OnTapIbc::Scraper.scrape_menu
23
+ OnTapIbc::Beer.create_from_menu(current_beers)
24
+ end
25
+
26
+ def sort_beers
27
+ OnTapIbc::Beer.all.each do |beer|
28
+ beer.short_desc.include?("5BBL") ? @@five << beer : @@nofive << beer
29
+ end
30
+ end
31
+
32
+ def list_beers
33
+ puts "\#. BEER - ABV %"
34
+ puts "-----------------------------------------"
35
+ puts "Flagship and Seasonal Beers"
36
+ @@nofive.map.with_index(1) do |beer, index|
37
+ puts "#{index}. #{beer.name} - #{beer.abv}"
38
+ end
39
+ puts "-----------------------------------------"
40
+ puts "5 Barrel Brews"
41
+ @@five.map.with_index(@@nofive.length + 1) do |beer, index|
42
+ puts "#{index}. #{beer.name} - #{beer.abv}"
43
+ end
44
+ puts "-----------------------------------------"
45
+ puts "Select a tap number to learn more about the beer."
46
+ sorted_tap_arr = (@@nofive + @@five).flatten
47
+ select_tap(sorted_tap_arr)
48
+ end
49
+
50
+ def select_tap(sorted_tap_arr)
51
+ input = nil
52
+ while input != "exit"
53
+ input = gets.strip.downcase
54
+
55
+ if input.to_i > 0 && input.to_i <= sorted_tap_arr.length
56
+ selected_tap = sorted_tap_arr[input.to_i-1]
57
+ OnTapIbc::Beer.assign_beer(selected_tap)
58
+ display_profile(selected_tap)
59
+ else
60
+ puts "Invalid tap number. Please try again."
61
+ end
62
+ end
63
+ end
64
+
65
+ def display_profile(selected_tap)
66
+ puts "-----------------------------------------"
67
+ puts "#{selected_tap.name.upcase}"
68
+ puts "-----------------------------------------"
69
+ if selected_tap.long_desc == nil
70
+ puts wrap("DESCRIPTION #{selected_tap.short_desc}")
71
+ puts "ABV #{selected_tap.abv}"
72
+ puts "HOPS N/A"
73
+ puts "DRY HOPS N/A"
74
+ puts "MALTS N/A"
75
+ else
76
+ puts "STYLE #{selected_tap.style}"
77
+ puts wrap("DESCRIPTION #{selected_tap.long_desc}")
78
+ selected_tap.addl1.each {|i| puts "#{i}"}
79
+ end
80
+ new_selection
81
+ end
82
+
83
+ def new_selection
84
+ puts "-----------------------------------------"
85
+ puts "Type list to select another beer or exit."
86
+ input = nil
87
+ input = gets.strip.downcase
88
+ if input == "list"
89
+ list_beers
90
+ elsif input == "exit"
91
+ puts "Cheers!"
92
+ exit
93
+ else
94
+ puts "Please try again."
95
+ end
96
+ end
97
+
98
+ def wrap(s, width=100)
99
+ s.gsub(/(.{1,#{width}})(\s+|\Z)/, "\\1\n")
100
+ end
101
+
102
+ end
@@ -0,0 +1,48 @@
1
+ require 'nokogiri'
2
+ require 'open-uri'
3
+
4
+ class OnTapIbc::Scraper
5
+
6
+ def self.updated_last
7
+ doc = Nokogiri::HTML(open("https://www.ithacabeer.com/taproom-menu/#anchor-tap-list"))
8
+ updated_last = doc.search("div#block-yui_3_17_2_8_1508769314339_15193 div.menu-section-title").text.strip
9
+ updated_last
10
+ end
11
+
12
+ def self.scrape_menu
13
+ beers = Nokogiri::HTML(open("https://www.ithacabeer.com/taproom-menu/#anchor-tap-list"))
14
+ current_beers = []
15
+ # Iterate through beer menu
16
+ beers.css("div#block-yui_3_17_2_8_1508769314339_15193 div.menu-items div.menu-item").each do |beer|
17
+
18
+ current_beers << {
19
+ :name => beer.css("div.menu-item-title").text.strip,
20
+ :abv => beer.css("span.menu-item-price-top").text.strip,
21
+ :short_desc => beer.css("div.menu-item-description").text.strip
22
+ }
23
+ end
24
+ current_beers
25
+ end
26
+
27
+ def self.beer_details
28
+ self.scrape_core_beliefs
29
+ end
30
+
31
+ def self.scrape_core_beliefs
32
+ beer_hashes = {}
33
+ ["https://www.ithacabeer.com/ithaca-beer-core-beliefs","https://www.ithacabeer.com/ithaca-beer-random-acts"].each do |url|
34
+
35
+ beers = Nokogiri::HTML(open(url))
36
+
37
+ beers.css("div.col.sqs-col-10.span-10").each do |beer|
38
+ beer_hashes["#{beer.css("div p.beerDetails").text.strip.upcase}"] = {
39
+ style: beer.css("div p.beerDetails2").text.strip,
40
+ long_desc: beer.css("div.html-block p")[0].text.strip,
41
+ addl1: beer.css("div.html-block p").last.text.strip
42
+ }
43
+ end
44
+ end
45
+ beer_hashes
46
+ end
47
+
48
+ end
@@ -0,0 +1,4 @@
1
+
2
+ module OnTapIbc
3
+ VERSION = "0.1.0"
4
+ end
@@ -0,0 +1,39 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "on_tap_ibc/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "on_tap_ibc"
8
+ spec.version = OnTapIbc::VERSION
9
+ spec.authors = ["Laura Darlak"]
10
+ spec.email = ["laura@polyporedesign.com"]
11
+
12
+ spec.summary = %q{Find out what is on tap at Ithaca Beer Company}
13
+ spec.homepage = "https://github.com/lauradarlak/on_tap_ibc"
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"] = "TODO: 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
+ # Specify which files should be added to the gem when it is released.
26
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
27
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
28
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
29
+ end
30
+ spec.bindir = "exe"
31
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ["lib"]
33
+
34
+ spec.add_development_dependency "bundler", "~> 1.16"
35
+ spec.add_development_dependency "rake", "~> 10.0"
36
+ spec.add_development_dependency "pry"
37
+
38
+ spec.add_dependency "nokogiri"
39
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: on_tap_ibc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Laura Darlak
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-09-26 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
+ description:
70
+ email:
71
+ - laura@polyporedesign.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - CODE_OF_CONDUCT.md
78
+ - Gemfile
79
+ - Gemfile.lock
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/on_tap
85
+ - bin/setup
86
+ - lib/on_tap_ibc.rb
87
+ - lib/on_tap_ibc/beer.rb
88
+ - lib/on_tap_ibc/cli.rb
89
+ - lib/on_tap_ibc/scraper.rb
90
+ - lib/on_tap_ibc/version.rb
91
+ - on_tap_ibc.gemspec
92
+ homepage: https://github.com/lauradarlak/on_tap_ibc
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.7.7
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Find out what is on tap at Ithaca Beer Company
116
+ test_files: []