dictionary_search 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/.DS_Store +0 -0
- data/.github/FUNDING.yml +12 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/.vscode/launch.json +14 -0
- data/3clear +0 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +45 -0
- data/LICENSE.txt +21 -0
- data/README.md +56 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/dictionary +3 -0
- data/bin/setup +6 -0
- data/dictionary.gemspec +36 -0
- data/lib/dictionary/cli.rb +134 -0
- data/lib/dictionary/scraper.rb +44 -0
- data/lib/dictionary/version.rb +3 -0
- data/lib/dictionary/word.rb +77 -0
- data/lib/dictionary.rb +7 -0
- metadata +138 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 96eaa16074866b1de1250ac5c415535326fb19a157ecaad18ee42dd0798670f8
|
4
|
+
data.tar.gz: 12f8ac26e1a72ca40d340a5231896d9d3b51fed9ec16938b01270235a1c1ff00
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9a301d6604d76f3f0897afaeb5c22e85d59de30dee750df9e0b6a4f50dc2fbd1a1632f3ad0a74d1cb5bd391cdf821b0a1fbe6ae5e40947edd27cca3a59d425a9
|
7
|
+
data.tar.gz: bf07604c64f1302698f1a38e8fc72d32403d771c92172e608ee266891df493aa1e34a2fff7bd8f4fc5acdc0a4c98c33090db62e4b413812b634bca10c6091571
|
data/.DS_Store
ADDED
Binary file
|
data/.github/FUNDING.yml
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# These are supported funding model platforms
|
2
|
+
|
3
|
+
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
4
|
+
patreon: # Replace with a single Patreon username
|
5
|
+
open_collective: # Replace with a single Open Collective username
|
6
|
+
ko_fi: # Replace with a single Ko-fi username
|
7
|
+
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
8
|
+
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
9
|
+
liberapay: # Replace with a single Liberapay username
|
10
|
+
issuehunt: # Replace with a single IssueHunt username
|
11
|
+
otechie: # Replace with a single Otechie username
|
12
|
+
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/.vscode/launch.json
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
{
|
2
|
+
// Use IntelliSense to learn about possible attributes.
|
3
|
+
// Hover to view descriptions of existing attributes.
|
4
|
+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
5
|
+
"version": "0.2.0",
|
6
|
+
"configurations": [
|
7
|
+
{
|
8
|
+
"name": "Debug Local File",
|
9
|
+
"type": "Ruby",
|
10
|
+
"request": "launch",
|
11
|
+
"program": "${workspaceRoot}/main.rb"
|
12
|
+
}
|
13
|
+
]
|
14
|
+
}
|
data/3clear
ADDED
File without changes
|
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 freddy.silber@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,45 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
dictionary (0.1.0)
|
5
|
+
colorize
|
6
|
+
nokogiri
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
colorize (0.8.1)
|
12
|
+
diff-lcs (1.3)
|
13
|
+
mini_portile2 (2.5.1)
|
14
|
+
nokogiri (1.11.5)
|
15
|
+
mini_portile2 (~> 2.5.0)
|
16
|
+
racc (~> 1.4)
|
17
|
+
racc (1.5.2)
|
18
|
+
rake (13.0.1)
|
19
|
+
rspec (3.9.0)
|
20
|
+
rspec-core (~> 3.9.0)
|
21
|
+
rspec-expectations (~> 3.9.0)
|
22
|
+
rspec-mocks (~> 3.9.0)
|
23
|
+
rspec-core (3.9.2)
|
24
|
+
rspec-support (~> 3.9.3)
|
25
|
+
rspec-expectations (3.9.1)
|
26
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
27
|
+
rspec-support (~> 3.9.0)
|
28
|
+
rspec-mocks (3.9.1)
|
29
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
30
|
+
rspec-support (~> 3.9.0)
|
31
|
+
rspec-support (3.9.3)
|
32
|
+
|
33
|
+
PLATFORMS
|
34
|
+
ruby
|
35
|
+
|
36
|
+
DEPENDENCIES
|
37
|
+
bundler (~> 2.0)
|
38
|
+
colorize
|
39
|
+
dictionary!
|
40
|
+
nokogiri
|
41
|
+
rake (~> 13.0)
|
42
|
+
rspec (~> 3.0)
|
43
|
+
|
44
|
+
BUNDLED WITH
|
45
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Freddy Silber
|
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,56 @@
|
|
1
|
+
# Dictionary CLI
|
2
|
+
A Merriam-Webster Dictionary Gem for getting the word of the day and searching definitions for words
|
3
|
+
## CLI Data Gem Portfolio Project
|
4
|
+
|
5
|
+
- Dictionary CLI Gem
|
6
|
+
- Ruby CLI Data Gem Portfolio Project
|
7
|
+
- Freddy Silber
|
8
|
+
- Summer 19'
|
9
|
+
|
10
|
+
## Walkthrough
|
11
|
+
|
12
|
+
-- YouTube: https://www.youtube.com/watch?v=h1DsQGNnf6k&feature=youtu.be
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
|
16
|
+
1. Fork and Clone this repo to your desktop
|
17
|
+
2. 'cd' to the folder
|
18
|
+
3. Run './bin/dictionary'. If you get an error, try running 'bundle install' first
|
19
|
+
4. Learn a word.. or two
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
gem 'dictionary'
|
23
|
+
or in a new terminal window...
|
24
|
+
$ git clone https://github.com/YOUR-USERNAME/DICTIONARY-CLI-FOLDER
|
25
|
+
```
|
26
|
+
|
27
|
+
And then execute:
|
28
|
+
|
29
|
+
$ bundle
|
30
|
+
|
31
|
+
Or install it yourself as:
|
32
|
+
|
33
|
+
$ gem install dictionary
|
34
|
+
|
35
|
+
## How To Use
|
36
|
+
|
37
|
+
Search in the command line for a word and recieve its definition as well as the Word of the Day! After forking this repo and getting the gem installed, open a new terminal window and 'cd' to the /dictionary-cli folder you just cloned.
|
38
|
+
When inside the folder, run './bin/dictionary' in the command prompt.
|
39
|
+
|
40
|
+
<!-- ## Development
|
41
|
+
|
42
|
+
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.
|
43
|
+
|
44
|
+
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). -->
|
45
|
+
|
46
|
+
## Contributing
|
47
|
+
|
48
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/dictionary. 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.
|
49
|
+
|
50
|
+
## License
|
51
|
+
|
52
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
53
|
+
|
54
|
+
## Code of Conduct
|
55
|
+
|
56
|
+
Everyone interacting in the Dictionary project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/dictionary/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# require "bundler/setup"
|
4
|
+
# require "dictionary"
|
5
|
+
require './lib/dictionary'
|
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__)
|
data/bin/dictionary
ADDED
data/bin/setup
ADDED
data/dictionary.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "dictionary/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "dictionary_search"
|
7
|
+
spec.version = Dictionary::VERSION
|
8
|
+
spec.authors = ["Freddy Silber"]
|
9
|
+
spec.email = ["freddy.silber@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = %q{summary.}
|
12
|
+
spec.description = %q{dictionary cli.}
|
13
|
+
spec.homepage = "https://github.com/freddysilber/dictionary-cli"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org/"
|
17
|
+
|
18
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
19
|
+
spec.metadata["source_code_uri"] = "https://github.com/freddysilber/dictionary-cli"
|
20
|
+
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
25
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
end
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
32
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
33
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
34
|
+
spec.add_dependency "nokogiri"
|
35
|
+
spec.add_dependency "colorize"
|
36
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
# CLI Controller
|
2
|
+
class Dictionary::CLI
|
3
|
+
def call
|
4
|
+
welcome_message
|
5
|
+
get_todays_word
|
6
|
+
show_word_of_the_day
|
7
|
+
get_user_input
|
8
|
+
find_word
|
9
|
+
show_searched_word
|
10
|
+
search_again?
|
11
|
+
end
|
12
|
+
|
13
|
+
def welcome_message
|
14
|
+
puts "\n----------------------------------------------------------------".cyan
|
15
|
+
puts
|
16
|
+
puts "\tWelcome to Merriam Webster online Dictionary!".colorize(:light_magenta)
|
17
|
+
puts
|
18
|
+
puts "\tDate: #{Date.today}".colorize(:light_yellow)
|
19
|
+
puts
|
20
|
+
puts "\tThe word of the day is:".colorize(:light_yellow)
|
21
|
+
end
|
22
|
+
|
23
|
+
def get_todays_word
|
24
|
+
w = Dictionary::Word.todays_word
|
25
|
+
@word_of_the_day = w
|
26
|
+
if @word_of_the_day == nil || @word_of_the_day == []
|
27
|
+
word = Dictionary::Scraper.get_word_of_day
|
28
|
+
w = Dictionary::Word.new_word_of_the_day(word)
|
29
|
+
@word_of_the_day = w
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def show_word_of_the_day
|
34
|
+
puts "\n-- Word: #{@word_of_the_day.word_name.capitalize.colorize(:light_green)}"
|
35
|
+
puts "---- Part of Speech: #{@word_of_the_day.part_of_speech.capitalize.colorize(:light_green)}"
|
36
|
+
puts "---- Pronounciation: '#{@word_of_the_day.pronounciation.colorize(:light_green)}'"
|
37
|
+
puts "---- Definition: #{@word_of_the_day.definition.colorize(:light_green)}"
|
38
|
+
puts "\n----------------------------------------------------------------".cyan
|
39
|
+
end
|
40
|
+
|
41
|
+
def get_user_input
|
42
|
+
exit_input = "exit".colorize(:light_red)
|
43
|
+
puts "\n-- Search for a word or type '#{exit_input}' . . ."
|
44
|
+
puts
|
45
|
+
input = gets.downcase.strip
|
46
|
+
puts
|
47
|
+
if input == "exit"
|
48
|
+
@exit = true
|
49
|
+
return "See you later!"
|
50
|
+
else
|
51
|
+
yes = "Y".colorize(:light_green)
|
52
|
+
no = "N".colorize(:red)
|
53
|
+
puts "-- The word you searched is #{input.upcase.colorize(:light_yellow)}. Is that correct? (#{yes}/#{no})"
|
54
|
+
puts
|
55
|
+
confirmation = gets.downcase.strip
|
56
|
+
if confirmation == "N" || confirmation == "n" || confirmation == "no" || confirmation == "NO"
|
57
|
+
get_user_input
|
58
|
+
else
|
59
|
+
@word_to_search = input
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def find_word
|
65
|
+
if @exit != true
|
66
|
+
search = @word_to_search.downcase
|
67
|
+
@searched = Dictionary::Word.find_a_word(search.downcase)
|
68
|
+
if @searched == nil || @searched == []
|
69
|
+
word = Dictionary::Scraper.search_for_word(search)
|
70
|
+
if word != nil
|
71
|
+
w = Dictionary::Word.new_word_from_search(word)
|
72
|
+
@searched = w
|
73
|
+
else
|
74
|
+
puts "Sorry we couldn't find the word you searched. Please try again or change spelling.".red
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def show_searched_word
|
81
|
+
if @exit != true && @searched != nil
|
82
|
+
counter = 1
|
83
|
+
formatted = []
|
84
|
+
sections = @searched.definition.split(":")
|
85
|
+
sections.delete_if(&:empty?)
|
86
|
+
puts "\n----------------------------------------------------------------".cyan
|
87
|
+
puts "\n-- Word: #{@searched.word_name.capitalize.colorize(:light_green)}"
|
88
|
+
puts "---- Part of Speech: #{@searched.part_of_speech.capitalize.colorize(:light_green)}"
|
89
|
+
puts "---- Pronounciation: '#{@searched.pronounciation.colorize(:light_green)}'"
|
90
|
+
puts "---- Definition:"
|
91
|
+
puts
|
92
|
+
for i in sections do
|
93
|
+
sec = i.split
|
94
|
+
first_word = sec[0].capitalize
|
95
|
+
sec.shift
|
96
|
+
sec.unshift(first_word)
|
97
|
+
s = sec.join(" ")
|
98
|
+
formatted << s
|
99
|
+
end
|
100
|
+
formatted.each {|f|
|
101
|
+
puts "\t" + "\t#{counter}. #{f}".colorize(:light_green)
|
102
|
+
puts
|
103
|
+
counter += 1
|
104
|
+
}
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def search_again?
|
109
|
+
if @exit != true
|
110
|
+
yes = "Y".colorize(:light_green)
|
111
|
+
no = "N".colorize(:red)
|
112
|
+
puts "----------------------------------------------------------------".cyan
|
113
|
+
puts "\n--- Would you like to search for another word? (#{yes}/#{no})"
|
114
|
+
puts
|
115
|
+
input = gets.strip
|
116
|
+
if input == "N" || input == "n" || input == "NO" || input == "no"
|
117
|
+
puts
|
118
|
+
goodbye_message
|
119
|
+
puts
|
120
|
+
else
|
121
|
+
self.call
|
122
|
+
end
|
123
|
+
else
|
124
|
+
goodbye_message
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def goodbye_message
|
129
|
+
puts "----------------------------------------------------------------".cyan
|
130
|
+
puts "See you later!".colorize(:light_yellow)
|
131
|
+
puts "----------------------------------------------------------------".cyan
|
132
|
+
puts
|
133
|
+
end
|
134
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
class Dictionary::Scraper
|
2
|
+
|
3
|
+
@@exception_count = 0
|
4
|
+
|
5
|
+
def self.get_word_of_day
|
6
|
+
word_of_the_day = {}
|
7
|
+
doc = Nokogiri::HTML(open("https://www.merriam-webster.com/word-of-the-day"))
|
8
|
+
wordname = doc.css('.word-header .word-and-pronunciation h2').text
|
9
|
+
partofspeech = doc.css('.main-attr').text
|
10
|
+
pronounciation = doc.css('.word-syllables').text
|
11
|
+
definition = doc.css('.wod-definition-container p')[0].text
|
12
|
+
word_of_the_day[:word_name] = wordname
|
13
|
+
word_of_the_day[:part_of_speech] = partofspeech
|
14
|
+
word_of_the_day[:pronounciation] = pronounciation
|
15
|
+
word_of_the_day[:definition]= definition
|
16
|
+
word_of_the_day[:date] = Date.today
|
17
|
+
word_of_the_day[:word_type] = "daily"
|
18
|
+
word_of_the_day
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.search_for_word(word)
|
22
|
+
word_searched = {}
|
23
|
+
begin
|
24
|
+
doc = Nokogiri::HTML(open("https://www.merriam-webster.com/dictionary/#{word}"))
|
25
|
+
|
26
|
+
wordname = doc.css('.hword')[0].text
|
27
|
+
partofspeech = doc.css('.parts-of-speech a')[0].text
|
28
|
+
pronounciation = doc.css('.play-pron-v2')[0].text
|
29
|
+
word_definition = doc.css('.dtText').text
|
30
|
+
definition = word_definition.to_s.gsub("\n", "")
|
31
|
+
|
32
|
+
word_searched[:word_name] = wordname
|
33
|
+
word_searched[:part_of_speech] = partofspeech
|
34
|
+
word_searched[:pronounciation] = pronounciation
|
35
|
+
word_searched[:definition] = definition
|
36
|
+
word_searched[:word_type] = "search"
|
37
|
+
rescue StandardError => e
|
38
|
+
word_searched = nil
|
39
|
+
# puts e
|
40
|
+
@@exception_count += 1
|
41
|
+
end
|
42
|
+
word_searched
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
class Dictionary::Word
|
2
|
+
|
3
|
+
attr_accessor :date, :word_name, :part_of_speech, :definition, :pronounciation, :word_type
|
4
|
+
|
5
|
+
@@all = []
|
6
|
+
|
7
|
+
def initialize(word_name = nil, date = nil, part_of_speech = nil, definition= nil, pronounciation = nil, word_type = nil)
|
8
|
+
@word_name = word_name
|
9
|
+
@date = date
|
10
|
+
@part_of_speech = part_of_speech
|
11
|
+
@pronounciation = pronounciation
|
12
|
+
@definition = definition
|
13
|
+
@word_type = word_type
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.new_word_of_the_day(hash)
|
17
|
+
word = self.new
|
18
|
+
word.word_name = hash[:word_name]
|
19
|
+
word.date = hash[:date]
|
20
|
+
word.part_of_speech = hash[:part_of_speech]
|
21
|
+
word.definition = hash[:definition]
|
22
|
+
word.pronounciation = hash[:pronounciation]
|
23
|
+
word.word_type = hash[:word_type]
|
24
|
+
@@all << word
|
25
|
+
word
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.new_word_from_search(hash)
|
29
|
+
word = self.new
|
30
|
+
word.word_name = hash[:word_name]
|
31
|
+
word.date = hash[:date]
|
32
|
+
word.part_of_speech = hash[:part_of_speech]
|
33
|
+
word.definition = hash[:definition]
|
34
|
+
word.pronounciation = hash[:pronounciation]
|
35
|
+
word.word_type = hash[:word_type]
|
36
|
+
@@all << word
|
37
|
+
word
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.all
|
41
|
+
@@all
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.words_of_the_day
|
45
|
+
words = []
|
46
|
+
@@all.each do |w|
|
47
|
+
if w.word_type == "daily"
|
48
|
+
words << w
|
49
|
+
end
|
50
|
+
end
|
51
|
+
words
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.searched_words
|
55
|
+
searched_words = []
|
56
|
+
@@all.each do |w|
|
57
|
+
if w.word_type == "search"
|
58
|
+
searched_words << w
|
59
|
+
end
|
60
|
+
end
|
61
|
+
searched_words
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.todays_word
|
65
|
+
@@all.detect {|w| w.date == Date.today}
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.find_a_word(search)
|
69
|
+
@@all.detect do |w|
|
70
|
+
if w.word_name == search
|
71
|
+
w
|
72
|
+
else
|
73
|
+
nil
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
data/lib/dictionary.rb
ADDED
metadata
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dictionary_search
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Freddy Silber
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-06-19 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: '13.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '13.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: nokogiri
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
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: colorize
|
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: dictionary cli.
|
84
|
+
email:
|
85
|
+
- freddy.silber@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".DS_Store"
|
91
|
+
- ".github/FUNDING.yml"
|
92
|
+
- ".gitignore"
|
93
|
+
- ".rspec"
|
94
|
+
- ".travis.yml"
|
95
|
+
- ".vscode/launch.json"
|
96
|
+
- 3clear
|
97
|
+
- CODE_OF_CONDUCT.md
|
98
|
+
- Gemfile
|
99
|
+
- Gemfile.lock
|
100
|
+
- LICENSE.txt
|
101
|
+
- README.md
|
102
|
+
- Rakefile
|
103
|
+
- bin/console
|
104
|
+
- bin/dictionary
|
105
|
+
- bin/setup
|
106
|
+
- dictionary.gemspec
|
107
|
+
- lib/dictionary.rb
|
108
|
+
- lib/dictionary/cli.rb
|
109
|
+
- lib/dictionary/scraper.rb
|
110
|
+
- lib/dictionary/version.rb
|
111
|
+
- lib/dictionary/word.rb
|
112
|
+
homepage: https://github.com/freddysilber/dictionary-cli
|
113
|
+
licenses:
|
114
|
+
- MIT
|
115
|
+
metadata:
|
116
|
+
allowed_push_host: https://rubygems.org/
|
117
|
+
homepage_uri: https://github.com/freddysilber/dictionary-cli
|
118
|
+
source_code_uri: https://github.com/freddysilber/dictionary-cli
|
119
|
+
post_install_message:
|
120
|
+
rdoc_options: []
|
121
|
+
require_paths:
|
122
|
+
- lib
|
123
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
requirements: []
|
134
|
+
rubygems_version: 3.0.3.1
|
135
|
+
signing_key:
|
136
|
+
specification_version: 4
|
137
|
+
summary: summary.
|
138
|
+
test_files: []
|