most_haunted 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: b74d8d20398da5da51ca41ae6a96e3a8be7fcde3
4
- data.tar.gz: 81570263b0825f9f696e8d659494cccd2f55e33f
2
+ SHA256:
3
+ metadata.gz: e608c2cfc119130c11cb3f6f9aa92624bb11a87cd9fbac5247d9ca5fb84dadf9
4
+ data.tar.gz: f8338e0204313f5de88984750da9065f1253247ec8e233ce3b2d29a2130afdb6
5
5
  SHA512:
6
- metadata.gz: 536cba7b0148846a734ed299e000d2ae3ec829b4fe9e24c6ccd774e8ae685c976704d8f79800eebe2a038c660094031396ffd09c2c03de7ec649f596e41495d8
7
- data.tar.gz: 2a1d3a6c711ac768fd4a2c227012e62642425ba43105d31ca233d0edea3a1b6604068f2658406de010e4b0ab81d4efa5a8fe3a790774dc45867df721cdeeeb9f
6
+ metadata.gz: 1b0e283795c2d0f83dd669d9b6a6051394f77d17c28ed181b67b6b09ed8ca80e3f3bbf600c63fd46e8c51dc172f8d63aa56b447d5002ff9a7c511f9577a5e458
7
+ data.tar.gz: 410fbb1423b6bbc081dddf1b52ffb800df6a1f09ddc07c07a1bedc0b8e5d6fd0d0b2a6d489ca6f39e04283d361de99ea5702abed7a8279dc36894c77eb72d410
@@ -1,10 +1,9 @@
1
1
  require 'nokogiri'
2
2
  require 'open-uri'
3
- require 'pry'
4
3
 
5
4
  require_relative "../lib/most_haunted/version"
6
5
  require_relative "../lib/most_haunted/cli"
7
6
  require_relative "../lib/most_haunted/america"
8
7
  require_relative "../lib/most_haunted/scraper"
9
8
  require_relative "../lib/most_haunted/states"
10
- require_relative "../lib/most_haunted"
9
+ require_relative "../lib/most_haunted"
@@ -1,48 +1,61 @@
1
1
  class MostHauntedCli::America
2
- attr_accessor :location, :description
3
-
4
- @@haunted = []
5
-
2
+ attr_accessor :id, :name, :location, :description
3
+
4
+ @@all = []
5
+
6
6
  INDEXES = [
7
- (46..48).to_a,
8
- (41..44).to_a,
9
- (36..39).to_a,
10
- (32..34).to_a,
11
- (28..30).to_a,
12
- (25..26).to_a,
13
- (21..23).to_a,
14
- (17..19).to_a,
15
- (13..15).to_a,
16
- (8..11).to_a,
7
+ (46..48),
8
+ (41..44),
9
+ (36..39),
10
+ (32..34),
11
+ (28..30),
12
+ (25..26),
13
+ (21..23),
14
+ (17..19),
15
+ (13..15),
16
+ (8..11),
17
17
  ]
18
-
19
- def initialize(location, description)
18
+
19
+ def initialize(id, name, location, description)
20
+ @id = id
21
+ @name = name
20
22
  @location = location
21
23
  @description = description
22
- @@haunted << self
24
+ @@all << self
23
25
  end
24
-
26
+
25
27
  def self.create(array)
26
- array.each do |h|
27
- location = h
28
- d = h.split(".")[0].to_i
29
- description = INDEXES[d-1]
30
- self.new(location, description)
28
+ array.each do |unparsed_info|
29
+ parsed_info = unparsed_info.split(",", 2)
30
+ name = parsed_info[0]
31
+ location = parsed_info[1]
32
+ id = unparsed_info.split(".")[0].to_i
33
+ description = indexes[id-1]
34
+
35
+ self.new(id, name, location, description)
31
36
  end
32
37
  end
33
-
34
- def self.haunted
35
- @@haunted
38
+
39
+ def self.all
40
+ @@all
36
41
  end
37
-
42
+
38
43
  def self.indexes
