wordwise 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 +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +47 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +21 -0
- data/NOTES.md +66 -0
- data/README.md +43 -0
- data/Rakefile +11 -0
- data/bin/setup +8 -0
- data/bin/wordwise +5 -0
- data/config/environment.rb +6 -0
- data/lib/cli.rb +218 -0
- data/lib/question.rb +21 -0
- data/lib/scraper.rb +61 -0
- data/lib/wordwise/version.rb +3 -0
- data/lib/wordwise.rb +2 -0
- data/spec.md +6 -0
- data/spec.rb +6 -0
- data/wordwise.gemspec +38 -0
- metadata +109 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 47ae2330eb8cdcdea1de5509a7abe87be602c46b80b0c0dcb5c3988b708c0293
|
4
|
+
data.tar.gz: 977add80942f694b6f1e574ec08e88936b8f867d2f630e34c3e8b56dde01b53d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4d39fa67ae151dfd56912d58e9f175dc44cf83fb0b4c7a581b163f325e3085a17ba281fb08495db65a614649474083b97d885235c5c82d4d4e1ae10121d33d00
|
7
|
+
data.tar.gz: 583934acaf9e92341f7477a79ec740e7a7b27f9e4b79e578f091dd139f05c48fca0c87d2dcb63530de3c1ba3aeb1e3c3fda1ec32795f190b11011271a7ebf88b
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -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 ron.sala@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
data/Gemfile.lock
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
wordwise (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
coderay (1.1.2)
|
10
|
+
diff-lcs (1.3)
|
11
|
+
method_source (0.9.0)
|
12
|
+
mini_portile2 (2.3.0)
|
13
|
+
nokogiri (1.8.2)
|
14
|
+
mini_portile2 (~> 2.3.0)
|
15
|
+
pry (0.11.3)
|
16
|
+
coderay (~> 1.1.0)
|
17
|
+
method_source (~> 0.9.0)
|
18
|
+
rake (10.5.0)
|
19
|
+
require_all (2.0.0)
|
20
|
+
rspec (3.7.0)
|
21
|
+
rspec-core (~> 3.7.0)
|
22
|
+
rspec-expectations (~> 3.7.0)
|
23
|
+
rspec-mocks (~> 3.7.0)
|
24
|
+
rspec-core (3.7.1)
|
25
|
+
rspec-support (~> 3.7.0)
|
26
|
+
rspec-expectations (3.7.0)
|
27
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
+
rspec-support (~> 3.7.0)
|
29
|
+
rspec-mocks (3.7.0)
|
30
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
31
|
+
rspec-support (~> 3.7.0)
|
32
|
+
rspec-support (3.7.1)
|
33
|
+
|
34
|
+
PLATFORMS
|
35
|
+
ruby
|
36
|
+
|
37
|
+
DEPENDENCIES
|
38
|
+
bundler
|
39
|
+
nokogiri
|
40
|
+
pry
|
41
|
+
rake
|
42
|
+
require_all
|
43
|
+
rspec (~> 3.0)
|
44
|
+
wordwise!
|
45
|
+
|
46
|
+
BUNDLED WITH
|
47
|
+
1.16.1
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018 Ron Sala
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 RonSala
|
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/NOTES.md
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
A quiz game. Challenge your vocabulary by choosing the correct definition from a list.
|
2
|
+
|
3
|
+
Ideas for expansion:
|
4
|
+
|
5
|
+
-- 2/multi player mode
|
6
|
+
-- Allowing user to chose among word lists
|
7
|
+
-- Reverse mode (get a definition and choose the word)
|
8
|
+
-- Provide only definitions of same part of speech as word
|
9
|
+
|
10
|
+
**Basic Interface:**
|
11
|
+
|
12
|
+
Welcome to Wordwise! Get ready to test your word wisdom!
|
13
|
+
|
14
|
+
What does #{@word} mean?
|
15
|
+
|
16
|
+
A) definition A
|
17
|
+
B) definition B
|
18
|
+
C) definition C
|
19
|
+
D) definition D
|
20
|
+
|
21
|
+
[User inputs guess.]
|
22
|
+
|
23
|
+
"Correct!" or "Incorrect!". Correct answer: #{fullEntry}"
|
24
|
+
|
25
|
+
"Type a word from the definition to define it, Enter for next question, or Q to quit."
|
26
|
+
|
27
|
+
On Q, user given percent of questions correct.
|
28
|
+
|
29
|
+
Icebox:
|
30
|
+
|
31
|
+
Make word entry url accessible for more info.
|
32
|
+
|
33
|
+
**Potential Enhanced Interface:**
|
34
|
+
|
35
|
+
Welcome to Wordwise! Get ready to test your word wisdom!
|
36
|
+
|
37
|
+
How many players?
|
38
|
+
|
39
|
+
[User inputs int.]
|
40
|
+
|
41
|
+
What's the name of Player 1?
|
42
|
+
|
43
|
+
[User inputs name.
|
44
|
+
|
45
|
+
What's the name of Player 2?
|
46
|
+
|
47
|
+
[So on till all players are named.]
|
48
|
+
|
49
|
+
#{@current_player}, what is #{@word}?
|
50
|
+
|
51
|
+
A) definition A
|
52
|
+
B) definition B
|
53
|
+
C) definition C
|
54
|
+
D) definition D
|
55
|
+
|
56
|
+
[User inputs guess.]
|
57
|
+
|
58
|
+
"Correct" or "Incorrect. Correct answer: #{correctAnswer}"
|
59
|
+
|
60
|
+
[Play goes until each player has had 10 questions and the leader is declared the winner. If no leader, "Name, Name, etc" (players tied for lead), your word wisdom is strong. Now entering Sudden Death Round! The first player, chosen at random, to answer correctly wins!. Random player asked question, etc.]
|
61
|
+
|
62
|
+
Debugging:
|
63
|
+
|
64
|
+
Suggestions from coach (4/21/18):
|
65
|
+
|
66
|
+
Classes using same module can share methods but not instance variables. The latter can be done with inheritance. Could make a bunch of questions at a time and use the sample method. Could give user a "loading..." message. Could use a grab_question method in Scraper. Can use finder methods like earlier in course. Says Question class still useful.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Wordwise
|
2
|
+
|
3
|
+
A quiz game. Challenge your vocabulary! Given a random word, choose the correct definition from a list. Option to see word origin.}
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'wordwise'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install wordwise
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
On starting, WordWise will choose a word and several definitions, one of which is correct. (This process may take a few seconds). Once you've made your choice, type the corresponding number and hit 'enter'. WordWise will tell you if you're correct and, if not, the correct definition. Type 'o' and 'enter' to see the word's origin (etymology) or 'n' and 'enter' for the next question. To exit the game, type 'e' and 'enter'.
|
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/ronsala/wordwise. 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.
|
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 Wordwise project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ronsala/wordwise/blob/master/CODE_OF_CONDUCT.md).
|
42
|
+
=======
|
43
|
+
# wordwise
|
data/Rakefile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require_relative './config/environment'
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
require "rspec/core/rake_task"
|
4
|
+
|
5
|
+
RSpec::Core::RakeTask.new(:spec)
|
6
|
+
|
7
|
+
task :default => :spec
|
8
|
+
|
9
|
+
task :console do #Calling this throws 'rake aborted! LoadError: cannot load such file -- nokogiri'
|
10
|
+
Pry.start
|
11
|
+
end
|
data/bin/setup
ADDED
data/bin/wordwise
ADDED
data/lib/cli.rb
ADDED
@@ -0,0 +1,218 @@
|
|
1
|
+
# Implements interface for user.
|
2
|
+
class Wordwise::CLI
|
3
|
+
WIDTH = 80
|
4
|
+
|
5
|
+
# Display welcome message.
|
6
|
+
def introduction
|
7
|
+
puts ''
|
8
|
+
puts "WELCOME TO WORDWISE!\n".center(80)
|
9
|
+
puts "You can learn more about the words in this quiz at https://www.oxforddictionaries.com.\n\n".center(80)
|
10
|
+
puts "Get ready to test your word wisdom....\n\n".center(80)
|
11
|
+
puts "What category would you like to test your knowledge on?\n"
|
12
|
+
display_lists
|
13
|
+
end
|
14
|
+
|
15
|
+
# Presents list of categories.
|
16
|
+
def display_lists
|
17
|
+
puts ''
|
18
|
+
Wordwise::Scraper.scrape_word_lists.each_with_index do |l, i|
|
19
|
+
puts wrap_indent("#{i + 1}) #{l}")
|
20
|
+
puts ''
|
21
|
+
end
|
22
|
+
ask_list
|
23
|
+
end
|
24
|
+
|
25
|
+
# Wraps strings to format them prettily within the default page width.
|
26
|
+
def wrap(str)
|
27
|
+
str.gsub(/(.{1,#{WIDTH}})(\s+|\Z)/, "\\1\n")
|
28
|
+
end
|
29
|
+
|
30
|
+
# As #wrap, with a five space left indent.
|
31
|
+
def wrap_indent(str)
|
32
|
+
str.gsub(/(.{1,#{WIDTH}})(\s+|\Z)/, " \\1\n")
|
33
|
+
end
|
34
|
+
|
35
|
+
# Asks user for category selection.
|
36
|
+
def ask_list
|
37
|
+
puts "Please enter the number of the category you want:"
|
38
|
+
input = gets.strip.to_i
|
39
|
+
size = Wordwise::Scraper.scrape_word_lists.size
|
40
|
+
if input.between?(1, size)
|
41
|
+
@words_defs_ary = Wordwise::Scraper.scrape_word_list(input - 1)
|
42
|
+
check_remaining
|
43
|
+
else
|
44
|
+
ask_list
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# Checks if there are enough unused words and definitions to form question.
|
49
|
+
# Minumum size is set at 5 because sample method in #sample_words_defs
|
50
|
+
# is not called on first item in array.
|
51
|
+
def check_remaining
|
52
|
+
if @words_defs_ary.size >= 5
|
53
|
+
sample_words_defs
|
54
|
+
else
|
55
|
+
ask_c_or_e
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def sample_words_defs
|
60
|
+
# Samples starting at index 1 of array to avoid any column headings.
|
61
|
+
@question_words_defs = @words_defs_ary[1..@words_defs_ary.size - 1].sample(4)
|
62
|
+
# Prevents repetition of words in questions.
|
63
|
+
# @words_defs_ary.delete_if { |wd| wd == @question_words_defs[0] }
|
64
|
+
set_question_words
|
65
|
+
end
|
66
|
+
|
67
|
+
# Iterates over array of words and definitions to make separate array of words.
|
68
|
+
def set_question_words
|
69
|
+
@@question_words = []
|
70
|
+
@question_words_defs.each_index do |i|
|
71
|
+
@@question_words << @question_words_defs[i][0]
|
72
|
+
end
|
73
|
+
set_question_defs
|
74
|
+
end
|
75
|
+
|
76
|
+
# Iterates over array of words and definitions to make separate array of
|
77
|
+
# definitions.
|
78
|
+
def set_question_defs
|
79
|
+
@@question_defs = []
|
80
|
+
@question_words_defs.each_index do |i|
|
81
|
+
@@question_defs << @question_words_defs[i][1]
|
82
|
+
end
|
83
|
+
play
|
84
|
+
end
|
85
|
+
|
86
|
+
# Displays question and asks for answer.
|
87
|
+
def play
|
88
|
+
puts "\nLoading question...\n\n"
|
89
|
+
@question = Wordwise::Question.new
|
90
|
+
display_question
|
91
|
+
ask_no
|
92
|
+
end
|
93
|
+
|
94
|
+
def self.get_question_words
|
95
|
+
@@question_words
|
96
|
+
end
|
97
|
+
|
98
|
+
def self.get_question_array
|
99
|
+
origin = Wordwise::Scraper.scrape_entry_pages
|
100
|
+
# Array is return value to be used in Question.
|
101
|
+
[@@question_words, @@question_defs, origin]
|
102
|
+
end
|
103
|
+
|
104
|
+
# Presents a question to the user.
|
105
|
+
def display_question
|
106
|
+
puts "\nWhat does '#{@question.word}' mean?\n\n"
|
107
|
+
(0..3).each do |i|
|
108
|
+
puts wrap_indent("#{i + 1}) #{@question.defs[i]}")
|
109
|
+
puts ''
|
110
|
+
end
|
111
|
+
@words_defs_ary.delete_if { |wd| wd == @question_words_defs[0] }
|
112
|
+
end
|
113
|
+
|
114
|
+
# Get definition number from user.
|
115
|
+
def ask_no
|
116
|
+
puts 'Please enter a number 1-4:'
|
117
|
+
input = gets.strip
|
118
|
+
case input
|
119
|
+
when '1'
|
120
|
+
@question.defs[0] == @question.def ? correct : incorrect
|
121
|
+
when '2'
|
122
|
+
@question.defs[1] == @question.def ? correct : incorrect
|
123
|
+
when '3'
|
124
|
+
@question.defs[2] == @question.def ? correct : incorrect
|
125
|
+
when '4'
|
126
|
+
@question.defs[3] == @question.def ? correct : incorrect
|
127
|
+
else
|
128
|
+
ask_no
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
# Tell user they answered correctly and ask how they want to proceed.
|
133
|
+
def correct
|
134
|
+
puts "\nCORRECT!"
|
135
|
+
ask_letter
|
136
|
+
end
|
137
|
+
|
138
|
+
# Tells user they answered incorrectly, gives correct answer, and asks how to
|
139
|
+
# proceed.
|
140
|
+
def incorrect
|
141
|
+
puts "\nINCORRECT.\n\n"
|
142
|
+
puts 'CORRECT ANSWER:'
|
143
|
+
puts wrap_indent("'#{@question.def}'")
|
144
|
+
ask_letter
|
145
|
+
end
|
146
|
+
|
147
|
+
# Display menu after user has answered a question.
|
148
|
+
def ask_letter
|
149
|
+
puts "\nWord origin: 'o'. Next question: 'n'. Change category: 'c'. Exit: 'e'.\n"
|
150
|
+
case_letter
|
151
|
+
end
|
152
|
+
|
153
|
+
# Initiates action based on user input.
|
154
|
+
def case_letter
|
155
|
+
input = gets.strip.downcase
|
156
|
+
case input
|
157
|
+
when 'o'
|
158
|
+
puts "\n#{@question.origin}\n\n"
|
159
|
+
ask_n_c_or_e
|
160
|
+
when 'n'
|
161
|
+
check_remaining
|
162
|
+
when 'c'
|
163
|
+
display_lists
|
164
|
+
when 'e'
|
165
|
+
goodbye
|
166
|
+
else
|
167
|
+
ask_letter
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
# Displays menu after origin has been displayed.
|
172
|
+
def ask_n_c_or_e
|
173
|
+
puts "Next question: 'n'. Change category: 'c'. Exit game: 'e'\n"
|
174
|
+
case_letter
|
175
|
+
end
|
176
|
+
|
177
|
+
# Tells user questions are exhausted in category and gives options.
|
178
|
+
def ask_c_or_e
|
179
|
+
puts 'Sorry, no more questions available in category.'
|
180
|
+
puts "Change category: 'c'. Exit: 'e'.\n"
|
181
|
+
case_letter
|
182
|
+
end
|
183
|
+
|
184
|
+
def goodbye
|
185
|
+
puts wrap("\nThanks for playing WordWise! Would you like to review the words and definitions from your session?")
|
186
|
+
puts ''
|
187
|
+
case_y_n
|
188
|
+
end
|
189
|
+
|
190
|
+
# Bids user farewell and end play.
|
191
|
+
def case_y_n
|
192
|
+
puts "Yes: 'y'. No: 'n'.\n"
|
193
|
+
input = gets.strip.downcase
|
194
|
+
case input
|
195
|
+
when 'y'
|
196
|
+
display_review
|
197
|
+
when 'n'
|
198
|
+
exit
|
199
|
+
else
|
200
|
+
case_y_n
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
def display_review
|
205
|
+
Wordwise::Question.all.each_index do |i|
|
206
|
+
question = Wordwise::Question.all[i]
|
207
|
+
puts "\n'#{question.word}':"
|
208
|
+
puts wrap_indent("#{question.def.capitalize}.")
|
209
|
+
puts wrap_indent("Origin: #{question.origin}")
|
210
|
+
end
|
211
|
+
puts ''
|
212
|
+
exit
|
213
|
+
end
|
214
|
+
|
215
|
+
def exit
|
216
|
+
puts "\nPlease come again!\n\n"
|
217
|
+
end
|
218
|
+
end
|
data/lib/question.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# Assemble a question consisting of a word and its definition shuffled with 3
|
2
|
+
# other definitions.
|
3
|
+
class Wordwise::Question
|
4
|
+
attr_reader :word, :def, :defs, :origin
|
5
|
+
|
6
|
+
@@all = []
|
7
|
+
|
8
|
+
# Set instance variables for Question objects.
|
9
|
+
def initialize
|
10
|
+
question_array = Wordwise::CLI.get_question_array
|
11
|
+
@word = question_array[0][0]
|
12
|
+
@def = question_array[1][0]
|
13
|
+
@defs = question_array[1].shuffle
|
14
|
+
@origin = question_array[2]
|
15
|
+
@@all << self
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.all
|
19
|
+
@@all
|
20
|
+
end
|
21
|
+
end
|
data/lib/scraper.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# Scrapes web page containing word and the individual pages with their
|
2
|
+
# definitions.
|
3
|
+
class Wordwise::Scraper
|
4
|
+
|
5
|
+
BASEPATH = 'https://en.oxforddictionaries.com'
|
6
|
+
|
7
|
+
# Scrapes page with list of word lists.
|
8
|
+
def self.scrape_word_lists
|
9
|
+
html = Nokogiri::HTML(open(BASEPATH + '/explore/word-lists'))
|
10
|
+
@list_urls, lists = [], []
|
11
|
+
# Populates arrays of word list names and urls.
|
12
|
+
(0..html.css('.record').size - 1).each do |i|
|
13
|
+
@list_urls << BASEPATH + html.css('.record a')[i].attribute('href').value
|
14
|
+
lists << html.css('.record h2')[i].text
|
15
|
+
end
|
16
|
+
|
17
|
+
# Removes list not fitting format.
|
18
|
+
@list_urls.delete_if { |u| u =~ /phobias/ }
|
19
|
+
lists.delete_if { |l| l =~ /phobias/ }
|
20
|
+
lists
|
21
|
+
end
|
22
|
+
|
23
|
+
# Scrapes a page with a word list.
|
24
|
+
def self.scrape_word_list(page_idx)
|
25
|
+
doc = Nokogiri::HTML(open(@list_urls[page_idx]))
|
26
|
+
@words_defs = {}
|
27
|
+
|
28
|
+
# Creates hash of word-definition pairs.
|
29
|
+
(0..doc.css('tr').length - 1).each do |i|
|
30
|
+
@words_defs.store(doc.css('tr')[i].css('td')[0].text, doc.css('tr')[i].css('td')[1].text)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Removes invalid entries
|
34
|
+
@words_defs.delete('')
|
35
|
+
@words_defs.delete_if { |w| w =~ /\W/ || w =~ /xylene/ || w =~ /do/ }
|
36
|
+
|
37
|
+
# Converts hash to array for use in .scrape_entry_pages.
|
38
|
+
@words_defs_ary = @words_defs.to_a
|
39
|
+
end
|
40
|
+
|
41
|
+
# Samples 4 urls to words' pages and parses the question word, its origin and
|
42
|
+
# definition, and 3 more definitions.
|
43
|
+
def self.scrape_entry_pages
|
44
|
+
docs, word_urls = [], []
|
45
|
+
question_words = Wordwise::CLI.get_question_words
|
46
|
+
# Iterates over array to make array of urls that are parsed by Nokogiri
|
47
|
+
# and put in another array.
|
48
|
+
question_words.each_index do |i|
|
49
|
+
word_urls << "#{BASEPATH}/definition/#{question_words[i]}"
|
50
|
+
docs << Nokogiri::HTML(open(word_urls[i]))
|
51
|
+
end
|
52
|
+
|
53
|
+
# Sets variable for word origin.
|
54
|
+
origin_wrapper = docs[0].css('.senseInnerWrapper p')[-1]
|
55
|
+
if origin_wrapper
|
56
|
+
origin = origin_wrapper.text
|
57
|
+
else
|
58
|
+
origin = 'Origin not available.'
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/lib/wordwise.rb
ADDED
data/spec.md
ADDED
data/spec.rb
ADDED
data/wordwise.gemspec
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "wordwise/version"
|
4
|
+
require 'open-uri'
|
5
|
+
require 'pry'
|
6
|
+
require 'nokogiri'
|
7
|
+
|
8
|
+
Gem::Specification.new do |spec|
|
9
|
+
spec.name = "wordwise"
|
10
|
+
spec.version = Wordwise::VERSION
|
11
|
+
spec.authors = ["RonSala"]
|
12
|
+
spec.email = ["ron.sala@gmail.com"]
|
13
|
+
|
14
|
+
spec.summary = %q{A quiz game. Challenge your vocabulary!}
|
15
|
+
spec.description = %q{Given a random word, choose the correct definition from a list. Option to see word origin.}
|
16
|
+
spec.homepage = "https://github.com/ronsala/wordwise"
|
17
|
+
spec.license = "MIT"
|
18
|
+
|
19
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
20
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
21
|
+
# if spec.respond_to?(:metadata)
|
22
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
23
|
+
# else
|
24
|
+
# raise "RubyGems 2.0 or newer is required to protect against " \
|
25
|
+
# "public gem pushes."
|
26
|
+
# end
|
27
|
+
|
28
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
29
|
+
f.match(%r{^(test|spec|features)/})
|
30
|
+
end
|
31
|
+
spec.bindir = "exe"
|
32
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
33
|
+
spec.require_paths = ["lib"]
|
34
|
+
|
35
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
36
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
37
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wordwise
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- RonSala
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-05-06 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
|
+
description: Given a random word, choose the correct definition from a list. Option
|
56
|
+
to see word origin.
|
57
|
+
email:
|
58
|
+
- ron.sala@gmail.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- ".travis.yml"
|
66
|
+
- CODE_OF_CONDUCT.md
|
67
|
+
- Gemfile
|
68
|
+
- Gemfile.lock
|
69
|
+
- LICENSE
|
70
|
+
- LICENSE.txt
|
71
|
+
- NOTES.md
|
72
|
+
- README.md
|
73
|
+
- Rakefile
|
74
|
+
- bin/setup
|
75
|
+
- bin/wordwise
|
76
|
+
- config/environment.rb
|
77
|
+
- lib/cli.rb
|
78
|
+
- lib/question.rb
|
79
|
+
- lib/scraper.rb
|
80
|
+
- lib/wordwise.rb
|
81
|
+
- lib/wordwise/version.rb
|
82
|
+
- spec.md
|
83
|
+
- spec.rb
|
84
|
+
- wordwise.gemspec
|
85
|
+
homepage: https://github.com/ronsala/wordwise
|
86
|
+
licenses:
|
87
|
+
- MIT
|
88
|
+
metadata: {}
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
requirements: []
|
104
|
+
rubyforge_project:
|
105
|
+
rubygems_version: 2.7.6
|
106
|
+
signing_key:
|
107
|
+
specification_version: 4
|
108
|
+
summary: A quiz game. Challenge your vocabulary!
|
109
|
+
test_files: []
|