museum_day 0.1.1 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6a4414b743dfe3ba0049410446b42b0a729e6faf5f1f3f6b2ed5398a134fa4be
4
- data.tar.gz: 03a4e03e2f30f7a81a2394086e99ad0ab78c88b7bd21874b864fb9d3042df9d5
3
+ metadata.gz: d938321beef4fed01f48eeec3bf71810e44a6d985bf19016e5431c4a4b20f43b
4
+ data.tar.gz: e3eb4b10c9d9ca4f22f0aafdff50f643fda270b130c90cca12586dd21e3664fa
5
5
  SHA512:
6
- metadata.gz: a2fa2f2ebf1ec02d96e9747869d18463edef174a16a879f4e68162df23a436e805d8345cd5b3d4fd6a75e5a14b9e407dfbb8527c948340fd48c02886231eb27d
7
- data.tar.gz: 75ef79ba09dee66454f6da71cbcd2d4295519ac626e5e4664304bde68f66a1581a9b1e5762d4bc03463d774abe0f215336499496cfeb5cce4d239c447b6790a5
6
+ metadata.gz: ac309afc924b9b76d27d71275bd8fa68704cc4ccbed3383d6cf8417df87d71d6a3cfbf9fb0d1b99c76ea6faf7124b7673b68177fcb4a37a95e879f136bebf63b
7
+ data.tar.gz: cb95c512b1483d69fffa9ce58936fd045f97a12bd38451dc8f1131b51a886183172f3a69511826e9aefeeb4f175b84c50e5986a6a77814c9d77d9d7110f7a9aa
data/.DS_Store ADDED
Binary file
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- museum_day (0.1.1)
4
+ museum_day (0.1.2)
5
5
  nokogiri
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -4,18 +4,6 @@ This Ruby Gem provides a CLI to view the participating Museums for Museum Day ti
4
4
 
5
5
  ## Installation
6
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 install
16
-
17
- Or install it yourself as:
18
-
19
7
  $ gem install museum_day
20
8
 
21
9
  ## Usage
@@ -8,50 +8,30 @@ class MuseumDay::CLI
8
8
 
9
9
 
10
10
  def start
11
- if !zipcode
12
- get_zipcode
13
- end
14
11
 
15
- exit?(zipcode)
16
- list_museums(zipcode)
12
+ get_zipcode if !zipcode
17
13
 
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
14
+ exit?(zipcode)
24
15
 
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"
16
+ list_museums(zipcode)
30
17
 
31
- end
32
- end
18
+ get_user_input_for_details_and_print
33
19
 
34
20
  menu
35
21
 
36
22
  input = gets.strip.downcase
37
23
  exit?(input)
38
24
 
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
25
+ new_or_back?(input)
26
+
47
27
  end
48
28
 
49
29
  def list_museums(input)
50
30
 
51
- MuseumDay::Scraper.new(input).make_museums
31
+ @scraper = MuseumDay::Scraper.new(input)
32
+ @scraper.make_museums
52
33
 
53
- puts ""
54
- puts "--------------Listing museums near #{zipcode}--------------"
34
+ puts "\n--------------Listing museums near #{zipcode}--------------"
55
35
 
56
36
  MuseumDay::Museum.all.each.with_index(1) do |museum, idx|
57
37
  puts "#{idx}. #{museum.name} - #{museum.city}"
@@ -62,55 +42,71 @@ class MuseumDay::CLI
62
42
 
63
43
  museum = MuseumDay::Museum.find(input.to_i)
64
44
 
65
- puts ""
66
- puts "--------------#{museum.name}--------------"
45
+ @scraper.scrape_details(museum)
46
+
47
+ puts "\n--------------#{museum.name}--------------"
67
48
  puts "#{museum.address}"
68
49
  puts " Hours: #{museum.hours}"
69
- puts ""
70
- puts "Phone Number: #{museum.phone_number}"
50
+ puts "\nPhone Number: #{museum.phone_number}"
71
51
  puts "Website: #{museum.website_url}"
52
+ puts "Facebook: #{museum.fb}" if museum.fb
53
+ puts "Twitter: #{museum.twitter}" if museum.twitter
54
+ puts "\n--------------Description--------------"
55
+ puts "#{museum.description}"
56
+ end
72
57
 
73
- museum.social_urls
74
- if museum.fb
75
- puts "Facebook: #{museum.fb}"
76
- end
58
+ def get_user_input_for_details_and_print
59
+ input = 0
77
60
 