39
- INDEXES
44
+ INDEXES.each{|range| (range).to_a }
40
45
  end
41
-
42
- def self.list_locations
43
- self.haunted.each{|l| puts l.location}
46
+
47
+ def self.found(input)
48
+ self.all.find{|america| america.id == input.to_i}
49
+ end
50
+
51
+ def self.list_location_names
52
+ self.all.each{|l| puts "#{l.name}"}
44
53
  end
45
-
54
+
55
+ def self.find_description_by_input(input)
56
+ self.all[input.to_i - 1].description
57
+ end
58
+
46
59
  def self.america_descriptions(input)
47
60
  input.each do |i|
48
61
  description = MostHauntedCli::Scraper.scrape_america_descriptions.children[i].text
@@ -51,4 +64,4 @@ class MostHauntedCli::America
51
64
  end
52
65
  end
53
66
 
54
- end
67
+ end
@@ -1,34 +1,34 @@
1
1
  class MostHauntedCli::CLI
2
-
2
+
3
3
  def initialize
4
4
  MostHauntedCli::Scraper.scrape_america
5
5
  MostHauntedCli::Scraper.states
6
6
  end
7
-
7
+
8
8
  def call
9
9
  puts "--" * 17
10
- puts "Search for Scary Places Near You!"
10
+ puts "Search for Scary Places Near You!"
11
11
  puts "--" * 17
12
12
  start
13
13
  goodbye
14
14
  end
15
-
15
+
16
16
  def start
17
17
  puts ''
18
18
  puts <<-DOC.gsub /^\s*/, ''
19
-
19
+
20
20
  1. Most Haunted Places in America
21
21
  2. Choose a State
22
22
  DOC
23
-
23
+
24
24
  input = nil
25
25
  puts ''
26
26
  while input != "exit"
27
27
  puts "--" * 17
28
28
  puts "Please enter '1', '2', or 'exit'"
29
- puts ""
29
+ puts ""
30
30
  input = gets.strip.downcase
31
-
31
+
32
32
  case input
33
33
  when "1"
34
34
  puts "--" * 17
@@ -52,35 +52,65 @@ class MostHauntedCli::CLI
52
52
  end
53
53
  end
54
54
  end
55
-
56
- def list_america
55
+
56
+ def list_america
57
57
  puts ''
58
- MostHauntedCli::America.list_locations
58
+ MostHauntedCli::America.list_location_names
59
59
  end
60
-
60
+
61
+ def america_descriptions
62
+ input = nil
63
+ while input != "exit"
64
+ puts "--" * 30
65
+ puts <<-DOC.gsub /^\s*/, ''
66
+
67
+ * choose an index (1-10) for more information on a location
68
+ * 'list' for the 10 Most Haunted Places in America
69
+ * 'main menu'
70
+ * 'exit'
71
+ DOC
72
+ input = gets.strip.downcase
73
+
74
+ if input.to_i.between?(1, MostHauntedCli::America.all.size)
75
+ puts ''
76
+ puts "Location: #{MostHauntedCli::America.all[input.to_i].location}"
77
+ puts ''
78
+ MostHauntedCli::America.america_descriptions(MostHauntedCli::America.find_description_by_input(input))
79
+ elsif input == "list"
80
+ puts ''
81
+ MostHauntedCli::America.list_location_names
82
+ elsif input == "main menu"
83
+ start
84
+ elsif input == 'exit'
85
+ goodbye
86
+ exit
87
+ else
88
+ puts ''
89
+ puts "** Please enter valid input **"
90
+ america_descriptions
91
+ end
92
+ end
93
+ end
94
+
61
95
  def list_states
62
96
  MostHauntedCli::States.state_columns
63
97
  end
64
-
98
+
65
99
  def state_options
66
100
  input = nil
67
101
  while input != "exit"
68
102
  puts "--" * 30
69
103
  puts <<-DOC.gsub /^\s*/, ''
70
-
104
+
71
105
  * choose an index (1-52) to discover the state's most haunted locations!
72
106
  * 'list' for a list of states
73
107
  * 'main menu'
