alc 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Manifest.txt +14 -0
- data/PostInstall.txt +7 -0
- data/README.rdoc +48 -0
- data/Rakefile +23 -0
- data/bin/alc +12 -0
- data/lib/alc.rb +68 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/spec/alc_spec.rb +53 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +10 -0
- data/tasks/rspec.rake +21 -0
- metadata +101 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/PostInstall.txt
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
= alc
|
2
|
+
|
3
|
+
* http://github.com/#{github_username}/#{project_name}
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
Use SPACE ALC (http://eow.alc.co.jp/) from command line.
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
* FIX (list of features or problems)
|
12
|
+
|
13
|
+
== SYNOPSIS:
|
14
|
+
|
15
|
+
FIX (code sample of usage)
|
16
|
+
|
17
|
+
== REQUIREMENTS:
|
18
|
+
|
19
|
+
* FIX (list of requirements)
|
20
|
+
|
21
|
+
== INSTALL:
|
22
|
+
|
23
|
+
* FIX (sudo gem install, anything else)
|
24
|
+
|
25
|
+
== LICENSE:
|
26
|
+
|
27
|
+
(The MIT License)
|
28
|
+
|
29
|
+
Copyright (c) 2010 zentooo
|
30
|
+
|
31
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
32
|
+
a copy of this software and associated documentation files (the
|
33
|
+
'Software'), to deal in the Software without restriction, including
|
34
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
35
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
36
|
+
permit persons to whom the Software is furnished to do so, subject to
|
37
|
+
the following conditions:
|
38
|
+
|
39
|
+
The above copyright notice and this permission notice shall be
|
40
|
+
included in all copies or substantial portions of the Software.
|
41
|
+
|
42
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
43
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
44
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
45
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
46
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
47
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
48
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'hoe', '>= 2.1.0'
|
3
|
+
require 'hoe'
|
4
|
+
require 'fileutils'
|
5
|
+
require './lib/alc'
|
6
|
+
|
7
|
+
Hoe.plugin :newgem
|
8
|
+
# Hoe.plugin :website
|
9
|
+
# Hoe.plugin :cucumberfeatures
|
10
|
+
|
11
|
+
# Generate all the Rake tasks
|
12
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
13
|
+
$hoe = Hoe.spec 'alc' do
|
14
|
+
self.developer 'zentooo', 'ankerasoy@gmail.com'
|
15
|
+
self.extra_deps = ['mechanize', 'termcolor']
|
16
|
+
end
|
17
|
+
|
18
|
+
require 'newgem/tasks'
|
19
|
+
Dir['tasks/**/*.rake'].each { |t| load t }
|
20
|
+
|
21
|
+
# TODO - want other tests/tasks run by default? Add them to the list
|
22
|
+
# remove_task :default
|
23
|
+
# task :default => [:spec, :features]
|
data/bin/alc
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'alc'
|
5
|
+
|
6
|
+
result_text = Alc::Alc.new(ARGV).make_result_text_from_page
|
7
|
+
tmp_file_name = "alc.temp" + Time.now.to_f.ceil.to_s
|
8
|
+
File.open("#{tmp_file_name}", "w") do |file|
|
9
|
+
file.write(result_text)
|
10
|
+
end
|
11
|
+
system("less -R #{tmp_file_name}")
|
12
|
+
system("rm -rf #{tmp_file_name}")
|
data/lib/alc.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'mechanize'
|
6
|
+
require 'termcolor'
|
7
|
+
|
8
|
+
require 'uri'
|
9
|
+
|
10
|
+
module Alc
|
11
|
+
|
12
|
+
VERSION = '0.0.1'
|
13
|
+
|
14
|
+
class Alc
|
15
|
+
|
16
|
+
BASE_URI = "http://eow.alc.co.jp/"
|
17
|
+
CHAR_CODE = "/UTF-8/"
|
18
|
+
|
19
|
+
def initialize(params)
|
20
|
+
@agent = WWW::Mechanize.new
|
21
|
+
@agent.user_agent_alias = 'Windows IE 7'
|
22
|
+
@agent.get(make_uri_from_params(params))
|
23
|
+
@words = params
|
24
|
+
end
|
25
|
+
|
26
|
+
def make_result_text_from_page
|
27
|
+
text = ""
|
28
|
+
meanings = get_meaning_text_from_page
|
29
|
+
get_midashi_text_from_page.each_with_index do |midashi, index|
|
30
|
+
text += "・" + midashi + "\n" + meanings[index] + "\n"
|
31
|
+
end
|
32
|
+
return text
|
33
|
+
end
|
34
|
+
|
35
|
+
def get_midashi_text_from_page
|
36
|
+
return @agent.page.search('li span.midashi').map do |midashi|
|
37
|
+
inner_text = midashi.inner_text
|
38
|
+
@words.each do |word|
|
39
|
+
inner_text.sub!(/(#{word})/i) { TermColor.parse("<on_blue>#{$1}</on_blue>") }
|
40
|
+
end
|
41
|
+
inner_text
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def get_meaning_text_from_page
|
46
|
+
meanings = Array.new
|
47
|
+
@agent.page.search('li div').each do |div|
|
48
|
+
lis = div.search('li')
|
49
|
+
if lis.size != 0
|
50
|
+
meanings << lis.inject('') { |text, li| text + " " + li.inner_text + "\n" }
|
51
|
+
else
|
52
|
+
meanings << " " + div.inner_text
|
53
|
+
end
|
54
|
+
end
|
55
|
+
return meanings
|
56
|
+
end
|
57
|
+
|
58
|
+
def make_uri_from_params(params)
|
59
|
+
return BASE_URI + make_query_from_params(params) + CHAR_CODE
|
60
|
+
end
|
61
|
+
|
62
|
+
def make_query_from_params(params)
|
63
|
+
return params.map { |param| URI.encode(param) }.join('+')
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
data/script/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# File: script/console
|
3
|
+
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
|
+
|
5
|
+
libs = " -r irb/completion"
|
6
|
+
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
7
|
+
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
8
|
+
libs << " -r #{File.dirname(__FILE__) + '/../lib/alc.rb'}"
|
9
|
+
puts "Loading alc gem"
|
10
|
+
exec "#{irb} #{libs} --simple-prompt"
|
data/script/destroy
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/destroy'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/generate'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Generate.new.run(ARGV)
|
data/spec/alc_spec.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
# Time to add your specs!
|
4
|
+
# http://rspec.info/
|
5
|
+
|
6
|
+
require 'uri'
|
7
|
+
|
8
|
+
describe "Alc" do
|
9
|
+
|
10
|
+
before do
|
11
|
+
BASE_URI = "http://eow.alc.co.jp/"
|
12
|
+
CHAR_CODE = "/UTF-8/"
|
13
|
+
@alc = Alc::Alc.new("test")
|
14
|
+
#@alc = Alc::Alc.new("男")
|
15
|
+
#@alc = Alc::Alc.new("take away")
|
16
|
+
@encoded_ja_test = URI.encode("てすと")
|
17
|
+
end
|
18
|
+
|
19
|
+
it "make query from parameters" do
|
20
|
+
@alc.make_query_from_params(%w[ test test test]).should == "test+test+test"
|
21
|
+
@alc.make_query_from_params(%w[ てすと てすと てすと]).should == "#{@encoded_ja_test}+#{@encoded_ja_test}+#{@encoded_ja_test}"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "make uri from parameters" do
|
25
|
+
@alc.make_uri_from_params(%w[ test test test]).should == BASE_URI + "test+test+test" + CHAR_CODE
|
26
|
+
end
|
27
|
+
|
28
|
+
it "perform request to alc page" do
|
29
|
+
#p @alc.perform_request(%w[ test ])
|
30
|
+
end
|
31
|
+
|
32
|
+
#it "gets hash from page" do
|
33
|
+
#p @alc.make_midashi_wordclass_hash_from_page
|
34
|
+
#end
|
35
|
+
|
36
|
+
#it "gets midashi from page" do
|
37
|
+
#p @alc.get_midashi_text_from_page
|
38
|
+
#end
|
39
|
+
|
40
|
+
#it "gets meaning from page" do
|
41
|
+
#p @alc.get_meaning_text_from_page
|
42
|
+
#end
|
43
|
+
|
44
|
+
it "make result" do
|
45
|
+
result_text = @alc.make_result_text_from_page
|
46
|
+
File.open("alc.temp", "w") do |file|
|
47
|
+
file.write(result_text)
|
48
|
+
end
|
49
|
+
system("more alc.temp")
|
50
|
+
system("rm -rf alc.temp")
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/spec/spec_helper.rb
ADDED
data/tasks/rspec.rake
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
begin
|
2
|
+
require 'spec'
|
3
|
+
rescue LoadError
|
4
|
+
require 'rubygems' unless ENV['NO_RUBYGEMS']
|
5
|
+
require 'spec'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'spec/rake/spectask'
|
9
|
+
rescue LoadError
|
10
|
+
puts <<-EOS
|
11
|
+
To use rspec for testing you must install rspec gem:
|
12
|
+
gem install rspec
|
13
|
+
EOS
|
14
|
+
exit(0)
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "Run the specs under spec/models"
|
18
|
+
Spec::Rake::SpecTask.new do |t|
|
19
|
+
t.spec_opts = ['--options', "spec/spec.opts"]
|
20
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: alc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- zentooo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-01-20 00:00:00 +09:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: mechanize
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: termcolor
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: hoe
|
37
|
+
type: :development
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 2.3.3
|
44
|
+
version:
|
45
|
+
description: Use SPACE ALC (http://eow.alc.co.jp/) from command line.
|
46
|
+
email:
|
47
|
+
- ankerasoy@gmail.com
|
48
|
+
executables:
|
49
|
+
- alc
|
50
|
+
extensions: []
|
51
|
+
|
52
|
+
extra_rdoc_files:
|
53
|
+
- History.txt
|
54
|
+
- Manifest.txt
|
55
|
+
- PostInstall.txt
|
56
|
+
files:
|
57
|
+
- History.txt
|
58
|
+
- Manifest.txt
|
59
|
+
- PostInstall.txt
|
60
|
+
- README.rdoc
|
61
|
+
- Rakefile
|
62
|
+
- lib/alc.rb
|
63
|
+
- bin/alc
|
64
|
+
- script/console
|
65
|
+
- script/destroy
|
66
|
+
- script/generate
|
67
|
+
- spec/alc_spec.rb
|
68
|
+
- spec/spec.opts
|
69
|
+
- spec/spec_helper.rb
|
70
|
+
- tasks/rspec.rake
|
71
|
+
has_rdoc: true
|
72
|
+
homepage: http://github.com/#{github_username}/#{project_name}
|
73
|
+
licenses: []
|
74
|
+
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options:
|
77
|
+
- --main
|
78
|
+
- README.rdoc
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: "0"
|
86
|
+
version:
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: "0"
|
92
|
+
version:
|
93
|
+
requirements: []
|
94
|
+
|
95
|
+
rubyforge_project: alc
|
96
|
+
rubygems_version: 1.3.5
|
97
|
+
signing_key:
|
98
|
+
specification_version: 3
|
99
|
+
summary: Use SPACE ALC (http://eow.alc.co.jp/) from command line.
|
100
|
+
test_files: []
|
101
|
+
|