words_and_idioms 0.1.3 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8cda497bcc77f6b57044188c08363b3bd9215677
4
- data.tar.gz: cabf7a700a9686c2a184afa1ad2a639e29119afb
3
+ metadata.gz: dcbf9e27a70c940bf2100fb99ea950dee1c7127e
4
+ data.tar.gz: a3d27ed5c1674d8d5a1f962b1d61995c7008502c
5
5
  SHA512:
6
- metadata.gz: 672352b070859b154429c11ae68ee4fbfff01a0d06f1523ebe3544e55a0270b1903499694558c519f604921918aff58f1c9990ec9cd3ccb2ecde99614ab22df2
7
- data.tar.gz: 992f3b4e65debd11c1a072f8592c83fc30316d1c398bd9f2e10e7fceadc7559c804766354cb6bb559fb49dea20838a1eb0b656fcf951dda61c8606c719ca2d7d
6
+ metadata.gz: 627df717b3550526f722f8857d84d7712c6efae6261878577cd30265707c9988aa1cfb19e7e9804f4b57df009f2cdc65d27934ebd97951d3d710562bc0397f51
7
+ data.tar.gz: 7b35f32f607aa22aa9bcf8f987ecf875685b132a26258d9542e8537ebddbda879f5d317a3d1d48caa2c638146c47f2c57ef68b67e1b09fc18286bcda8c4c450f
File without changes
@@ -1,5 +1,3 @@
1
- require 'colorize'
2
-
3
1
  class WordsAndIdioms::CLI
4
2
 
5
3
  def call
@@ -26,7 +24,8 @@ def menu
26
24
  DictionaryScraper.new
27
25
  greet_user
28
26
  elsif first_choice == 2
29
- IdiomExplorer.idiom_routine
27
+ IdiomScraper.constructor
28
+ IdiomExplorer.print_list
30
29
  greet_user
31
30
  elsif first_choice != 1 && first_choice != 2 && first_choice != 3
32
31
  puts " "
@@ -1,66 +1,54 @@
1
- require 'open-uri'
2
- require 'nokogiri'
3
- require 'colorize'
4
1
  class DictionaryScraper
5
2
 
6
3
  attr_accessor :user_input
7
4
 
8
5
  @@word = ""
9
6
  @@definition = ""
7
+ @@correct_spelling = nil
10
8
 
11
9
  def initialize
12
10
  begin
13
- @@word = UserInput.get_word
11
+ @@word = @@correct_spelling || UserInput.get_word
14
12
  word_url = "http://www.dictionary.com/browse/#{@@word}"
15
13
  html = open(word_url)
16
- doc = Nokogiri::HTML(html)
17
-
14
+ @@doc = Nokogiri::HTML(html)
18
15
  rescue OpenURI::HTTPError
19
- DictionaryScraper.check_spelling
20
-
16
+ check_spelling
21
17
  else
22
- definition_xml = doc.css(".def-content")[0].text
23
- definition_init_parse = definition_xml.split("\r\n")
24
- @@definition = definition_init_parse[1].delete("\n").strip
25
- puts " "
26
- puts " "
27
- puts "According to dictionary.com #{@@word} means:".green
28
- puts "#{@@definition}"
29
- puts " "
30
- puts " "
18
+ print_definition
31
19
  end
32
20
  end
33
21
 
34
- def self.check_spelling
22
+ def print_definition
23
+ definition_xml = @@doc.css(".def-content")[0].text
24
+ definition_init_parse = definition_xml.split("\r\n")
25
+ @@definition = definition_init_parse[1].delete("\n").strip
26
+ puts " "
27
+ puts "According to dictionary.com #{@@word} means:".green
28
+ puts "#{@@definition}"
29
+ puts " "
30
+ @@correct_spelling = nil
31
+ end
32
+
33
+ def check_spelling
35
34
  begin
36
35
  check_url = "http://www.macmillandictionary.com/spellcheck/british/?q=#{@@word}"
37
36
  check_html = open(check_url)
38
37
  check_doc = Nokogiri::HTML(check_html)
39
- @correct_spelling = check_doc.css("#search-results")[1].children.children[1].children.children.text
40
- rescue NoMethodError
41
- puts "Hmmm... That's a tough one. I can't find that one anywhere. Maybe you can add it to the open dictionary!".red
42
- puts " "
43
- puts " "
44
- else
45
- puts "Hmmm... I can't find that one in the dictionary. Did you mean #{@correct_spelling.upcase}?".yellow
38
+ @@correct_spelling = check_doc.css("#search-results")[1].children.children[1].children.children.text
39
+ rescue NoMethodError
40
+ puts "Hmmm... That's a tough one. I can't find that one anywhere. Maybe you can add it to the open dictionary!".red
41
+ puts " "
42
+ else
43
+ puts "Hmmm... I can't find that one in the dictionary. Did you mean #{@@correct_spelling.upcase}?".yellow
46
44
  puts "Y/N?:"