74
108
  * 'exit'
75
-
109
+
76
110
  DOC
77
111
  input= gets.strip.downcase
78
-
79
- if input.to_i > 0 && input.to_i < 53
80
- puts "--" * 20
81
- MostHauntedCli::Scraper.scrape_state_title(input.to_i)
82
- puts "--" * 20
83
- puts ''
112
+
113
+ if input.to_i.between?(1, MostHauntedCli::States.all.length)
84
114
  MostHauntedCli::States.open_state_info(input.to_i)
85
115
  elsif input == 'main menu'
86
116
  start
@@ -97,41 +127,9 @@ class MostHauntedCli::CLI
97
127
  end
98
128
  end
99
129
  end
100
-
101
- def america_descriptions
102
- input = nil
103
- while input != "exit"
104
- puts "--" * 30
105
- puts <<-DOC.gsub /^\s*/, ''
106
-
107
- * choose an index (1-10) for more information on a location
108
- * 'list' for the 10 Most Haunted Places in America
109
- * 'main menu'
110
- * 'exit'
111
- DOC
112
- input = gets.strip.downcase
113
-
114
- if input.to_i > 0 && input.to_i < 11
115
- puts ''
116
- MostHauntedCli::America.america_descriptions(MostHauntedCli::America.indexes[input.to_i-1])
117
- elsif input == "list"
118
- puts ''
119
- MostHauntedCli::America.list_locations
120
- elsif input == "main menu"
121
- start
122
- elsif input == 'exit'
123
- goodbye
124
- exit
125
- else
126
- puts ''
127
- puts "** Please enter valid input **"
128
- america_descriptions
129
- end
130
- end
131
- end
132
-
130
+
133
131
  def goodbye
134
132
  puts ''
135
133
  puts "Scare ya later!"
136
134
  end
137
- end
135
+ end
@@ -1,73 +1,60 @@
1
1
  class MostHauntedCli::Scraper
2
-
2
+
3
3
  @@america = []
4
- @@s = []
4
+ @@states = []
5
5
  @@urls = []
6
-
6
+
7
7
  URL = "https://hauntedrooms.com/haunted-places"
8
-
8
+
9
9
  def self.america
10
- @@america
10
+ @@america
11
11
  end
12
-
13
- def self.s
14
- @@s
15
- end
16
-
17
- def self.urls
18
- @@urls
19
- end
20
-
12
+
21
13
  def self.scrape_america
22
14
  doc = Nokogiri::HTML(open(URL))
23
- new = doc.search("h3.section-title.clearfix span").children
24
- new.each do |list|
25
- self.america << list.text
15
+ list = doc.search("h3.section-title span").children
16
+ list.each do |l|
17
+ self.america << l.text.strip
26
18
  end
27
19
  MostHauntedCli::America.create(self.america)
28
20
  end
29
-
21
+
30
22
  def self.scrape_america_descriptions
31
23
  doc = Nokogiri::HTML(open(URL))
32
24
  paragraphs = doc.search("div.entry-content p")
33
25
  paragraphs
34
26
  end
35
-
27
+
36
28
  # Individual State Information
37
-
38
- def self.states
39
- doc = Nokogiri::HTML(open(URL))
40
- states = doc.search("tbody li").children
41
- states.each do |t|
42
- self.s << t.text
43
- end
44
- MostHauntedCli::States.create_state(self.s)
29
+
30
+ def self.all_states
31
+ @@states
45
32
  end
46
-
47
- def self.scrape_state_url
33
+
34
+ def self.urls
35
+ @@urls
36
+ end
37
+
38
+ def self.states
48
39
  doc = Nokogiri::HTML(open(URL))
49
40
  states = doc.search("tbody li").children
50
41
  states.each do |t|
42
+ self.all_states << t.text
51
43
  self.urls << t.attribute("href").value
52
44
  end
