most_haunted 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: b74d8d20398da5da51ca41ae6a96e3a8be7fcde3
4
+ data.tar.gz: 81570263b0825f9f696e8d659494cccd2f55e33f
5
+ SHA512:
6
+ metadata.gz: 536cba7b0148846a734ed299e000d2ae3ec829b4fe9e24c6ccd774e8ae685c976704d8f79800eebe2a038c660094031396ffd09c2c03de7ec649f596e41495d8
7
+ data.tar.gz: 2a1d3a6c711ac768fd4a2c227012e62642425ba43105d31ca233d0edea3a1b6604068f2658406de010e4b0ab81d4efa5a8fe3a790774dc45867df721cdeeeb9f
data/bin/most_haunted ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require_relative '../lib/most_haunted'
5
+
6
+ MostHauntedCli::CLI.new.call
@@ -0,0 +1,10 @@
1
+ require 'nokogiri'
2
+ require 'open-uri'
3
+ require 'pry'
4
+
5
+ require_relative "../lib/most_haunted/version"
6
+ require_relative "../lib/most_haunted/cli"
7
+ require_relative "../lib/most_haunted/america"
8
+ require_relative "../lib/most_haunted/scraper"
9
+ require_relative "../lib/most_haunted/states"
10
+ require_relative "../lib/most_haunted"
@@ -0,0 +1,54 @@
1
+ class MostHauntedCli::America
2
+ attr_accessor :location, :description
3
+
4
+ @@haunted = []
5
+
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,
17
+ ]
18
+
19
+ def initialize(location, description)
20
+ @location = location
21
+ @description = description
22
+ @@haunted << self
23
+ end
24
+
25
+ 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)
31
+ end
32
+ end
33
+
34
+ def self.haunted
35
+ @@haunted
36
+ end
37
+
38
+ def self.indexes
39
+ INDEXES
40
+ end
41
+
42
+ def self.list_locations
43
+ self.haunted.each{|l| puts l.location}
44
+ end
45
+
46
+ def self.america_descriptions(input)
47
+ input.each do |i|
48
+ description = MostHauntedCli::Scraper.scrape_america_descriptions.children[i].text
49
+ puts description.scan(/.{1,73}/).join("\n")
50
+ puts ""
51
+ end
52
+ end
53
+
54
+ end
@@ -0,0 +1,137 @@
1
+ class MostHauntedCli::CLI
2
+
3
+ def initialize
4
+ MostHauntedCli::Scraper.scrape_america
5
+ MostHauntedCli::Scraper.states
6
+ end
7
+
8
+ def call
9
+ puts "--" * 17
10
+ puts "Search for Scary Places Near You!"
11
+ puts "--" * 17
12
+ start
13
+ goodbye
14
+ end
15
+
16
+ def start
17
+ puts ''
18
+ puts <<-DOC.gsub /^\s*/, ''
19
+
20
+ 1. Most Haunted Places in America
21
+ 2. Choose a State
22
+ DOC
23
+
24
+ input = nil
25
+ puts ''
26
+ while input != "exit"
27
+ puts "--" * 17
28
+ puts "Please enter '1', '2', or 'exit'"
29
+ puts ""
30
+ input = gets.strip.downcase
31
+
32
+ case input
33
+ when "1"
34
+ puts "--" * 17
35
+ puts "10 Most Haunted Places in America"
36
+ puts "--" * 17
37
+ puts ""
38
+ sleep(2)
39
+ list_america
40
+ america_descriptions
41
+ when "2"
42
+ puts ""
43
+ list_states
44
+ state_options
45
+ when "exit"
46
+ goodbye
47
+ exit
48
+ else
49
+ puts ''
50
+ puts "** Please enter valid input **"
51
+ start
52
+ end
53
+ end
54
+ end
55
+
56
+ def list_america
57
+ puts ''
58
+ MostHauntedCli::America.list_locations
59
+ end
60
+
61
+ def list_states
62
+ MostHauntedCli::States.state_columns
63
+ end
64
+
65
+ def state_options
66
+ input = nil
67
+ while input != "exit"
68
+ puts "--" * 30
69
+ puts <<-DOC.gsub /^\s*/, ''
70
+
71
+ * choose an index (1-52) to discover the state's most haunted locations!
72
+ * 'list' for a list of states
73
+ * 'main menu'
74
+ * 'exit'
75
+
76
+ DOC
77
+ 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 ''
84
+ MostHauntedCli::States.open_state_info(input.to_i)
85
+ elsif input == 'main menu'
86
+ start
87
+ elsif input == 'list'
88
+ puts ''
89
+ MostHauntedCli::States.state_columns
90
+ elsif input == 'exit'
91
+ goodbye
92
+ exit
93
+ else
94
+ puts ''
95
+ puts "** Please enter valid input **"
96
+ state_options
97
+ end
98
+ end
99
+ 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
+
133
+ def goodbye
134
+ puts ''
135
+ puts "Scare ya later!"
136
+ end
137
+ end
@@ -0,0 +1,83 @@
1
+ class MostHauntedCli::Scraper
2
+
3
+ @@america = []
4
+ @@s = []
5
+ @@urls = []
6
+
7
+ URL = "https://hauntedrooms.com/haunted-places"
8
+
9
+ def self.america
10
+ @@america
11
+ end
12
+
13
+ def self.s
14
+ @@s
15
+ end
16
+
17
+ def self.urls
18
+ @@urls
19
+ end
20
+
21
+ def self.scrape_america
22
+ 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
26
+ end
27
+ MostHauntedCli::America.create(self.america)
28
+ end
29
+
30
+ def self.scrape_america_descriptions
31
+ doc = Nokogiri::HTML(open(URL))
32
+ paragraphs = doc.search("div.entry-content p")
33
+ paragraphs
34
+ end
35
+
36
+ # 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)
45
+ end
46
+
47
+ def self.scrape_state_url
48
+ doc = Nokogiri::HTML(open(URL))
49
+ states = doc.search("tbody li").children
50
+ states.each do |t|
51
+ self.urls << t.attribute("href").value
52
+ 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
64
+ end
65
+
66
+ def self.scrape_state_locations(input)
67
+ list = []
68
+ u = MostHauntedCli::States.haunted
69
+ url = u[input.to_i - 1].url
70
+ doc = Nokogiri::HTML(open(url))
71
+ locations = doc.search("div.entry-content h2").children
72
+ if locations.empty? == true
73
+ locations = doc.search("div.entry-content i").children
74
+ if locations.empty? == true
75
+ locations = doc.search("h3.section-title.clearfix.title_center").children
76
+ end
77
+ end
78
+ locations.each do |l|
79
+ list << l.text.gsub("end section_title", " ") unless l.text == "(Stay Here)" || l.text == "(Book Now)" || l.text == "(Book a Room)"
80
+ end
81
+ list
82
+ end
83
+ end
@@ -0,0 +1,60 @@
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
@@ -0,0 +1,3 @@
1
+ module MostHauntedCli
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,5 @@
1
+ module MostHauntedCli
2
+
3
+ end
4
+
5
+ require_relative '../config/environment'
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: most_haunted
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - jamiegiuliano
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-01-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: '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: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
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
+ - !ruby/object:Gem::Dependency
70
+ name: nokogiri
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 1.8.1
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 1.8.1
83
+ description: Top 10 Haunted Locations in America and Top Haunted Locations in Every
84
+ State.
85
+ email:
86
+ - jamiepgiuliano@gmail.com
87
+ executables:
88
+ - most_haunted
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - bin/most_haunted
93
+ - config/environment.rb
94
+ - lib/most_haunted.rb
95
+ - lib/most_haunted/america.rb
96
+ - lib/most_haunted/cli.rb
97
+ - lib/most_haunted/scraper.rb
98
+ - lib/most_haunted/states.rb
99
+ - lib/most_haunted/version.rb
100
+ homepage: https://github.com/jamiegiuliano/most_haunted_cli_gem
101
+ licenses:
102
+ - MIT
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.5.1
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: Most Haunted Places in America
124
+ test_files: []