babbel_explorer 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 16b07657b36fb2c3ca753237b3ebe9ee225144cca4638d7d9b2ef06e07d8866a
4
+ data.tar.gz: 199058f903dd4888f7ef6142d1bd88f0c7d391d77ee7e75ee83b731822e1325c
5
+ SHA512:
6
+ metadata.gz: 152df90f8254b37f4389b503741c385494ff6a64b9975793585efca62ae9484d281d1e35258f1ace92e5155724f0b01ee7b54cacde53ecef2b533b8ff87937dc
7
+ data.tar.gz: b193236c1d413b60b372327a77b19a10c3dd9d84023a95edf70d70a491bed0778587bb3794cf8951c91c91b2ae63c5ff6c1552601e8d8a24479a7d31c1a79587
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ .DS_Store
@@ -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 abrolon87@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 [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in babbel_explorer.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
@@ -0,0 +1,47 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ babbel_explorer (0.1.0)
5
+ nokogiri
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ coderay (1.1.2)
11
+ colorize (0.8.1)
12
+ diff-lcs (1.3)
13
+ method_source (0.9.2)
14
+ mini_portile2 (2.4.0)
15
+ nokogiri (1.10.8)
16
+ mini_portile2 (~> 2.4.0)
17
+ pry (0.12.2)
18
+ coderay (~> 1.1.0)
19
+ method_source (~> 0.9.0)
20
+ rake (12.3.3)
21
+ rspec (3.9.0)
22
+ rspec-core (~> 3.9.0)
23
+ rspec-expectations (~> 3.9.0)
24
+ rspec-mocks (~> 3.9.0)
25
+ rspec-core (3.9.1)
26
+ rspec-support (~> 3.9.1)
27
+ rspec-expectations (3.9.0)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.9.0)
30
+ rspec-mocks (3.9.1)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.9.0)
33
+ rspec-support (3.9.2)
34
+
35
+ PLATFORMS
36
+ ruby
37
+
38
+ DEPENDENCIES
39
+ babbel_explorer!
40
+ bundler (~> 2.0)
41
+ colorize
42
+ pry
43
+ rake (~> 12.0)
44
+ rspec (~> 3.0)
45
+
46
+ BUNDLED WITH
47
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 abrolon87
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.
@@ -0,0 +1,73 @@
1
+ A CLI app that shows a list of countries and users can choose a country to see the languages spoken in that country.
2
+
3
+ Flow
4
+ User types babbel_explorer
5
+
6
+ Display list of countries
7
+
8
+ "Choose a country by its corresponding number"
9
+
10
+ user sees languages spoken in chosen country
11
+ <!-- countries.each.with_index do |country, i|
12
+ puts "#{i}. #{country}
13
+ -->
14
+
15
+ Classes
16
+ country
17
+ region(?maybe in a later version?)
18
+ scraper
19
+
20
+ site = "https://www.cia.gov/library/publications/the-world-factbook/fields/402.html"
21
+ #THIS WORKS!
22
+ page = Nokogiri::HTML(open(site))
23
+ countries = page.css("table#fieldListing tr")
24
+ scraped_countries = []
25
+
26
+ countries.each do |c|
27
+ country_name = c.css("td.country").text.strip
28
+ lang = c.css("div.category_data.subfield.text").text
29
+
30
+ puts country_name
31
+ puts lang
32
+
33
+ end
34
+
35
+
36
+ Refactoring cli.rb
37
+
38
+ get_countries
39
+ country_list
40
+ get_selection
41
+ explore_more
42
+
43
+
44
+ skteches:
45
+
46
+ create into hash?
47
+ {:name => "name", :language => "language"}
48
+
49
+ check for valid input
50
+ <!-- def valid_input(input, data)
51
+ input.to_i <= data.length && input.to_i > 0
52
+ end -->
53
+
54
+ # def get_countries
55
+ # countries = BabbelExplorer::Scraper.scrape_countries
56
+ # countries.shift
57
+ # if BabbelExplorer::Country.all.empty?
58
+ # countries.each do |country|
59
+ # BabbelExplorer::Country.new(country[:name], country[:language])
60
+ # end
61
+ # end
62
+ # #@countries = BabbelExplorer::Country.all
63
+ # end
64
+
65
+ # def explore
66
+ # input = ""
67
+ # until input == "exit"
68
+ # get_countries
69
+ # country_list
70
+ # get_selection
71
+ # end #i want a confirmation message to the user before exiting
72
+ # exit
73
+ # end
@@ -0,0 +1,41 @@
1
+ # BabbelExplorer
2
+
3
+ Welcome to Babbel Explorer! This Ruby gem is for people who are interested in exploring the langauges of the world. The user can choose a country and view the language data of that country.
4
+
5
+ The gem will later be updated to be able to explore by region and by language.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'babbel_explorer'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install babbel_explorer
22
+
23
+ ## Usage
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ 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).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/abrolon87/babbel_explorer_cli_gem. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/abrolon87/babbel_explorer_cli_gem/blob/master/CODE_OF_CONDUCT.md).
34
+
35
+ ## License
36
+
37
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
38
+
39
+ ## Code of Conduct
40
+
41
+ Everyone interacting in the BabbelExplorer project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/abrolon87/babbel_explorer_cli_gem/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,36 @@
1
+ require_relative 'lib/babbel_explorer/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "babbel_explorer"
5
+ spec.version = BabbelExplorer::VERSION
6
+ spec.authors = ["abrolon87"]
7
+ spec.email = ["abrolon87@gmail.com"]
8
+
9
+ spec.summary = %q{Languages by Country Gem}
10
+ #spec.description = %q{TODO: Write a longer description or delete this line.}
11
+ spec.homepage = "https://github.com/abrolon87/babbel_explorer_cli_gem"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = spec.homepage
19
+ #spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = 'exe'
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+
31
+ spec.add_development_dependency "bundler", "~> 2.0"
32
+ spec.add_development_dependency "rake", "~> 12.3.3"
33
+ spec.add_development_dependency "pry"
34
+ spec.add_development_dependency "colorize"
35
+ spec.add_dependency "nokogiri"
36
+ end
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+
4
+ require './lib/environment'
5
+
6
+
7
+ BabbelExplorer::CLI.new.call
8
+
9
+
10
+
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "babbel_explorer"
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,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,100 @@
1
+ # CLI controller
2
+ class BabbelExplorer::CLI
3
+
4
+ def call
5
+ puts "\nWelcome to Babbel Explorer!\n".cyan.bold
6
+ menu
7
+ end
8
+
9
+ def menu
10
+ puts "\nTo view country list, type 'explore'\n".green
11
+ puts "Type 'exit' to exit.".green
12
+ input = gets.strip
13
+ case input.downcase
14
+ when "explore"
15
+ explore
16
+ when "exit"
17
+ exit
18
+ else
19
+ invalid_input
20
+ end
21
+ end
22
+
23
+ def explore
24
+ #input = ""
25
+ #unless input == "q"
26
+ get_countries
27
+ country_list
28
+ get_selection
29
+ #end
30
+ explore_more
31
+ end
32
+
33
+ def get_countries
34
+ BabbelExplorer::Scraper.scrape_countries if BabbelExplorer::Country.all.empty?
35
+ end
36
+
37
+ def country_list
38
+ puts "\nChoose a country by its corresponding number or type 'q' to quit".yellow.bold
39
+ puts "\nScroll down to view countries\n".yellow
40
+ puts "\n"
41
+
42
+ BabbelExplorer::Country.all.each_with_index do |country, index|
43
+ if index == 0
44
+ nil
45
+ else
46
+ puts "#{index}. #{country.name}".yellow
47
+ end
48
+ end
49
+ puts "\nScroll up to view countries\n".yellow
50
+ end
51
+
52
+ def get_selection
53
+ chosen_country = gets.strip
54
+ max_countries = BabbelExplorer::Country.all.length - 1
55
+
56
+ if chosen_country.to_i == 238
57
+ puts "\nThere are more than 7,000 languages spoken in the world. Try selecting a specific country:\n".red
58
+ get_selection
59
+ elsif chosen_country.to_i > 0 && chosen_country.to_i <= max_countries
60
+ chosen_country = chosen_country.to_i
61
+ show_lang_blurb(chosen_country)
62
+ elsif chosen_country == 'q'
63
+ explore_more
64
+ else
65
+ puts "Invalid command! Please try again.".red.bold
66
+ get_selection
67
+ end
68
+ end
69
+
70
+ def invalid_input
71
+ puts "\nInvalid Command!".red.bold
72
+ puts "Please try again\n".red
73
+ menu
74
+ end
75
+
76
+ def show_lang_blurb(chosen_country)
77
+ countries = BabbelExplorer::Country.all
78
+ country = countries[chosen_country]
79
+ puts "\nLanguages spoken in #{country.name}:".magenta.bold
80
+ puts "#{country.language}".magenta
81
+ puts "Select another country from the list or type 'q' to quit.".yellow
82
+ get_selection
83
+ end
84
+
85
+ def explore_more
86
+ puts "All done exploring for now? Hit any key to view country list again or type 'exit' to exit.".red
87
+ input = gets.strip.downcase
88
+ if input == 'exit'
89
+ exit
90
+ else
91
+ explore
92
+ end
93
+ end
94
+
95
+ def exit
96
+ puts "\nThank you for using Babbel Explorer!\n".cyan.bold
97
+ abort
98
+ end
99
+
100
+ end
@@ -0,0 +1,16 @@
1
+ class BabbelExplorer::Country
2
+ attr_reader :name, :language
3
+
4
+ @@all = []
5
+
6
+ def initialize(name, language)
7
+ @name = name
8
+ @language = language
9
+ @@all << self
10
+ end
11
+
12
+ def self.all
13
+ @@all
14
+ end
15
+
16
+ end
@@ -0,0 +1,19 @@
1
+ class BabbelExplorer::Scraper
2
+
3
+ def self.scrape_countries
4
+ doc = Nokogiri::HTML(open("https://www.cia.gov/library/publications/the-world-factbook/fields/402.html"))
5
+
6
+ countries = doc.css("table#fieldListing tr")
7
+
8
+ countries.each do |country|
9
+ name = country.css("td.country").text.strip
10
+ language = country.css("div.category_data.subfield.text").text
11
+
12
+ BabbelExplorer::Country.new(name, language)
13
+ end
14
+ end
15
+ end
16
+
17
+
18
+
19
+
@@ -0,0 +1,3 @@
1
+ module BabbelExplorer
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,16 @@
1
+ # This is my environment
2
+ require 'open-uri'
3
+ require 'nokogiri'
4
+ require 'pry'
5
+ require 'colorize'
6
+
7
+ require_relative './babbel_explorer/version'
8
+ require_relative './babbel_explorer/cli'
9
+ require_relative './babbel_explorer/country'
10
+ require_relative './babbel_explorer/scraper'
11
+
12
+
13
+ module BabbelExplorer
14
+ class Error < StandardError; end
15
+ # Your code goes here...
16
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: babbel_explorer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - abrolon87
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-09-09 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: 12.3.3
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 12.3.3
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
+ - abrolon87@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - CODE_OF_CONDUCT.md
92
+ - Gemfile
93
+ - Gemfile.lock
94
+ - LICENSE.txt
95
+ - NOTES.md
96
+ - README.md
97
+ - Rakefile
98
+ - babbel_explorer.gemspec
99
+ - bin/babbel_explorer
100
+ - bin/console
101
+ - bin/setup
102
+ - lib/babbel_explorer/cli.rb
103
+ - lib/babbel_explorer/country.rb
104
+ - lib/babbel_explorer/scraper.rb
105
+ - lib/babbel_explorer/version.rb
106
+ - lib/environment.rb
107
+ homepage: https://github.com/abrolon87/babbel_explorer_cli_gem
108
+ licenses:
109
+ - MIT
110
+ metadata:
111
+ allowed_push_host: https://rubygems.org
112
+ homepage_uri: https://github.com/abrolon87/babbel_explorer_cli_gem
113
+ source_code_uri: https://github.com/abrolon87/babbel_explorer_cli_gem
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: 2.3.0
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubygems_version: 3.0.8
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: Languages by Country Gem
133
+ test_files: []