53
- self.urls
54
- end
55
-
56
- def self.scrape_state_title(input)
57
- title = []
58
- u = MostHauntedCli::States.haunted
59
- url = u[input - 1].url
60
- doc = Nokogiri::HTML(open(url))
61
- t = doc.search("h1.entry-title").text
62
- title << t
63
- puts title
45
+ MostHauntedCli::States.create_state(self.all_states)
64
46
  end
65
-
47
+
66
48
  def self.scrape_state_locations(input)
67
49
  list = []
68
- u = MostHauntedCli::States.haunted
50
+ title = []
51
+ u = MostHauntedCli::States.all
69
52
  url = u[input.to_i - 1].url
70
- doc = Nokogiri::HTML(open(url))
53
+ doc = Nokogiri::HTML(open("https://hauntedrooms.com"+"#{url}"))
54
+
55
+ t = doc.search("h1.entry-title").text.strip
56
+ title << t
57
+
71
58
  locations = doc.search("div.entry-content h2").children
72
59
  if locations.empty? == true
73
60
  locations = doc.search("div.entry-content i").children
@@ -78,6 +65,10 @@ class MostHauntedCli::Scraper
78
65
  locations.each do |l|
79
66
  list << l.text.gsub("end section_title", " ") unless l.text == "(Stay Here)" || l.text == "(Book Now)" || l.text == "(Book a Room)"
80
67
  end
68
+ puts "--" * 20
69
+ puts title
70
+ puts "--" * 20
71
+ puts ''
81
72
  list
82
73
  end
83
- end
74
+ end
@@ -1,3 +1,3 @@
1
1
  module MostHauntedCli
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: most_haunted
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - jamiegiuliano
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-30 00:00:00.000000000 Z
11
+ date: 2018-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,20 +52,6 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
- - !ruby/object:Gem::Dependency
56
- name: pry
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: nokogiri
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -95,7 +81,6 @@ files:
95
81
  - lib/most_haunted/america.rb
96
82
  - lib/most_haunted/cli.rb
97
83
  - lib/most_haunted/scraper.rb
98
- - lib/most_haunted/states.rb
99
84
  - lib/most_haunted/version.rb
100
85
  homepage: https://github.com/jamiegiuliano/most_haunted_cli_gem
101
86
  licenses:
@@ -117,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
102
  version: '0'
118
103
  requirements: []
119
104
  rubyforge_project:
120
- rubygems_version: 2.5.1
105
+ rubygems_version: 2.7.5
121
106
  signing_key:
122
107
  specification_version: 4
123
108
  summary: Most Haunted Places in America
@@ -1,60 +0,0 @@
1
- class MostHauntedCli::States
2
- attr_accessor :name, :url
3
-
4
- @@haunted = []
5
- @@states = []
6
-
7
- def initialize(name)
8
- @name = name
9
- @@haunted << self
10
- end
11
-
12
- def self.create_state(array)
13
- array.each do |s|
14
- name = s
15
- self.new(name)
16
- end
17
- add_urls
18
- end
19
-
20
- def self.haunted
21
- @@haunted
22
- end
23
-
24
- def self.states
25
- @@states
26
- end
27
-
28
- def self.states_list
29
- self.haunted.collect.with_index(1){|s, i| "#{i}. #{s.name}"}
30
- end
31
-
32
- def self.create_columns(slice)
33
- l = slice[0].length
34
- if l >= 24
35
- puts "#{slice[0]}"+" "+"#{slice[1]}"
36
- else
37
- puts "#{slice[0]}"+" " * (30 - l)+"#{slice[1]}"
38
- end
39
- end
40
-
41
- def self.state_columns
42
- states_list.each.each_slice(2) do |slice|
43
- create_columns(slice)
44
- end
45
- end
46
-
47
- # Individual State Information
48
-
49
- def self.open_state_info(input)
50
- info = MostHauntedCli::Scraper.scrape_state_locations(input)
51
- info.each{|i| puts i.gsub(' –', '.')}
52
- end
53
-
54
- def self.add_urls
55
- u = MostHauntedCli::Scraper.scrape_state_url
56
- self.haunted.each.with_index do |h, i|
57
- h.url = u[i]
58
- end
59
- end
60
- end