47
- if gets.chomp == "Y"
48
- @correct_word = @correct_spelling
49
- corrected_url = "http://www.dictionary.com/browse/#{@correct_word}"
50
- corrected_html = open(corrected_url)
51
- corrected_doc = Nokogiri::HTML(corrected_html)
52
- corrected_definition_xml = corrected_doc.css(".def-content")[0].text
53
- corrected_definition_init_parse = corrected_definition_xml.split("\r\n")
54
- @corrected_definition = corrected_definition_init_parse[1].delete("\n").strip
55
- puts "According to dictionary.com #{@correct_word} means:".green
56
- puts "#{@corrected_definition}"
57
- else
58
- puts " "
59
- puts " "
60
- puts "Well, then. Perhaps we can try again.".green
61
- puts " "
62
- puts " "
63
- end
45
+ if gets.chomp.downcase == "y"
46
+ DictionaryScraper.new
47
+ else
48
+ puts " "
49
+ puts "Well, then. Perhaps we can try again.".green
50
+ puts " "
51
+ end
64
52
  end
65
53
  end
66
54
 
@@ -1,63 +1,31 @@
1
- require 'open-uri'
2
- require 'nokogiri'
3
- require 'colorize'
4
-
5
1
  class IdiomExplorer
6
- @@word_url = "http://www.macmillandictionary.com/us/open-dictionary/latestEntries.html"
7
- @@html = open(@@word_url)
8
- @@doc = Nokogiri::HTML(@@html)
9
- @@all = []
10
-
11
2
 
12
- def self.usage
13
- @usage_array = []
14
- counter = 0
15
- @@doc.css(" #openEntries .openEntry .openSense").each do |entry|
16
- if @@doc.css(" #openEntries .openEntry .openSense")[counter].children[2] != nil
17
- @usage_array << @@doc.css(" #openEntries .openEntry .openSense")[counter].children[1].text
18
- else
19
- @usage_array << "Looks like nobody's put an example sentence up yet. Maybe you could submit one!"
20
- end
21
- counter +=1
22
- end
23
- @usage_array
3
+ def self.print_list
4
+ puts "Below is a list of newly created idioms from MacMillan's Open Dictionary Project"
5
+ IdiomScraper.all.each.with_index(1) do |idiom, i|
6
+ puts "#{i}. #{idiom}"
24
7
  end
8
+ show_idiom
9
+ end
25
10
 
26
- def self.idiom_routine
27
- IdiomList.new
28
- counter = 1
29
- IdiomList.all.each do |hash|
30
- hash.each do |k,v|
31
- puts "#{counter}. #{k}"
32
- counter += 1
33
- end
34
- end
35
- puts " "
11
+ def show_idiom
36
12
  puts "Which idiom would you like me to define?"
37
13
  puts " "
38
- input = (gets.chomp).to_i
14
+ input = ((gets.chomp).to_i - 1)
39
15
  puts " "
40
16
  puts "Interesting choice. Here is the definition:".magenta
41
17
  puts " "
42
- hash_value = IdiomList.all[input - 1]
43
- hash_idiom = hash_value.keys[0]
44
- hash_def = hash_value[hash_idiom]
45
- puts "#{hash_idiom.upcase.yellow}: #{hash_def}"
46
- puts " "
18
+ puts IdiomScraper.all[input].name.upcase.yellow": " IdiomScraper.all[input].definition
47
19
  puts " "
48
20
  puts "Would you like to see this word in context?".light_blue
49
21
  puts "Y/N"
50
22
 
51
23
  context = gets.chomp.downcase
52
24
  if context == "y"
53
- self.usage
54
- puts " "
55
- puts " "
56
- puts @usage_array[input - 1].green
57
25
  puts " "
26
+ puts IdiomScraper.all[input].usage].green
58
27
  puts " "
59
28
  end
60
29
  end
61
30
 
62
-
63
31
  end