78
- if museum.twitter
79
- puts "Twitter: #{museum.twitter}"
80
- end
61
+ while !input.to_i.between?(1, MuseumDay::Museum.all.size)
62
+ puts "\nEnter the number of the museum you'd like more info on or type exit"
63
+ input = gets.strip
81
64
 
82
- puts ""
83
- puts "--------------Description--------------"
84
- puts "#{museum.description}"
65
+ exit?(input)
66
+ if input.to_i.between?(1, MuseumDay::Museum.all.size)
67
+ print_museum_details(input)
68
+ else
69
+ puts "Invalid number"
70
+
71
+ end
72
+ end
85
73
  end
86
74
 
87
75
  def menu
88
- puts ""
89
- puts "To go back to list of museum, enter 'back'."
76
+ puts "\n---------------------------------------------"
77
+ puts "To go back to list of museums, enter 'back'."
90
78
  puts "To search a new zipcode, enter 'new'."
91
79
  puts "To quit, enter 'exit'."
80
+ puts "---------------------------------------------"
92
81
  end
93
82
 
94
83
  def get_zipcode
95
- puts ""
96
- puts "Please enter your zipcode or type exit"
84
+ puts "\nPlease enter your zipcode or type exit"
97
85
 
98
- @zipcode = gets.strip
86
+ self.zipcode = gets.strip
99
87
  exit?(zipcode)
100
88
 
101
89
  if zipcode.size != 5
102
- puts ""
103
- puts "Invalid Zipcode"
90
+ puts "\nInvalid Zipcode"
104
91
  get_zipcode
105
92
  end
106
93
  end
107
94
 
108
- def exit?(input)
109
- if input.downcase == "exit"
110
- goodbye
95
+ def new_or_back?(input)
96
+ if input == "new"
97
+ MuseumDay::Museum.clear_all
98
+ self.zipcode = nil
99
+ start
100
+ elsif input == "back"
101
+ MuseumDay::Museum.clear_all
102
+ start
111
103
  end
112
104
  end
113
105
 
106
+ def exit?(input)
107
+ goodbye if input.downcase == "exit"
108
+ end
109
+
114
110
  def goodbye
115
111
  puts "-----------------"
116
112
  puts "| Goodbye |"
@@ -5,20 +5,11 @@ class MuseumDay::Museum
5
5
 
6
6
  @@all = []
7
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
8
+ def initialize(attributes)
9
+ @name = attributes[:name]
10
+ @city = attributes[:city]
11
+ @url = attributes[:url]
12
+ @hours = attributes[:hours]
22
13
  @@all << self
23
14
  end
24
15
 
@@ -30,38 +21,6 @@ class MuseumDay::Museum
30
21
  self.all[id-1]
31
22
  end
32
23
 
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
24
  def self.clear_all
66
25
  @@all.clear
67
26
  end
@@ -16,8 +16,30 @@ class MuseumDay::Scraper
16
16
 
17
17
  def make_museums
18
18
  scrape_museums_index.each do |museum|
19
- MuseumDay::Museum.new_from_index(museum)
19
+ attribute_hash = {
20
+ name: museum.css("h4.name").text,
21
+ city: museum.css("h5.location").text,
22
+ url: museum.css("a").attribute("href").value,
23
+ hours: museum.at("div strong").next_sibling.text.strip
24
+ }
25
+ MuseumDay::Museum.new(attribute_hash)
20
26
  end
21
27
  end
22
28
 
29
+ def scrape_details(museum)
30
+ doc = Nokogiri::HTML(open("https://www.smithsonianmag.com#{museum.url}"))
31
+ museum.description = doc.css("div.aux-info p").first.text
32
+ museum.address = doc.css("p.address").text.strip
33
+ museum.website_url = doc.css("i.fa-external-link + a").attribute("href").value
34
+ museum.phone_number = doc.at("i.fa-phone").next_sibling.text.strip
35
+
36
+ #Scrape Socials
37
+ doc.css("div.contact a").collect { |link| link.attribute("href").value }.each do |link|
38
+ if link.include?("twitter")
39
+ museum.twitter = link
40
+ elsif link.include?("facebook")
41
+ museum.fb = link
42
+ end
43
+ end
44
+ end
23
45
  end
@@ -1,3 +1,3 @@
1
1
  module MuseumDay
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: museum_day
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Darrel Castellano
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-30 00:00:00.000000000 Z
11
+ date: 2019-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -75,6 +75,7 @@ executables:
75
75
  extensions: []
76
76
  extra_rdoc_files: []
77
77
  files:
78
+ - ".DS_Store"
78
79
  - ".gitignore"
79
80
  - CODE_OF_CONDUCT.md
80
81
  - Gemfile