thes 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +89 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/thes +20 -0
- data/lib/thes.rb +49 -0
- data/lib/thes/version.rb +3 -0
- data/thes.gemspec +31 -0
- metadata +156 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5ccb456a1a284e80e2d9c63b54118927e3409cb2
|
4
|
+
data.tar.gz: 6ea025b3be44b702a6ab9fdca5bb8af9b4dfa59e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f397a8777c20fd1a2c28f4e5b1c9194cbaaa9619b90d3385b393270e61a6ee3d98a345167178c8540ff2561cdbbd3a9242505a806622a1b5cef42d498dc639d0
|
7
|
+
data.tar.gz: 067c9085b475f2d57a1d1626ba3e95fedf884b494e671fee455b9a96462fbd6fb4348feee4633f759d19e23878ea61268054e648bbc4c8be4db2120c883978e2
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Rob Watson
|
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,89 @@
|
|
1
|
+
# thes
|
2
|
+
|
3
|
+
A simple utility to provide access to [thesaurus.com](http://www.thesaurus.com) from the command line.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
`gem install thes`
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
`thes <some word>`
|
12
|
+
|
13
|
+
For example:
|
14
|
+
|
15
|
+
`thes nature`
|
16
|
+
|
17
|
+
Result:
|
18
|
+
|
19
|
+
```
|
20
|
+
+--------------------------+-------------------------+-------------------------+
|
21
|
+
| noun: character, disposition |
|
22
|
+
+--------------------------+-------------------------+-------------------------+
|
23
|
+
| description | attributes | bottom line |
|
24
|
+
| essence | being | name of game |
|
25
|
+
| humor | complexion | name of tune |
|
26
|
+
| mood | constitution | nature of beast |
|
27
|
+
| personality | drift | |
|
28
|
+
| quality | essentiality | |
|
29
|
+
| type | features | |
|
30
|
+
| | heart | |
|
31
|
+
| | individualism | |
|
32
|
+
| | individuality | |
|
33
|
+
| | like | |
|
34
|
+
| | makeup | |
|
35
|
+
| | meat | |
|
36
|
+
| | outlook | |
|
37
|
+
| | point | |
|
38
|
+
| | score | |
|
39
|
+
| | stuff | |
|
40
|
+
| | temper | |
|
41
|
+
| | temperament | |
|
42
|
+
| | texture | |
|
43
|
+
| | traits | |
|
44
|
+
+--------------------------+-------------------------+-------------------------+
|
45
|
+
+---------------------------------------+--------------------------------------+
|
46
|
+
| noun: type, kind |
|
47
|
+
+---------------------------------------+--------------------------------------+
|
48
|
+
| character | anatomy |
|
49
|
+
| description | brand |
|
50
|
+
| sort | cast |
|
51
|
+
| structure | category |
|
52
|
+
| style | color |
|
53
|
+
| variety | conformation |
|
54
|
+
| way | figure |
|
55
|
+
| | framework |
|
56
|
+
| | ilk |
|
57
|
+
| | shape |
|
58
|
+
| | species |
|
59
|
+
| | stripe |
|
60
|
+
+---------------------------------------+--------------------------------------+
|
61
|
+
+--------------------------+-------------------------+-------------------------+
|
62
|
+
| noun: earth, creation |
|
63
|
+
+--------------------------+-------------------------+-------------------------+
|
64
|
+
| environment | cosmos | megacosm |
|
65
|
+
| landscape | country | natural history |
|
66
|
+
| view | countryside | |
|
67
|
+
| world | forest | |
|
68
|
+
| | generation | |
|
69
|
+
| | macrocosm | |
|
70
|
+
| | outdoors | |
|
71
|
+
| | scenery | |
|
72
|
+
| | seascape | |
|
73
|
+
| | setting | |
|
74
|
+
| | universe | |
|
75
|
+
+--------------------------+-------------------------+-------------------------+
|
76
|
+
```
|
77
|
+
|
78
|
+
## Contributing
|
79
|
+
|
80
|
+
Bug reports and PRs are welcome.
|
81
|
+
|
82
|
+
## License
|
83
|
+
|
84
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
85
|
+
|
86
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
87
|
+
|
88
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
89
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "thes"
|
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__)
|
data/bin/setup
ADDED
data/exe/thes
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'thes'
|
4
|
+
|
5
|
+
query = ARGV.join(' ').strip
|
6
|
+
|
7
|
+
if query.length.zero?
|
8
|
+
puts 'Usage: thes <search term>'
|
9
|
+
exit 1
|
10
|
+
end
|
11
|
+
|
12
|
+
result = Thes.new(query).call
|
13
|
+
|
14
|
+
if $stdout.isatty
|
15
|
+
IO.popen('less', 'w') { |f| f << result }
|
16
|
+
else
|
17
|
+
$stdout << result
|
18
|
+
end
|
19
|
+
|
20
|
+
exit 0
|
data/lib/thes.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require "thes/version"
|
2
|
+
|
3
|
+
require 'uri'
|
4
|
+
require 'cgi'
|
5
|
+
require 'open-uri'
|
6
|
+
require 'nokogiri'
|
7
|
+
require 'terminal-table'
|
8
|
+
|
9
|
+
class Thes
|
10
|
+
BASE_URL = 'http://www.thesaurus.com/browse/'.freeze
|
11
|
+
|
12
|
+
def initialize(query)
|
13
|
+
@query = query
|
14
|
+
end
|
15
|
+
|
16
|
+
def call
|
17
|
+
url = URI.join(BASE_URL, CGI.escape(@query))
|
18
|
+
html = Nokogiri::HTML.parse(open(url))
|
19
|
+
filters = html.search('.filters')
|
20
|
+
|
21
|
+
tables = filters.map do |filter|
|
22
|
+
type = filter.search('em.txt').text
|
23
|
+
desc = filter.search('em.txt ~ strong').text
|
24
|
+
|
25
|
+
groups = filter.search('.relevancy-block ul > li > a').group_by do |el|
|
26
|
+
el.attr('data-category').match(/relevant-(\d+)/)[1].to_i
|
27
|
+
end
|
28
|
+
|
29
|
+
columns = groups.values.map do |els|
|
30
|
+
els.map { |el| el.search('span.text').text }
|
31
|
+
end
|
32
|
+
|
33
|
+
columns.each(&:sort!)
|
34
|
+
|
35
|
+
max_size = columns.max_by(&:size).size
|
36
|
+
columns.each { |group| group.fill('', group.size, max_size - group.size) }
|
37
|
+
|
38
|
+
rows = columns.transpose
|
39
|
+
|
40
|
+
Terminal::Table.new(
|
41
|
+
title: "#{type}: #{desc}",
|
42
|
+
rows: rows,
|
43
|
+
style: { width: 80 }
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
tables.join("\n")
|
48
|
+
end
|
49
|
+
end
|
data/lib/thes/version.rb
ADDED
data/thes.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'thes/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'thes'
|
8
|
+
spec.version = Thes::VERSION
|
9
|
+
spec.authors = ['Rob Watson']
|
10
|
+
spec.email = ['rob@rfwatson.net']
|
11
|
+
|
12
|
+
spec.summary = %q{Access www.thesaurus.com from the command line.}
|
13
|
+
spec.homepage = 'https://github.com/rfwatson/thes'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = 'exe'
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ['lib']
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.15'
|
24
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
25
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
26
|
+
spec.add_development_dependency 'awesome_print', '~> 1.7'
|
27
|
+
spec.add_development_dependency 'byebug', '~> 9'
|
28
|
+
|
29
|
+
spec.add_dependency 'nokogiri', '~> 1.8'
|
30
|
+
spec.add_dependency 'terminal-table', '~> 1.8'
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: thes
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rob Watson
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-09-05 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.15'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.15'
|
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
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: awesome_print
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.7'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.7'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: byebug
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '9'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '9'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: nokogiri
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.8'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.8'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: terminal-table
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.8'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.8'
|
111
|
+
description:
|
112
|
+
email:
|
113
|
+
- rob@rfwatson.net
|
114
|
+
executables:
|
115
|
+
- thes
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- ".gitignore"
|
120
|
+
- ".rspec"
|
121
|
+
- ".travis.yml"
|
122
|
+
- Gemfile
|
123
|
+
- LICENSE.txt
|
124
|
+
- README.md
|
125
|
+
- Rakefile
|
126
|
+
- bin/console
|
127
|
+
- bin/setup
|
128
|
+
- exe/thes
|
129
|
+
- lib/thes.rb
|
130
|
+
- lib/thes/version.rb
|
131
|
+
- thes.gemspec
|
132
|
+
homepage: https://github.com/rfwatson/thes
|
133
|
+
licenses:
|
134
|
+
- MIT
|
135
|
+
metadata: {}
|
136
|
+
post_install_message:
|
137
|
+
rdoc_options: []
|
138
|
+
require_paths:
|
139
|
+
- lib
|
140
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
|
+
requirements:
|
147
|
+
- - ">="
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
requirements: []
|
151
|
+
rubyforge_project:
|
152
|
+
rubygems_version: 2.6.13
|
153
|
+
signing_key:
|
154
|
+
specification_version: 4
|
155
|
+
summary: Access www.thesaurus.com from the command line.
|
156
|
+
test_files: []
|