clispell 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/bin/clispell +62 -6
- data/clispell.gemspec +7 -3
- data/lib/clipboard_example.rb +18 -0
- metadata +29 -17
data/Rakefile
CHANGED
@@ -18,6 +18,7 @@ Jeweler::Tasks.new do |gem|
|
|
18
18
|
gem.add_dependency 'dmarkow-raspell'
|
19
19
|
gem.add_dependency 'mattscilipoti-rdialog'
|
20
20
|
gem.add_dependency 'oald_parser'
|
21
|
+
gem.add_dependency 'clipboard'
|
21
22
|
gem.executables = ['clispell']
|
22
23
|
gem.homepage = "http://github.com/ip2k/clispell"
|
23
24
|
gem.license = "Creative Commons by-nc-sa"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/bin/clispell
CHANGED
@@ -1,12 +1,39 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# ---- REQUIRED GEMS ----
|
2
3
|
require 'raspell'
|
3
4
|
require 'mattscilipoti-rdialog'
|
4
5
|
require 'oald_parser'
|
5
6
|
|
7
|
+
# ---- FLAGS AND GLOBAL VARS ----
|
8
|
+
|
9
|
+
# set this to true if we want to automatically copy the...
|
10
|
+
# ...correctly spelled word to the clipboard.
|
11
|
+
# NOTE: Requires the 'xclip' binary on Linux.
|
12
|
+
$enable_copy_to_clipboard = true
|
13
|
+
|
14
|
+
# ---- INIT LOGIC ----
|
15
|
+
|
16
|
+
# if we're enabling the clipboard functionality, require the 'clipboard' gem.
|
17
|
+
if $enable_copy_to_clipboard
|
18
|
+
require 'clipboard'
|
19
|
+
# if we're running on Linux, make sure that 'xclip' is available...
|
20
|
+
# ...and quit if it isn't since clipboard won't work without it.
|
21
|
+
if RUBY_PLATFORM.include?("linux")
|
22
|
+
xclip = `which xclip`.strip
|
23
|
+
if xclip.empty?
|
24
|
+
abort("You need the 'xclip' binary for copy-to-clipboard functionality to work properly under Linux")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
# ---- METHODS ----
|
31
|
+
|
6
32
|
# helper method for instantiating our ASpell API...
|
7
33
|
# using this, you only have to configure it in one spot.
|
8
34
|
def new_speller()
|
9
|
-
# instantiate our speller and set the dict to en_US
|
35
|
+
# instantiate our speller and set the dict to en_US...
|
36
|
+
# ...(English - United States) and ignore cAsE.
|
10
37
|
speller = Aspell.new("en_US")
|
11
38
|
speller.set_option("ignore-case", "true")
|
12
39
|
return speller
|
@@ -15,7 +42,8 @@ end
|
|
15
42
|
# helper method for instantiating our dialog API...
|
16
43
|
# using this, you only have to configure it in one spot.
|
17
44
|
def new_dialog()
|
18
|
-
# instantiate our dialog and set some options
|
45
|
+
# instantiate our dialog and set some options...
|
46
|
+
# ...then return it as an object
|
19
47
|
dialog = RDialog.new
|
20
48
|
dialog.nocancel = true
|
21
49
|
dialog.shadow = false
|
@@ -24,11 +52,14 @@ end
|
|
24
52
|
|
25
53
|
# look up a word in the Oxford Advanced Learners Dictionary
|
26
54
|
def define_word(someword)
|
55
|
+
# use the Facade interface from the oald_parser gem...
|
56
|
+
# ...which does the scraping / parsing for us.
|
57
|
+
puts "Waiting for the definition of #{someword} (requires internet access)..."
|
27
58
|
facade = OaldParser::Facade.create_configured_instance
|
28
59
|
return facade.describe(str: someword)
|
29
60
|
end
|
30
61
|
|
31
|
-
#
|
62
|
+
# check the spelling of a word and return boolean.
|
32
63
|
def check_spelling(someword)
|
33
64
|
myspeller = new_speller()
|
34
65
|
# test [someword] for spelling error and return true if it's correct.
|
@@ -39,22 +70,37 @@ def check_spelling(someword)
|
|
39
70
|
end
|
40
71
|
end
|
41
72
|
|
73
|
+
# copy [something] to the clipboard (works on OSX/Linux/Win)...
|
74
|
+
# ...if we have the flag set to enable that.
|
75
|
+
def copy_to_clipboard(something)
|
76
|
+
if $enable_copy_to_clipboard
|
77
|
+
Clipboard.copy(something)
|
78
|
+
puts "Copied #{something} to the clipboard."
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# get an array of possible corrections.
|
42
83
|
def get_suggestions(someword)
|
43
84
|
myspeller = new_speller()
|
44
85
|
return myspeller.suggest(someword)
|
45
86
|
end
|
46
87
|
|
88
|
+
# show a dialog menu with all the possible corrections
|
47
89
|
def show_suggestion_array(orig_word,suggestions)
|
48
90
|
# use our new_dialog helper method and call the menu() method on it...
|
49
91
|
# ...with our fancy text and suggestions array, then...
|
50
92
|
# ...block until the user picks something and return what they picked.
|
51
|
-
return new_dialog.menu("#{orig_word} not found or spelled incorrectly
|
93
|
+
return new_dialog.menu("#{orig_word} not found or spelled incorrectly.\nSelect a word below view the definition.", suggestions)
|
52
94
|
end
|
53
95
|
|
96
|
+
# show a dialog box with the definition.
|
54
97
|
def show_definition(definition)
|
55
98
|
return new_dialog.msgbox(definition)
|
56
99
|
end
|
57
100
|
|
101
|
+
|
102
|
+
# ---- MAIN ----
|
103
|
+
|
58
104
|
# if the user didn't pass any args, abort and let them know that they need to.
|
59
105
|
if ARGV.first.nil?
|
60
106
|
abort("You must specify a word that you want to spell check or define")
|
@@ -62,9 +108,14 @@ else
|
|
62
108
|
# if the user spelled the word right, just show the definition...
|
63
109
|
# and tell them they were right while we're waiting on the API.
|
64
110
|
if check_spelling(ARGV.first)
|
65
|
-
|
111
|
+
|
112
|
+
# if we're copying stuff to the clipboard, copy the correct spelling.
|
113
|
+
copy_to_clipboard(ARGV.first)
|
114
|
+
puts "#{ARGV.first} is spelled correctly."
|
115
|
+
|
116
|
+
# get and display the definition, then end.
|
66
117
|
definition = define_word(ARGV.first)
|
67
|
-
show_definition("#{ARGV.first}:\n#{definition}")
|
118
|
+
show_definition("#{ARGV.first} is spelled correctly.\n\n#{ARGV.first}:\n#{definition}")
|
68
119
|
exit(0)
|
69
120
|
else
|
70
121
|
# get possible words if the user sends us a typo'd word.
|
@@ -76,6 +127,11 @@ else
|
|
76
127
|
|
77
128
|
# call our show_suggestion_array method with the array-of-arrays.
|
78
129
|
user_selection_string = show_suggestion_array(ARGV.first, suggestions_array)
|
130
|
+
|
131
|
+
# if we're copying stuff to the clipboard, copy what the user picks.
|
132
|
+
copy_to_clipboard(user_selection_string)
|
133
|
+
|
134
|
+
# get and display the definition of the word the user picks, then end.
|
79
135
|
definition = define_word(user_selection_string)
|
80
136
|
show_definition("#{user_selection_string}:\n#{definition}")
|
81
137
|
exit(0)
|
data/clispell.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{clispell}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["ip2k"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-08-01}
|
13
13
|
s.default_executable = %q{clispell}
|
14
14
|
s.description = %q{clispell provides an easy-to-use CLI that harnesses ASpell the Oxford Advanced Learner's Dictionary and delivers pretty word info FAST right to your terminal}
|
15
15
|
s.email = %q{github@seanp2k.endjunk.com}
|
@@ -27,7 +27,8 @@ Gem::Specification.new do |s|
|
|
27
27
|
"Rakefile",
|
28
28
|
"VERSION",
|
29
29
|
"bin/clispell",
|
30
|
-
"clispell.gemspec"
|
30
|
+
"clispell.gemspec",
|
31
|
+
"lib/clipboard_example.rb"
|
31
32
|
]
|
32
33
|
s.homepage = %q{http://github.com/ip2k/clispell}
|
33
34
|
s.licenses = ["Creative Commons by-nc-sa"]
|
@@ -46,6 +47,7 @@ Gem::Specification.new do |s|
|
|
46
47
|
s.add_runtime_dependency(%q<dmarkow-raspell>, [">= 0"])
|
47
48
|
s.add_runtime_dependency(%q<mattscilipoti-rdialog>, [">= 0"])
|
48
49
|
s.add_runtime_dependency(%q<oald_parser>, [">= 0"])
|
50
|
+
s.add_runtime_dependency(%q<clipboard>, [">= 0"])
|
49
51
|
else
|
50
52
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
51
53
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
@@ -54,6 +56,7 @@ Gem::Specification.new do |s|
|
|
54
56
|
s.add_dependency(%q<dmarkow-raspell>, [">= 0"])
|
55
57
|
s.add_dependency(%q<mattscilipoti-rdialog>, [">= 0"])
|
56
58
|
s.add_dependency(%q<oald_parser>, [">= 0"])
|
59
|
+
s.add_dependency(%q<clipboard>, [">= 0"])
|
57
60
|
end
|
58
61
|
else
|
59
62
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
@@ -63,6 +66,7 @@ Gem::Specification.new do |s|
|
|
63
66
|
s.add_dependency(%q<dmarkow-raspell>, [">= 0"])
|
64
67
|
s.add_dependency(%q<mattscilipoti-rdialog>, [">= 0"])
|
65
68
|
s.add_dependency(%q<oald_parser>, [">= 0"])
|
69
|
+
s.add_dependency(%q<clipboard>, [">= 0"])
|
66
70
|
end
|
67
71
|
end
|
68
72
|
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# set this to true if we want to automatically copy the...
|
2
|
+
# ...correctly spelled word to the clipboard.
|
3
|
+
# NOTE: Requires the 'xclip' binary on Linux.
|
4
|
+
enable_copy_to_clipboard = true
|
5
|
+
|
6
|
+
if enable_copy_to_clipboard
|
7
|
+
require 'clipboard'
|
8
|
+
# if we're running on Linux, make sure that 'xclip' is available...
|
9
|
+
# ...and quit if it isn't since clipboard won't work without it.
|
10
|
+
if RUBY_PLATFORM.include?("linux")
|
11
|
+
xclip = `which xclip`.strip
|
12
|
+
if xclip.empty?
|
13
|
+
abort("You need the 'xclip' binary for copy-to-clipboard functionality to work properly under Linux")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
Clipboard.copy("test123")
|
17
|
+
puts Clipboard.paste
|
18
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clispell
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,12 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-08-01 00:00:00.000000000 -04:00
|
13
13
|
default_executable: clispell
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: shoulda
|
17
|
-
requirement: &
|
17
|
+
requirement: &80047820 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *80047820
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: bundler
|
28
|
-
requirement: &
|
28
|
+
requirement: &80047580 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: 1.0.0
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *80047580
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: jeweler
|
39
|
-
requirement: &
|
39
|
+
requirement: &80047340 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ~>
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: 1.6.4
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *80047340
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: rcov
|
50
|
-
requirement: &
|
50
|
+
requirement: &80047100 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ! '>='
|
@@ -55,10 +55,10 @@ dependencies:
|
|
55
55
|
version: '0'
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *80047100
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: dmarkow-raspell
|
61
|
-
requirement: &
|
61
|
+
requirement: &80046860 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - ! '>='
|
@@ -66,10 +66,10 @@ dependencies:
|
|
66
66
|
version: '0'
|
67
67
|
type: :runtime
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *80046860
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: mattscilipoti-rdialog
|
72
|
-
requirement: &
|
72
|
+
requirement: &80046620 !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
74
74
|
requirements:
|
75
75
|
- - ! '>='
|
@@ -77,10 +77,10 @@ dependencies:
|
|
77
77
|
version: '0'
|
78
78
|
type: :runtime
|
79
79
|
prerelease: false
|
80
|
-
version_requirements: *
|
80
|
+
version_requirements: *80046620
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
82
|
name: oald_parser
|
83
|
-
requirement: &
|
83
|
+
requirement: &80046380 !ruby/object:Gem::Requirement
|
84
84
|
none: false
|
85
85
|
requirements:
|
86
86
|
- - ! '>='
|
@@ -88,7 +88,18 @@ dependencies:
|
|
88
88
|
version: '0'
|
89
89
|
type: :runtime
|
90
90
|
prerelease: false
|
91
|
-
version_requirements: *
|
91
|
+
version_requirements: *80046380
|
92
|
+
- !ruby/object:Gem::Dependency
|
93
|
+
name: clipboard
|
94
|
+
requirement: &80046140 !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
type: :runtime
|
101
|
+
prerelease: false
|
102
|
+
version_requirements: *80046140
|
92
103
|
description: clispell provides an easy-to-use CLI that harnesses ASpell the Oxford
|
93
104
|
Advanced Learner's Dictionary and delivers pretty word info FAST right to your terminal
|
94
105
|
email: github@seanp2k.endjunk.com
|
@@ -108,6 +119,7 @@ files:
|
|
108
119
|
- VERSION
|
109
120
|
- bin/clispell
|
110
121
|
- clispell.gemspec
|
122
|
+
- lib/clipboard_example.rb
|
111
123
|
has_rdoc: true
|
112
124
|
homepage: http://github.com/ip2k/clispell
|
113
125
|
licenses:
|
@@ -124,7 +136,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
124
136
|
version: '0'
|
125
137
|
segments:
|
126
138
|
- 0
|
127
|
-
hash:
|
139
|
+
hash: -777866863
|
128
140
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
141
|
none: false
|
130
142
|
requirements:
|