meaning 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 +9 -0
- data/Gemfile +9 -0
- data/LICENSE.txt +21 -0
- data/README.md +32 -0
- data/Rakefile +2 -0
- data/bin/meaning +49 -0
- data/imgs/factotum.png +0 -0
- data/lib/meaning/version.rb +3 -0
- data/lib/meaning.rb +65 -0
- data/meaning.gemspec +29 -0
- metadata +125 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8c6dd854170dee07cda5d32546365c24038cfb42
|
4
|
+
data.tar.gz: 29a05f7bba0df458499be733ea12266d3f8f442e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a7875d687fa6ded6a87874670df6da2f4e70fe539848e6b0b407c8531c27ad832e4a823592a58421f14c3d94d4c72b983035aff9d55ed6309b4f667b4d3ef43f
|
7
|
+
data.tar.gz: 6fe1f1c7fb0c84bdb961504e08554d7b99699a3bbf35befd21aae4314565c1d7fe38784a9b4084cfb6a52181ef870d8f927062454d077c59e0925be0c977c668
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 n
|
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,32 @@
|
|
1
|
+
# Meaning [](https://badge.fury.io/rb/meaning)
|
2
|
+
|
3
|
+
English Dictionary(CLI and API) based on dictionary.cambridge.org
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'meaning'
|
11
|
+
```
|
12
|
+
Or install it yourself as:
|
13
|
+
|
14
|
+
```bash
|
15
|
+
$ gem install meaning
|
16
|
+
```
|
17
|
+
## Usage
|
18
|
+
API:
|
19
|
+
```ruby
|
20
|
+
word = Meaning::MeaningLab.new "word"
|
21
|
+
word.dictionary
|
22
|
+
```
|
23
|
+
CLI:
|
24
|
+
```bash
|
25
|
+
$ meaning of Factotum
|
26
|
+
```
|
27
|
+

|
28
|
+
|
29
|
+
## License
|
30
|
+
|
31
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
32
|
+
|
data/Rakefile
ADDED
data/bin/meaning
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require_relative '../lib/meaning.rb'
|
4
|
+
Dependencies = ['open-uri','thor','nokogiri','rainbow/ext/string']
|
5
|
+
Dependencies.each {|dependency| require dependency}
|
6
|
+
|
7
|
+
module Meaning
|
8
|
+
class Base < Thor
|
9
|
+
|
10
|
+
desc 'of',"Getting description of a WORD in english"
|
11
|
+
def of word
|
12
|
+
meaning = MeaningLab.new word
|
13
|
+
error = meaning.dictionary[:error]
|
14
|
+
error.nil? ? colorize(meaning.dictionary) : puts("(#{word.capitalize.underline.red}): #{error.color(:red)}.")
|
15
|
+
end
|
16
|
+
|
17
|
+
desc 'help',"Full Description of how both the CLi and the API work"
|
18
|
+
def help
|
19
|
+
puts <<EOH
|
20
|
+
Meaning is a open source CLI and API dictionary Based on http://dictionary.cambridge.org/ site.
|
21
|
+
|
22
|
+
to use the CLI,open your terminal and type:
|
23
|
+
#{"meaning of Ruby".color(:green)}
|
24
|
+
|
25
|
+
to use the gem as an API:
|
26
|
+
#{"word = Meaning::MeaningLab.new('ruby')".color(:green)}
|
27
|
+
#{"word.dictioanry".color(:green)}
|
28
|
+
|
29
|
+
Disclaimer: This gem has no direct or indirect relation to http://dictionary.cambridge.org/
|
30
|
+
EOH
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
def colorize text
|
35
|
+
word = text[:word].color(:yellow).underline
|
36
|
+
sound = text[:sound].color(:yellow)
|
37
|
+
definitions = text[:definitions]
|
38
|
+
examples = text[:examples]
|
39
|
+
|
40
|
+
puts "\n(#{word}) [#{sound}]"
|
41
|
+
puts "\n\n Definitions:".color(:green)
|
42
|
+
definitions.each {|dev| puts "- #{dev}\n".color(:green)}
|
43
|
+
puts "\n\n Examples:".color(:orange)
|
44
|
+
examples.each {|eg| puts "- #{eg}\n".color(:orange)}
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
Meaning::Base.start ARGV
|
data/imgs/factotum.png
ADDED
Binary file
|
data/lib/meaning.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
require_relative "meaning/version"
|
2
|
+
module Meaning
|
3
|
+
class MeaningLab
|
4
|
+
attr_reader :dictionary
|
5
|
+
def initialize word
|
6
|
+
word = word.dup.capitalize
|
7
|
+
@dictionary = {word: word}
|
8
|
+
define
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
def define
|
13
|
+
unless status? == "404 Not Found"
|
14
|
+
sound
|
15
|
+
fetch_for("definitions",".def")
|
16
|
+
fetch_for("examples",".eg")
|
17
|
+
else
|
18
|
+
@dictionary[:error] = "Not even a word!"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def sound
|
23
|
+
@dictionary[:sound] = sanatize(@doc.css(".pos-header").first.text)
|
24
|
+
end
|
25
|
+
|
26
|
+
def sanatize text
|
27
|
+
text.gsub!(/(\t)+|(\n)+|\s{2,}|\/+|#{word.capitalize}|#{word.downcase}/,"")
|
28
|
+
end
|
29
|
+
|
30
|
+
def word
|
31
|
+
dictionary[:word]
|
32
|
+
end
|
33
|
+
|
34
|
+
def fetch_for name,css_class
|
35
|
+
elements = []
|
36
|
+
@doc.css(css_class).each do |element|
|
37
|
+
elements << sanatize_from_colon(element.text)
|
38
|
+
end
|
39
|
+
@dictionary[name.to_sym] = elements
|
40
|
+
end
|
41
|
+
def sanatize_from_colon text
|
42
|
+
text.gsub!(":",".")
|
43
|
+
text
|
44
|
+
end
|
45
|
+
def status?
|
46
|
+
begin
|
47
|
+
load_page
|
48
|
+
"Ok"
|
49
|
+
rescue OpenURI::HTTPError => e
|
50
|
+
e.message
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def load_page
|
55
|
+
@doc ||= Nokogiri::HTML(file)
|
56
|
+
end
|
57
|
+
|
58
|
+
def file
|
59
|
+
open(api)
|
60
|
+
end
|
61
|
+
def api
|
62
|
+
"http://dictionary.cambridge.org/dictionary/english/#{dictionary[:word].downcase}"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/meaning.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'meaning/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "meaning"
|
8
|
+
spec.version = Meaning::VERSION
|
9
|
+
spec.authors = ["Khaled0Fares"]
|
10
|
+
spec.email = ["kfares29@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{English Dictionary(CLI and API) based on dictionary.cambridge.org}
|
13
|
+
spec.description = %q{English Dictionary(CLI and API) based on dictionary.cambridge.org site}
|
14
|
+
spec.homepage = "https://github.com/khaledmohammedfares/meaning"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
spec.bindir = "bin"
|
20
|
+
spec.executables = ['meaning'] #spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_runtime_dependency "thor"
|
26
|
+
spec.add_runtime_dependency "nokogiri"
|
27
|
+
spec.add_runtime_dependency "rainbow"
|
28
|
+
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: meaning
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Khaled0Fares
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-03 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.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
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: thor
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
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: 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: rainbow
|
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: English Dictionary(CLI and API) based on dictionary.cambridge.org site
|
84
|
+
email:
|
85
|
+
- kfares29@gmail.com
|
86
|
+
executables:
|
87
|
+
- meaning
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- bin/meaning
|
97
|
+
- imgs/factotum.png
|
98
|
+
- lib/meaning.rb
|
99
|
+
- lib/meaning/version.rb
|
100
|
+
- meaning.gemspec
|
101
|
+
homepage: https://github.com/khaledmohammedfares/meaning
|
102
|
+
licenses:
|
103
|
+
- MIT
|
104
|
+
metadata: {}
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
requirements: []
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 2.5.1
|
122
|
+
signing_key:
|
123
|
+
specification_version: 4
|
124
|
+
summary: English Dictionary(CLI and API) based on dictionary.cambridge.org
|
125
|
+
test_files: []
|