museum_day 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
+ SHA256:
3
+ metadata.gz: a4f45192c7623ffdcdcf038c8c1a69a47f2592a109775ec22006a586df0a8053
4
+ data.tar.gz: 35512b5eef61eeccae4315a03cd1f24d1fbfae288a818dd86bc0467a790edf74
5
+ SHA512:
6
+ metadata.gz: 3d482533ae62a9c95433a04805cd1d4d6585e42dae552030501df2303d9af34eb15fb5e65b578b027973edf03137517df182ee54c4dc972e33af397528f52edc
7
+ data.tar.gz: aed7a835341eed02ddbdf30aa3fbbeccbe3146ec5cda9af15c241b31f6eea6d839ca64be44acbb9f1651b7e9875ef0cbbd54b728ec3182e245848e371c81a7aa
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,27 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people
4
+ who contribute through reporting issues, posting feature requests,
5
+ updating documentation, submitting pull requests or patches, and other activities.
6
+
7
+ We are committed to making participation in this project a harassment-free
8
+ experience for everyone, regardless of level of experience, gender, gender
9
+ identity and expression, sexual orientation, disability, personal appearance,
10
+ body size, race, ethnicity, age, or religion.
11
+
12
+ Examples of unacceptable behavior by participants include the use of sexual
13
+ language or imagery, derogatory comments or personal attacks, trolling, public
14
+ or private harassment, insults, or other unprofessional conduct.
15
+
16
+ Project maintainers have the right and responsibility to remove, edit, or reject
17
+ comments, commits, code, wiki edits, issues, and other contributions that are not
18
+ aligned to this Code of Conduct. Project maintainers who do not follow the Code
19
+ of Conduct may be removed from the project team.
20
+
21
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
22
+ reported by opening an issue or contacting one or more of the project maintainers.
23
+
24
+ This Code of Conduct is adapted from the
25
+ [Contributor Covenant](http://contributor-covenant.org), version 1.0.0,
26
+ available at [http://contributor-covenant.org/version/1/0/0/]
27
+ (http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in museum_day.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,30 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ museum_day (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.2)
12
+ mini_portile2 (2.4.0)
13
+ nokogiri (1.10.4)
14
+ mini_portile2 (~> 2.4.0)
15
+ pry (0.12.2)
16
+ coderay (~> 1.1.0)
17
+ method_source (~> 0.9.0)
18
+ rake (10.5.0)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ bundler (~> 2.0)
25
+ museum_day!
26
+ pry
27
+ rake (~> 10.0)
28
+
29
+ BUNDLED WITH
30
+ 2.0.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Darrel Castellano
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,41 @@
1
+ # MuseumDay
2
+
3
+ This Ruby Gem provides a CLI to view the participating Museums for Museum Day ticket holders based on your zipcode
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'museum_day'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install museum_day
20
+
21
+ ## Usage
22
+
23
+ Type the below and follow the on screen prompts.
24
+
25
+ $ museum_day
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/DarrelJames/museum_day.
36
+
37
+ 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.
38
+
39
+ ## License
40
+
41
+ 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 "museum_day"
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/museum_day ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "museum_day"
5
+
6
+ MuseumDay::CLI.new.call
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
@@ -0,0 +1,120 @@
1
+ class MuseumDay::CLI
2
+ attr_accessor :zipcode
3
+
4
+ def call
5
+ puts "--------------Welcome to Museum Day--------------"
6
+ start
7
+ end
8
+
9
+
10
+ def start
11
+ if !zipcode
12
+ get_zipcode
13
+ end
14
+
15
+ exit?(zipcode)
16
+ list_museums(zipcode)
17
+
18
+ input = 0
19
+
20
+ while !input.to_i.between?(1, MuseumDay::Museum.all.size)
21
+ puts ""
22
+ puts "Enter the number of the museum you'd like more info on or type exit"
23
+ input = gets.strip
24
+
25
+ exit?(input)
26
+ if input.to_i.between?(1, MuseumDay::Museum.all.size)
27
+ print_museum_details(input)
28
+ else
29
+ puts "Invalid number"
30
+
31
+ end
32
+ end
33
+
34
+ menu
35
+
36
+ input = gets.strip.downcase
37
+ exit?(input)
38
+
39
+ if input == "new"
40
+ MuseumDay::Museum.clear_all
41
+ @zipcode = nil
42
+ start
43
+ elsif input == "back"
44
+ MuseumDay::Museum.clear_all
45
+ start
46
+ end
47
+ end
48
+
49
+ def list_museums(input)
50
+
51
+ MuseumDay::Scraper.new(input).make_museums
52
+
53
+ puts ""
54
+ puts "--------------Listing museums near #{zipcode}--------------"
55
+
56
+ MuseumDay::Museum.all.each.with_index(1) do |museum, idx|
57
+ puts "#{idx}. #{museum.name} - #{museum.city}"
58
+ end
59
+ end
60
+
61
+ def print_museum_details(input)
62
+
63
+ museum = MuseumDay::Museum.find(input.to_i)
64
+
65
+ puts ""
66
+ puts "--------------#{museum.name}--------------"
67
+ puts "#{museum.address}"
68
+ puts " Hours: #{museum.hours}"
69
+ puts ""
70
+ puts "Phone Number: #{museum.phone_number}"
71
+ puts "Website: #{museum.website_url}"
72
+
73
+ museum.social_urls
74
+ if museum.fb
75
+ puts "Facebook: #{museum.fb}"
76
+ end
77
+
78
+ if museum.twitter
79
+ puts "Twitter: #{museum.twitter}"
80
+ end
81
+
82
+ puts ""
83
+ puts "--------------Description--------------"
84
+ puts "#{museum.description}"
85
+ end
86
+
87
+ def menu
88
+ puts ""
89
+ puts "To go back to list of museum, enter 'back'."
90
+ puts "To search a new zipcode, enter 'new'."
91
+ puts "To quit, enter 'exit'."
92
+ end
93
+
94
+ def get_zipcode
95
+ puts ""
96
+ puts "Please enter your zipcode or type exit"
97
+
98
+ @zipcode = gets.strip
99
+ exit?(zipcode)
100
+
101
+ if zipcode.size != 5
102
+ puts ""
103
+ puts "Invalid Zipcode"
104
+ get_zipcode
105
+ end
106
+ end
107
+
108
+ def exit?(input)
109
+ if input.downcase == "exit"
110
+ goodbye
111
+ end
112
+ end
113
+
114
+ def goodbye
115
+ puts "-----------------"
116
+ puts "| Goodbye |"
117
+ puts "-----------------"
118
+ exit
119
+ end
120
+ end
@@ -0,0 +1,68 @@
1
+ class MuseumDay::Museum
2
+
3
+ attr_accessor :name, :city, :url, :address, :phone_number, :website_url, :twitter, :fb,
4
+ :description, :hours, :doc
5
+
6
+ @@all = []
7
+
8
+ def self.new_from_index(museum)
9
+ self.new(
10
+ museum.css("h4.name").text,
11
+ museum.css("h5.location").text,
12
+ museum.css("a").attribute("href").value,
13
+ museum.at("div strong").next_sibling.text.strip
14
+ )
15
+ end
16
+
17
+ def initialize(name = nil, city = nil, url = nil, hours = nil)
18
+ @name = name
19
+ @city = city
20
+ @url = url
21
+ @hours = hours
22
+ @@all << self
23
+ end
24
+
25
+ def self.all
26
+ @@all
27
+ end
28
+
29
+ def self.find(id)
30
+ self.all[id-1]
31
+ end
32
+
33
+ def address
34
+ @address ||= doc.css("p.address").text.strip
35
+ end
36
+
37
+ def phone_number
38
+ @phone_number ||= doc.at("i.fa-phone").next_sibling.text.strip
39
+ end
40
+
41
+ def website_url
42
+ @website_url ||= doc.css("i.fa-external-link + a").attribute("href").value
43
+ end
44
+
45
+ def social_urls
46
+ social_links = doc.css("div.contact a").collect { |link| link.attribute("href").value }
47
+
48
+ social_links.each do |link|
49
+ if link.include?("twitter")
50
+ self.twitter = link
51
+ elsif link.include?("facebook")
52
+ self.fb = link
53
+ end
54
+ end
55
+ end
56
+
57
+ def description
58
+ @description ||= doc.css("div.aux-info p").first.text
59
+ end
60
+
61
+ def doc
62
+ @doc ||= Nokogiri::HTML(open("https://www.smithsonianmag.com#{self.url}"))
63
+ end
64
+
65
+ def self.clear_all
66
+ @@all.clear
67
+ end
68
+ end
@@ -0,0 +1,23 @@
1
+ class MuseumDay::Scraper
2
+
3
+ attr_accessor :zipcode
4
+
5
+ def initialize(zipcode)
6
+ @zipcode = zipcode
7
+ end
8
+
9
+ def get_museums_page
10
+ Nokogiri::HTML(open("https://www.smithsonianmag.com/museumday/search/?q=&around_zip=#{zipcode}"))
11
+ end
12
+
13
+ def scrape_museums_index
14
+ self.get_museums_page.css("div.museum div.museum-text")
15
+ end
16
+
17
+ def make_museums
18
+ scrape_museums_index.each do |museum|
19
+ MuseumDay::Museum.new_from_index(museum)
20
+ end
21
+ end
22
+
23
+ end
@@ -0,0 +1,3 @@
1
+ module MuseumDay
2
+ VERSION = "0.1.0"
3
+ end
data/lib/museum_day.rb ADDED
@@ -0,0 +1,8 @@
1
+ require "open-uri"
2
+ require "nokogiri"
3
+
4
+
5
+ require_relative "./museum_day/version"
6
+ require_relative "./museum_day/cli"
7
+ require_relative "./museum_day/scraper"
8
+ require_relative "./museum_day/museum"
@@ -0,0 +1,37 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "museum_day/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "museum_day"
7
+ spec.version = MuseumDay::VERSION
8
+ spec.authors = ["Darrel Castellano"]
9
+ spec.email = ["dcastellano2007@gmail.com"]
10
+
11
+ spec.summary = "Museums in your area"
12
+ spec.description = "View participating Museum Day ticket holders in your area. View details about the museum"
13
+ spec.homepage = "https://github.com/DarrelJames/museum_day"
14
+ spec.license = "MIT"
15
+
16
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
17
+ #
18
+ # spec.metadata["homepage_uri"] = spec.homepage
19
+ # spec.metadata["source_code_uri"] = "https://github.com/DarrelJames/museum_day"
20
+ # spec.metadata["changelog_uri"] = "https://github.com/DarrelJames/museum_day/blob/master/CHANGELOG.md"
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ end
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_development_dependency "bundler", "~> 2.0"
32
+ spec.add_development_dependency "rake", "~> 10.0"
33
+ spec.add_development_dependency "pry"
34
+
35
+ spec.add_dependency "nokogiri"
36
+
37
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: museum_day
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Darrel Castellano
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-09-30 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: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
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: View participating Museum Day ticket holders in your area. View details
70
+ about the museum
71
+ email:
72
+ - dcastellano2007@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - CODE_OF_CONDUCT.md
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/museum_day
86
+ - bin/setup
87
+ - lib/museum_day.rb
88
+ - lib/museum_day/cli.rb
89
+ - lib/museum_day/museum.rb
90
+ - lib/museum_day/scraper.rb
91
+ - lib/museum_day/version.rb
92
+ - museum_day.gemspec
93
+ homepage: https://github.com/DarrelJames/museum_day
94
+ licenses:
95
+ - MIT
96
+ metadata:
97
+ allowed_push_host: https://rubygems.org
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubygems_version: 3.0.6
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Museums in your area
117
+ test_files: []