@@ -0,0 +1,40 @@
1
+ class IdiomScraper
2
+ @@url = "http://www.macmillandictionary.com/us/open-dictionary/latestEntries.html"
3
+ @@html = open(@@url)
4
+ @@doc = Nokogiri::HTML(@@html)
5
+
6
+ @@all = []
7
+
8
+ attr_accessor :name, :definition, :usage
9
+
10
+ def initialize(name, definition, usage)
11
+ @name = name
12
+ @definition = definition
13
+ @usage = usage
14
+ self.save
15
+ end
16
+
17
+ def self.constructor
18
+ counter = 0
19
+ @@doc.search(".openEntry").each do |node|
20
+ name = @@doc.search(".openEntry")[counter].css("a").text
21
+ definition = @@doc.search(".openEntry")[counter].css(".openDef").text
22
+ if @@doc.search(".openEntry")[counter].css(".openEx").text != ""
23
+ usage = @@doc.search(".openEntry")[counter].css(".openEx").text
24
+ elsif @@doc.search(".openEntry")[counter].css(".openEx").text == ""
25
+ usage = "It looks like nobody has submitted a sentence yet. Maybe you could write one!"
26
+ end
27
+ IdiomScraper.new(name, definition, usage)
28
+ counter += 1
29
+ end
30
+ end
31
+
32
+ def save
33
+ @@all << self
34
+ end
35
+
36
+ def all
37
+ @@all
38
+ end
39
+
40
+ end
@@ -1,3 +1,3 @@
1
1
  module WordsAndIdioms
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -0,0 +1,43 @@
1
+ class IdiomExplorer
2
+
3
+ def initialize
4
+
5
+ end
6
+ def self.idiom_routine
7
+ IdiomList.new
8
+ counter = 1
9
+ IdiomList.all.each do |hash|
10
+ hash.each do |k,v|
11
+ puts "#{counter}. #{k}"
12
+ counter += 1
13
+ end
14
+ end
15
+ puts " "
16
+ puts "Which idiom would you like me to define?"
17
+ puts " "
18
+ input = (gets.chomp).to_i
19
+ puts " "
20
+ puts "Interesting choice. Here is the definition:".magenta
21
+ puts " "
22
+ hash_value = IdiomList.all[input - 1]
23
+ hash_idiom = hash_value.keys[0]
24
+ hash_def = hash_value[hash_idiom]
25
+ puts "#{hash_idiom.upcase.yellow}: #{hash_def}"
26
+ puts " "
27
+ puts " "
28
+ puts "Would you like to see this word in context?".light_blue
29
+ puts "Y/N"
30
+
31
+ context = gets.chomp.downcase
32
+ if context == "y"
33
+ self.usage
34
+ puts " "
35
+ puts " "
36
+ puts @usage_array[input - 1].green
37
+ puts " "
38
+ puts " "
39
+ end
40
+ end
41
+
42
+
43
+ end
@@ -1,6 +1,3 @@
1
- require 'open-uri'
2
- require 'nokogiri'
3
-
4
1
  class IdiomList
5
2
 
6
3
  @@word_url = "http://www.macmillandictionary.com/us/open-dictionary/latestEntries.html"
@@ -1,6 +1,11 @@
1
+ require 'colorize'
2
+ require 'nokogiri'
3
+ require 'pry'
4
+ require 'open-uri'
5
+
1
6
  require_relative "./words_and_idioms/version"
2
7
  require_relative './words_and_idioms/cli'
3
8
  require_relative './words_and_idioms/dictionary_scraper'
4
9
  require_relative './words_and_idioms/idiom_explorer'
5
- require_relative './words_and_idioms/idioms'
10
+ require_relative './words_and_idioms/idiom_scraper'
6
11
  require_relative './words_and_idioms/user_input'
@@ -34,7 +34,7 @@ Gem::Specification.new do |spec|
34
34
  spec.add_development_dependency "rake", "~> 10.0"
35
35
  spec.add_development_dependency "rspec", "~> 3.0"
36
36
  spec.add_development_dependency "pry"
37
+ spec.add_development_dependency "nokogiri"
38
+ spec.add_development_dependency "colorize"
37
39
 
38
- spec.add_dependency "colorize"
39
- spec.add_dependency 'nokogiri'
40
40
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: words_and_idioms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - skmcloughlin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-07-04 00:00:00.000000000 Z
11
+ date: 2017-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -67,13 +67,13 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: colorize
70
+ name: nokogiri
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
- type: :runtime
76
+ type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
@@ -81,13 +81,13 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: nokogiri
84
+ name: colorize
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
- type: :runtime
90
+ type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
@@ -113,14 +113,16 @@ files:
113
113
  - Rakefile
114
114
  - bin/console
115
115
  - bin/setup
116
- - bin/words_and_idioms.rb
116
+ - bin/words_and_idioms
117
117
  - lib/words_and_idioms.rb
118
118
  - lib/words_and_idioms/cli.rb
119
119
  - lib/words_and_idioms/dictionary_scraper.rb
120
120
  - lib/words_and_idioms/idiom_explorer.rb
121
- - lib/words_and_idioms/idioms.rb
121
+ - lib/words_and_idioms/idiom_scraper.rb
122
122
  - lib/words_and_idioms/user_input.rb
123
123
  - lib/words_and_idioms/version.rb
124
+ - lib/words_and_idioms/zz - idiom_explorer_old.rb
125
+ - lib/words_and_idioms/zz - idioms.rb
124
126
  - words_and_idioms.gemspec
125
127
  homepage: https://github.com/skmcloughlin/WordsAndIdiomsGem
126
128
  licenses: