martial_arts 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: 316b71c30e2141874e58eb3a64a236dd4efcb599e1a92f868b2657576cab88fb
4
+ data.tar.gz: 16022d8d1db5fbc6b690acc5c4866bf950b0878c96b663aecd6cbd3d6ba89c8e
5
+ SHA512:
6
+ metadata.gz: 2c05d4780050c067c3bd95318e94e919623e5e3253ac49afe1f7f8ca58e74a75130ea7e014f24973d55a9bc8643e8a13b326d3995cc340e0dbf120b3eb99246f
7
+ data.tar.gz: 43be206f24f904d03fb3286968d23209cca7ff930643f76c0c963dd20ff8d87f7ee931e9445ce8fe3ce5ec3980d11b1def9b292821e74807f26d0a34b257eab4
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 'blackbeltdiaries@gmail.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/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in martial_arts.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 'Joseph Jimenez'
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,45 @@
1
+ # MartialArts
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/martial_arts`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: This Ruby Gem provides a CLI to view the world's most popular martial arts taken from a www.singpatong-sitnumnoi.com; Users can also learn more information about the style such as (wiki-website, description, name, country, fighting-focus). styles, can be searched by country, or fighting-focus. I have also added code to collect incomplete data from the scrape if one has the desire to add code to retrieve it. Enjoy!
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'martial_arts'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install martial_arts
22
+
23
+ ## Usage
24
+
25
+ Type the below and follow the on screen prompts.
26
+
27
+ TODO: $ ./bin/martial-arts-console
28
+
29
+ ## Development
30
+
31
+ 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.
32
+
33
+ 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).
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/'MonksAndNinjas'/martial_arts. 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.
38
+
39
+ ## License
40
+
41
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
42
+
43
+ ## Code of Conduct
44
+
45
+ Everyone interacting in the MartialArts project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/'MonksAndNinjas'/martial_arts/blob/master/CODE_OF_CONDUCT.md).
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
+ require 'pry'
3
+ #require 'bundler/setup'
4
+ require "./lib/martial_arts"
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__)
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require './lib/martial_arts'
4
+
5
+ puts ""
6
+ puts ""
7
+ puts ""
8
+ puts ""
9
+ puts ""
10
+
11
+ puts " \ | ,".green
12
+ puts " 888888 88888 88888 88888888 888888888 888 88888 888 * -".green
13
+ puts " 888 888 88 888 888 888 888 888 888 888 888 888 888 | `".cyan
14
+ puts " 888 8888 888 888 888 888 888 888 888 888 888 888".magenta
15
+ puts " 888 88 888 888 888 888 888 888 888 888 888 88888888".blue
16
+
17
+ puts ""
18
+ puts ""
19
+
20
+ puts " 88888 88888888 888888888 888888".green
21
+ puts " 888 888 888 888 888 88x".cyan
22
+ puts " 888 888 888 888 888 *88".magenta
23
+ puts " 888 888 888 888 888 8888888".blue
24
+
25
+ puts " ......please wait".blue
26
+ puts ""
27
+ puts ""
28
+ puts ""
29
+
30
+ MartialArts::Scraper.scrape_data
31
+ MartialArts::CLI.new.call
32
+
33
+
34
+ puts " "
35
+ puts " "
36
+ puts " #{"_ _ _ _".green}"
37
+ puts " #{"/@)".cyan }#{"-' '-".green}#{"(@\\".cyan}"
38
+ puts " #{"|".cyan} #{"/ \\".green} #{"|".cyan}"
39
+ puts " #{"(,".magenta}#{". .".green}#{",)".magenta}"
40
+ puts " #{"|8".magenta}#{"| |".green}#{"8|".magenta}"
41
+ puts " #{"|8".blue}#{"| |".yellow}#{"8|".blue}"
42
+ puts " #{".".blue} #{">".yellow} #{"<".yellow} #{".".blue}"
43
+ puts " "
44
+ puts " GOODBYE".blue
45
+ puts " thanks for visiting".blue
46
+ puts " "
47
+ puts " "
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,10 @@
1
+ require 'open-uri'
2
+ require 'nokogiri'
3
+ require 'colorize'
4
+
5
+ require_relative "./martial_arts/version"
6
+ require_relative "./martial_arts/cli"
7
+ require_relative "./martial_arts/styles"
8
+ require_relative "./martial_arts/countries"
9
+ require_relative "./martial_arts/fighting_focus"
10
+ require_relative "./martial_arts/scraper"
@@ -0,0 +1,357 @@
1
+ # CLI Controler
2
+ class MartialArts::CLI
3
+
4
+ def call
5
+ messages("greeting")
6
+
7
+ menu
8
+ end
9
+
10
+ def menu
11
+ navigation = {
12
+ 1 => [ "Popular Martial Arts", method(:popular_martial_arts_submenu) ],
13
+ 2 => [ "Martial Arts by Country", method(:martial_arts_by_country_submenu) ],
14
+ 3 => [ "Martial Art Styles", method(:all_styles_submenu) ],
15
+ 4 => [ "Martial Art by Fighting-Focus", method(:fighting_focus_submenu) ]
16
+ }
17
+
18
+ input = nil
19
+
20
+ while input != "exit"
21
+ puts " "
22
+ navigation.each {|i, submenu_array| puts "#{i}. #{submenu_array[0]}" }
23
+ puts " "
24
+ puts "Please enter the corresponding number or type exit".cyan
25
+
26
+ input = gets.strip.downcase
27
+
28
+ case input
29
+ when "1", "2", "3", "4"
30
+ navigation[input.to_i][1].()
31
+
32
+ when "missing data" #hidden submenu
33
+ MartialArts::Styles.missing_info.each.with_index(1) do |style_instance, i|
34
+ puts "#{i}. #{style_instance.name}"
35
+ puts "Country: #{style_instance.country_name}" if style_instance.country_name == "N/A"
36
+ puts "Fighting-Focus: #{style_instance.fighting_focus_name}" if style_instance.fighting_focus_name == "N/A"
37
+ puts "Description: #{style_instance.description}" if style_instance.description == "N/A"
38
+ puts " "
39
+ end
40
+ when "exit"
41
+ #exits the application
42
+ else
43
+ messages("invalid")
44
+ end
45
+
46
+ end
47
+ end
48
+
49
+ def popular_martial_arts_submenu
50
+ #this outputs the 10 most popular martial arts in the world.
51
+ input = nil
52
+
53
+ popular_list
54
+
55
+ while input != "back"
56
+ input = gets.strip.downcase
57
+
58
+ case input
59
+ when "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"
60
+ style = MartialArts::Styles.popular[input.to_i - 1]
61
+
62
+ if style == "Chinese Martial Arts"
63
+ MartialArts::Styles.search_by_country("China").each do |style_instance|
64
+ puts "#{display_info_for(style_instance)}"
65
+ end
66
+
67
+ messages("list or back")
68
+ else
69
+ display_info_for(style)
70
+ messages("list or back")
71
+ end
72
+
73
+ when "list"
74
+ popular_list
75
+ when "back"
76
+ break
77
+ else
78
+ messages("invalid")
79
+ end
80
+
81
+ end
82
+ end
83
+
84
+ def popular_list
85
+
86
+ messages("popular")
87
+ MartialArts::Styles.popular.each.with_index(1) do |style_instance, i|
88
+ puts "#{i}. #{style_instance.name}" if style_instance.class == MartialArts::Styles
89
+ puts "#{i}. #{style_instance}" if style_instance.class == String #This could be removed if it is performed along with the scrape
90
+ end
91
+ messages("user")
92
+
93
+ end
94
+
95
+ def martial_arts_by_country_submenu
96
+ size = MartialArts::Countries.country_list.size
97
+ input = nil
98
+
99
+ messages("countries")
100
+ MartialArts::Countries.country_list.each.with_index(1) {|country, i| puts "#{i}. #{country}"}
101
+ messages("user")
102
+
103
+ while input != "back"
104
+ input = gets.strip.downcase
105
+
106
+ case input
107
+ when /\d\d*/ #checks if input is a number
108
+
109
+ if (1...size+1).include?(input.to_i)
110
+ styles_by_country_list(input)
111
+
112
+ country_styles_sub_submenu
113
+ else
114
+ messages("invalid")
115
+ end
116
+
117
+ when "list"
118
+ messages("countries")
119
+ MartialArts::Countries.country_list.each.with_index(1) {|country, i| puts "#{i}. #{country}"}
120
+ messages("user")
121
+ when "back"
122
+ break
123
+ else
124
+ messages("invalid")
125
+ end
126
+
127
+ end
128
+ end
129
+
130
+ def country_styles_sub_submenu
131
+ size = @style_list.size
132
+ input = nil
133
+
134
+ while input != "back"
135
+ input = gets.strip.downcase
136
+
137
+ case input
138
+ when /\d\d*/ #checks if input is a number
139
+
140
+ if (1...size+1).include?(input.to_i)
141
+
142
+ display_info_for(@style_list[input.to_i-1])
143
+ messages("list or back")
144
+ else
145
+ messages("invalid")
146
+ end
147
+
148
+ when "list"
149
+ styles_by_country_list(@country_input)
150
+ when "back"
151
+ messages("countries")
152
+ MartialArts::Countries.country_list.each.with_index(1) {|country, i| puts "#{i}. #{country}"}
153
+ messages("user")
154
+ break
155
+ else
156
+ messages("invalid")
157
+ end
158
+
159
+ end
160
+ end
161
+
162
+ def styles_by_country_list(input)
163
+ @country_input = input
164
+ @country = MartialArts::Countries.country_list[input.to_i-1]
165
+ @style_list = MartialArts::Styles.search_by_country(@country)
166
+
167
+ messages("styles by country")
168
+ @style_list.each.with_index(1) {|style_instance, i| puts "#{i}. #{style_instance.name}"}
169
+ messages("user")
170
+
171
+ end
172
+
173
+ def all_styles_submenu
174
+ size = MartialArts::Styles.all.size
175
+ input = nil
176
+
177
+ messages("all styles")
178
+ MartialArts::Styles.styles_list.each.with_index(1) {|style_instance, i| puts "#{i}. #{style_instance.name}" }
179
+ messages("user")
180
+
181
+ while input != "back"
182
+ input = gets.strip.downcase
183
+
184
+ case input
185
+ when /\d\d*/ #Checks if input is a number
186
+
187
+ if (1...size+1).include?(input.to_i)
188
+ style = MartialArts::Styles.styles_list[input.to_i-1]
189
+
190
+ display_info_for(style)
191
+ messages("list or back")
192
+ else
193
+ messages("invalid")
194
+ end
195
+
196
+ when "list"
197
+ messages("all styles")
198
+ MartialArts::Styles.styles_list.each.with_index(1) {|style_instance, i| puts "#{i}. #{style_instance.name}" }
199
+ messages("user")
200
+ when "back"
201
+ break
202
+ else
203
+ messages("invalid")
204
+ end
205
+
206
+ end
207
+ end
208
+
209
+ def fighting_focus_submenu
210
+ @focus_list = {1 => "Striking", 2 => "Grappling", 3 => "Weaponry", 4 => "Hybrid", 5 => "Internal"}
211
+ input = nil
212
+
213
+ messages("fighting focus menu")
214
+ @focus_list.each {|i, focus| puts "#{i}. #{focus}" }
215
+ messages("user")
216
+
217
+ while input != "back"
218
+ input = gets.strip.downcase
219
+
220
+ case input
221
+ when "1", "2", "3", "4", "5"
222
+ styles_by_focus_list(input)
223
+ styles_by_focus_sub_submenu
224
+
225
+ when "list"
226
+ messages("fighting focus menu")
227
+ @focus_list.each {|i, focus| puts "#{i}. #{focus}" }
228
+ messages("user")
229
+ when "back"
230
+ break
231
+ else
232
+ messages("invalid")
233
+ end
234
+
235
+ end
236
+ end
237
+
238
+ def styles_by_focus_sub_submenu
239
+ size = @focus_style_list.size
240
+ input = nil
241
+
242
+ while input != "back"
243
+ input = gets.strip.downcase
244
+
245
+ case input
246
+ when /\d\d*/ #checks if input is a number
247
+
248
+ if (1...size+1).include?(input.to_i)
249
+ display_info_for(@focus_style_list[input.to_i-1])
250
+ messages("list or back")
251
+ else
252
+ messages("invalid")
253
+ end
254
+
255
+ when "list"
256
+ styles_by_focus_list(@focus_input)
257
+ when "back"
258
+ messages("fighting focus menu")
259
+ @focus_list.each {|i, focus| puts "#{i}. #{focus}" }
260
+ messages("user")
261
+ break
262
+ else
263
+ messages("invalid")
264
+ end
265
+
266
+ end
267
+ end
268
+
269
+ def styles_by_focus_list(input)
270
+ @focus_input = input #save input from focus_submenu so user can return
271
+ @focus_style_list = MartialArts::Styles.search_by_focus(@focus_list[input.to_i])
272
+
273
+ messages("styles by focus")
274
+ @focus_style_list.each.with_index(1) {|style_instance, i| puts "#{i}. #{style_instance.name}" }
275
+ messages("user")
276
+
277
+ end
278
+
279
+ def messages(type)
280
+ case type
281
+ when "greeting"
282
+
283
+ puts "OOOOOOSSSsss".magenta
284
+ puts "Choose your destiny".blue
285
+ #maybe want to add delay from first puts to second, maybe 3 seconds.
286
+ when "invalid"
287
+
288
+ puts ""
289
+ puts "I'm confused can you try that again?".cyan
290
+ puts ""
291
+
292
+ when "user"
293
+
294
+ puts ""
295
+ puts "Enter the corresponding number for more information".light_cyan
296
+ puts "#{"Otherwise type".cyan} list #{"or".cyan} back"
297
+
298
+ when "styles by focus"
299
+
300
+ puts ""
301
+ puts " #{"FIGHTING FOCUS:".magenta} #{@focus_list[@focus_input.to_i]}"
302
+ puts ""
303
+
304
+ when "fighting focus menu"
305
+
306
+ puts ""
307
+ puts " CHOOSE YOUR FIGHTING FOCUS".magenta
308
+ puts ""
309
+
310
+ when "all styles"
311
+
312
+ puts ""
313
+ puts " #{"ALL STYLES".magenta}"
314
+ puts ""
315
+
316
+ when "styles by country"
317
+
318
+ puts ""
319
+ puts " #{"MARTIAL ARTS FROM".magenta} #{@country.upcase.cyan}"
320
+ puts ""
321
+
322
+ when "countries"
323
+
324
+ puts ""
325
+ puts " #{"COUNTRIES".magenta}"
326
+ puts ""
327
+
328
+ when "popular"
329
+
330
+ puts ""
331
+ puts " POPULAR MARTIAL ARTS".magenta#15 tabs for title
332
+ puts ""
333
+
334
+ when "list or back"
335
+
336
+ puts "#{"Type".cyan} list #{"or".cyan} back"
337
+
338
+ else
339
+ end
340
+ end
341
+
342
+ def display_info_for(style)
343
+
344
+ puts " "
345
+ puts " #{"Style info for".magenta} #{style.name.cyan}"
346
+ puts " "
347
+ puts "Country: #{style.country_name.green}"
348
+ puts "Fighting Focus: #{style.fighting_focus_name.yellow}"
349
+ puts " "
350
+ puts "Description: #{style.description.red}"
351
+ puts " "
352
+ puts "More Info: #{style.website.magenta}"
353
+ puts " "
354
+
355
+ end
356
+
357
+ end
@@ -0,0 +1,35 @@
1
+
2
+ class MartialArts::Countries
3
+ attr_reader :name
4
+ @@unfiltered = []
5
+ @@filtered = []
6
+
7
+ def initialize(name)
8
+ @name = name
9
+ @styles = []
10
+ end
11
+
12
+ def add_style(style)
13
+ @styles << style
14
+ style.country = self
15
+ end
16
+
17
+ #def styles
18
+ # @styles styles method not needed, but fulfills country has many styles relationship
19
+ #end
20
+
21
+ def self.country_list
22
+ self.filtered.uniq.sort {|a,b| a <=> b }
23
+ end
24
+
25
+ def self.filtered
26
+ #styles from the list of martial arts wikipedia page, easer to acces but not as much info
27
+ @@filtered
28
+ end
29
+
30
+ def self.unfiltered
31
+ #countries from the style's wikipedia page, has more info but harder to access if not specific
32
+ @@unfiltered
33
+ end
34
+
35
+ end
@@ -0,0 +1,25 @@
1
+
2
+ class MartialArts::FightingFocus
3
+ attr_reader :name
4
+ @@all = []
5
+
6
+ def initialize(fighting_focus)
7
+ @name = fighting_focus
8
+ @styles = []
9
+ end
10
+
11
+ def add_style(style)
12
+ @styles << style
13
+ style.fighting_focus = self
14
+ end
15
+
16
+ #def styles
17
+ # @styles styles method not needed, but fulfills fighting_focus has many styles relationship
18
+ #end
19
+
20
+ def self.all
21
+ #contains fighting_focus in it's raw form; may contain 1, 2, or even 3 types of fighting_focus
22
+ @@all
23
+ end
24
+
25
+ end
@@ -0,0 +1,119 @@
1
+
2
+ class MartialArts::Scraper
3
+ @@all = []
4
+
5
+ def self.scrape_data
6
+ #4 steps
7
+ #1 retrieve all style information from their individual wikipedia websites
8
+ doc = Nokogiri::HTML(open("https://en.wikipedia.org/wiki/List_of_martial_arts"))
9
+ doc.css('.div-col.columns.column-width li').each do |style|
10
+ #opens the style's website
11
+ html = Nokogiri::HTML(open("https://en.wikipedia.org#{style.css('a')[0]['href']}"))
12
+
13
+ if html.css('table.infobox tr') != nil
14
+ html.css('table.infobox tr').each do |info|
15
+
16
+ #retrieves focus and country data
17
+ @focus = info.css('td a').text if info.css('th').text == "Focus"
18
+ @country = info.css('td').text if info.css('th').text == "Country of origin"
19
+
20
+ end
21
+ end
22
+
23
+ #retrieves style data
24
+ style_edit = "#{html.css('h1').text.downcase}".gsub(/(\s\Dmartial\sarts?\D)/, '') #removes generic words in style name
25
+ @style = "#{style_edit}".split.map(&:capitalize).join(' ') #capitalizes first letter of each word
26
+
27
+ #retrieves description data
28
+ description_info = html.css('div.mw-parser-output p').detect do |p|
29
+ p.text.size > 20 and p.text.include?("#{@style}") and p.text != nil
30
+ end
31
+
32
+ if description_info == nil
33
+ @description = "N/A"
34
+ else
35
+ description_edit = "#{description_info.text}".tr('(\D[123456789]\D)', '') #removes unwanted text
36
+ @description = "#{description_edit}".sub('listen', '') #removes first occurence of listen
37
+ end
38
+
39
+ #retrieves website data
40
+ @website = "https://en.wikipedia.org#{style.css('a')[0]['href']}"
41
+
42
+ #checks for missing data that is converted to N/A
43
+
44
+ @country = "N/A" if @country == ""
45
+ @focus = "N/A" if @focus == ""
46
+
47
+ #puts it all together into one string of data
48
+ self.all << "#{@style} - #{@country} - #{@focus} - #{@website} - #{@description}"
49
+ end
50
+
51
+ #2 instantiates the informaiton
52
+ self.import_styles
53
+ #3 retrieves popular martial arts from a website
54
+ self.import_popular
55
+ #4 retrieves easier to acces country list
56
+ self.import_countries
57
+ end
58
+
59
+ def self.import_styles
60
+ self.all.each do |data_string|
61
+ data_array = data_string.split(" - ")
62
+
63
+ @style = data_array[0]
64
+ @country = data_array[1]
65
+ @fighting_focus = data_array[2]
66
+ @website = data_array[3]
67
+ @description = data_array[4]
68
+
69
+ if MartialArts::Styles.duplicates?(@style) == nil
70
+ self.correct_errors(@style, @country, @fighting_focus, @website, @description)
71
+ MartialArts::Styles.all << MartialArts::Styles.new(@style, @country, @fighting_focus, @website, @description)
72
+ end
73
+
74
+ end
75
+ end
76
+
77
+ def self.import_popular
78
+ #popular martial arts 2018
79
+ doc = Nokogiri::HTML(open("http://www.singpatong-sitnumnoi.com/10-most-popular-martial-arts/"))
80
+ info = doc.css('strong').text.split(/No.\w*. | from /) #mixture of country and style
81
+ styles = info.select.with_index {|_, style| style.odd?}
82
+
83
+ styles.each do |style|
84
+ #assuming the style_instance will definitely be there for the most popular style name
85
+ style_instance = MartialArts::Styles.all.find {|style_instance| style_instance.name.downcase == style.downcase }
86
+ self.correct_errors(style_instance, style)
87
+ end
88
+ end
89
+
90
+ def self.import_countries
91
+ doc = Nokogiri::HTML(open("https://en.wikipedia.org/wiki/List_of_martial_arts"))
92
+ doc.css('.div-col.columns.column-width').each_with_index do |info, i|
93
+
94
+ info.css('li').each {|country| MartialArts::Countries.filtered << country.css('a')[1].text } if i == 0 #list for African countries
95
+ info.css('dt a').each {|country| MartialArts::Countries.filtered << country.text } if i > 0 #rest of the countries
96
+
97
+ end
98
+ end
99
+
100
+ def self.all
101
+ @@all
102
+ end
103
+
104
+ def self.correct_errors(info_1, info_2 = nil, info_3 = nil, info_4 = nil, info_5 = nil)
105
+ #enter code here for problems with style info
106
+ if info_1 == "Karate In The United States" #info_1 = style(String class) - from .import_syles
107
+ @style = "American Karate"
108
+ @country = "United States"
109
+ @fighting_focus = "Hybrid"
110
+ end
111
+
112
+ MartialArts::Styles.popular << info_1 if info_1.class == MartialArts::Styles #info_1 == style_instance - from .import_popular
113
+ MartialArts::Styles.popular << "Chinese Martial Arts" if info_2 == "Kung fu" #info_2 == style - from .import_popular
114
+ #Kung Fu encompasses many of the chinese martial arts
115
+
116
+ #ERROR - some styles lead to sites about their people which include info on the style, it just prints out weird ex: Surma people
117
+ end
118
+
119
+ end
@@ -0,0 +1,60 @@
1
+
2
+ class MartialArts::Styles
3
+ attr_accessor :country, :fighting_focus
4
+ attr_reader :name, :website, :description
5
+ @@all = []
6
+ @@popular = []
7
+ @@missing_info = []
8
+
9
+ def initialize(style, country, fighting_focus, website, description)
10
+ @name = style
11
+ @country = MartialArts::Countries.new(country)
12
+ @fighting_focus = MartialArts::FightingFocus.new(fighting_focus)
13
+ @website = website
14
+ @description = description
15
+
16
+ @country.add_style(self) #every style belongs to a country or fighting_focus
17
+ @fighting_focus.add_style(self)
18
+
19
+ self.class.missing_info << self if country == "N/A" or fighting_focus == "N/A" or description == "N/A"
20
+ end
21
+
22
+ def country_name
23
+ self.country.name
24
+ end
25
+
26
+ def fighting_focus_name
27
+ self.fighting_focus.name
28
+ end
29
+
30
+ def self.all
31
+ @@all
32
+ end
33
+
34
+ def self.popular
35
+ #top 10 list taken from simpatong website; up-to-date, but list is not dynamic
36
+ @@popular
37
+ end
38
+
39
+ def self.styles_list
40
+ self.all.sort {|a,b| a.name <=> b.name }
41
+ end
42
+
43
+ def self.search_by_country(country) #need to setup so that cli is getting from country_instance.styles
44
+ self.styles_list.find_all {|style_instance| style_instance.country_name.strip.include? "#{country}" }
45
+ end
46
+
47
+ def self.search_by_focus(focus) #need to setup so that cli is getting from fighting_focus_instance.styles
48
+ self.styles_list.find_all {|style_instance| style_instance.fighting_focus_name.strip.include? "#{focus}" }
49
+ end
50
+
51
+ def self.duplicates?(style)
52
+ self.all.detect {|style_instance| style_instance.name == style}
53
+ end
54
+
55
+ def self.missing_info
56
+ #use missing_info array to make corrections to retrieve it via the scraper's correct errors method
57
+ @@missing_info
58
+ end
59
+
60
+ end
@@ -0,0 +1,3 @@
1
+ module MartialArts
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,38 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "martial_arts/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "martial_arts"
8
+ spec.version = MartialArts::VERSION
9
+ spec.authors = ["Joseph Jimenez"]
10
+ spec.email = ["blackbeltdiaries@gmail.com"]
11
+
12
+ spec.summary = "provides info for a martial art's style."
13
+ spec.homepage = "https://github.com/MonksAndNinjas/martial-arts-cli-app.git"
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"] = "https://rubygems.org"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against " \
22
+ "public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.16"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "pry"
35
+ spec.add_development_dependency "colorize"
36
+
37
+ spec.add_dependency "nokogiri"
38
+ end
data/notes.md ADDED
@@ -0,0 +1,18 @@
1
+ MartialArtsCLI will be a command-line app to allow users to search for the 10 most popular martial arts in the world. When the app is run, the user will be greeted, and asked to enter a number corresponding to a prompt. The available prompts will be ‘Top 10 list’, ‘Martial Arts by country’, ‘Martial Arts Styles’, ‘Fighting-focus’, and ‘quit’ program.
2
+
3
+ When they choose ‘Top 10 list’ the user will see a list of popular martial arts styles that are scraped from Google’s list at the top of the page, using ‘popular martial arts in the world’ as the search keyword. User will then enter the corresponding number to receive more information about the style selected. Information about the style will include name, country, focus, and description. This information will be scraped from Wikipedia's list of martial arts page and www.singpatong-sitnumnoi.com. Otherwise, user can enter ‘back’ to go back to the main menu.
4
+
5
+ When they choose ‘Martial Arts by Country’ the user will see a numbered list of countries and receive a prompt asking to enter a number corresponding to the country and it’s martial arts’ styles. Otherwise, user can enter ‘back’ to go back to the main menu.
6
+
7
+ When they choose ‘Martial Art Styles’ the user will see a numbered list of styles and receive a prompt asking to enter a number corresponding to the style. Otherwise, user can enter ‘back’ to go back to the main menu.
8
+
9
+ When they choose ‘Martial Art Focus’ the user will see a numbered list corresponding to 1. Striking 2. Grappling 3. Weaponry 4. Meditation. The user will then be asked to enter a number returning a list of martial arts styles that correspond to the method of attack. Otherwise, user can enter ‘back’ to go back to the main menu.
10
+
11
+ For the architecture, we’ll have the following:
12
+ Class MartialArts to represent each style
13
+ Class Focus to represent each fighting method
14
+ Class Country to represent each countrie’s style
15
+ Class MartialArtsScraper to will be used to create the styles
16
+
17
+
18
+ The first version of the app, the user will see the greeting and receive the list of the top 10 martial arts in the world, it’s info as well as search info for different styles.
data/spec.md ADDED
@@ -0,0 +1,32 @@
1
+ # Specifications for the CLI Assessment
2
+
3
+ Specs:
4
+ - [x] Have a CLI for interfacing with the application
5
+
6
+ bin/martial-arts-console requires lib/martial_arts.rb, which serves as the environment and talks to
7
+ lib/martial_arts/cli.rb where the user can interface with the application. From cli.rb the various instance methods displays its menu
8
+ options based on user input and returns the request waiting for further instructions which will involve entering commands to
9
+ display info, lists, go back, or again require user input.
10
+
11
+ - [x] Pull data from an external source
12
+
13
+ For this CLI the information is pulled from http://www.singpatong-sitnumnoi.com/10-most-popular-martial-arts/ for the most popular
14
+ list.
15
+ https://en.wikipedia.org/wiki/List_of_martial_arts for names of all known martial arts and its country.
16
+ and
17
+ https://en.wikipedia.org/- style name - for more informaiton about the style.
18
+
19
+ - [x] Implement both list and detail views
20
+
21
+ Lists:
22
+ - Popular martial arts
23
+ - Countries with martial arts
24
+ - All styles
25
+ - Fighting_Focus
26
+
27
+ Detail Views:
28
+ - Style name
29
+ - Country
30
+ - Fighting_Focus
31
+ - Description
32
+ - Wiki website
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: martial_arts
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Joseph Jimenez
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-06-07 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: colorize
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: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
85
+ - blackbeltdiaries@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - CODE_OF_CONDUCT.md
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - bin/console
97
+ - bin/martial-arts-console
98
+ - bin/setup
99
+ - lib/martial_arts.rb
100
+ - lib/martial_arts/cli.rb
101
+ - lib/martial_arts/countries.rb
102
+ - lib/martial_arts/fighting_focus.rb
103
+ - lib/martial_arts/scraper.rb
104
+ - lib/martial_arts/styles.rb
105
+ - lib/martial_arts/version.rb
106
+ - martial_arts.gemspec
107
+ - notes.md
108
+ - spec.md
109
+ homepage: https://github.com/MonksAndNinjas/martial-arts-cli-app.git
110
+ licenses:
111
+ - MIT
112
+ metadata:
113
+ allowed_push_host: https://rubygems.org
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubyforge_project:
130
+ rubygems_version: 2.7.7
131
+ signing_key:
132
+ specification_version: 4
133
+ summary: provides info for a martial art's style.
134
+ test_files: []