eudict-translate 0.0.1

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.
@@ -0,0 +1,3 @@
1
+ === 0.0.1 2010-08-10
2
+
3
+ * Initial release
@@ -0,0 +1,15 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.rdoc
4
+ Rakefile
5
+ bin/eudict
6
+ lib/eudict-gem.rb
7
+ lib/eudict/cli.rb
8
+ script/console
9
+ script/destroy
10
+ script/generate
11
+ spec/eudict-gem_spec.rb
12
+ spec/eudict_cli_spec.rb
13
+ spec/spec.opts
14
+ spec/spec_helper.rb
15
+ tasks/rspec.rake
@@ -0,0 +1,44 @@
1
+ = eudict-translate
2
+
3
+ * http://github.com/bkrsta/eudict-translate
4
+
5
+ == FEATURES/PROBLEMS:
6
+
7
+ * fix unicode string length
8
+
9
+ == SYNOPSIS:
10
+
11
+ Usage: eudict [src lang] [dest lang] [text]
12
+
13
+ == REQUIREMENTS:
14
+
15
+ * mechanize, hpricot, terminal-table
16
+
17
+ == INSTALL:
18
+
19
+ sudo gem i eudict-translate
20
+
21
+ == LICENSE:
22
+
23
+ (The MIT License)
24
+
25
+ Copyright (c) 2010 BKrsta
26
+
27
+ Permission is hereby granted, free of charge, to any person obtaining
28
+ a copy of this software and associated documentation files (the
29
+ 'Software'), to deal in the Software without restriction, including
30
+ without limitation the rights to use, copy, modify, merge, publish,
31
+ distribute, sublicense, and/or sell copies of the Software, and to
32
+ permit persons to whom the Software is furnished to do so, subject to
33
+ the following conditions:
34
+
35
+ The above copyright notice and this permission notice shall be
36
+ included in all copies or substantial portions of the Software.
37
+
38
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
39
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
40
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
41
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
42
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
43
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
44
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,20 @@
1
+ require 'rubygems'
2
+ gem 'hoe', '>= 2.1.0'
3
+ require 'hoe'
4
+ require 'fileutils'
5
+ require './lib/eudict-gem'
6
+
7
+ Hoe.plugin :newgem
8
+
9
+ $hoe = Hoe.spec 'eudict-translate' do
10
+ self.developer 'BKrsta', 'bkrsta@gmail.com'
11
+ self.rubyforge_name = 'eudict-translate'
12
+ self.extra_deps = [
13
+ ['mechanize','> 0'],
14
+ ['hpricot','> 0'],
15
+ ['terminal-table','> 0']
16
+ ]
17
+ end
18
+
19
+ require 'newgem/tasks'
20
+ Dir['tasks/**/*.rake'].each { |t| load t }
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'mechanize'
4
+ require 'hpricot'
5
+ require 'terminal-table/import'
6
+
7
+ usage = [ "Usage: #{File.basename(__FILE__)} [src lang] [dest lang] [text]",
8
+ " example: #{File.basename(__FILE__)} eng cro ruby" ].join("\n")
9
+
10
+ def translate from, to, text
11
+ stats_url = "http://www.eudict.com/indexHr.php?word=#{CGI.escape text}&lang=#{from}#{to}"
12
+ agent = Mechanize.new
13
+ agent.user_agent_alias = 'Mac Safari'
14
+ page = agent.get(stats_url)
15
+ page = agent.get_file(stats_url)
16
+ doc = Hpricot(page)
17
+
18
+ rows = doc.search("//div[@id='content']/table/tr/td")
19
+ 2.times { rows.delete rows.first }
20
+ 3.times { rows.delete rows.last }
21
+ x=0; @table_rows=[]; temp=[]
22
+ if rows.empty?
23
+ puts "No result from EUdict ..."
24
+ exit
25
+ end
26
+ rows.each do |row|
27
+ if x%2==0
28
+ temp = [row.inner_text]
29
+ else
30
+ temp << row.inner_text
31
+ @table_rows << temp
32
+ end
33
+ x+=1
34
+ end
35
+ @table_rows
36
+ tbl = table do |t|
37
+ t.headings = from, to
38
+ @table_rows.each { |r| t<<r }
39
+ end
40
+ puts tbl
41
+ end
42
+
43
+ if ARGV[0]
44
+ from = ARGV[0]
45
+ if ARGV[1]
46
+ to = ARGV[1]
47
+ if !ARGV[2]
48
+ puts "Nothing to translate..."
49
+ puts
50
+ puts usage
51
+ exit
52
+ end
53
+ if ARGV[3]
54
+ puts usage
55
+ exit
56
+ end
57
+ text = ARGV[2]
58
+ translate from, to, text
59
+ puts "** this information was gathered from: http://www.eudict.com/ **"
60
+ else
61
+ puts usage
62
+ end
63
+ else
64
+ puts usage
65
+ end
@@ -0,0 +1,6 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ module EudictGem
5
+ VERSION = '0.0.1'
6
+ end
@@ -0,0 +1,42 @@
1
+ require 'optparse'
2
+
3
+ module Eudict
4
+ class CLI
5
+ def self.execute(stdout, arguments=[])
6
+
7
+ # NOTE: the option -p/--path= is given as an example, and should be replaced in your application.
8
+
9
+ options = {
10
+ :path => '~'
11
+ }
12
+ mandatory_options = %w( )
13
+
14
+ parser = OptionParser.new do |opts|
15
+ opts.banner = <<-BANNER.gsub(/^ /,'')
16
+ This application is wonderful because...
17
+
18
+ Usage: #{File.basename($0)} [options]
19
+
20
+ Options are:
21
+ BANNER
22
+ opts.separator ""
23
+ opts.on("-p", "--path PATH", String,
24
+ "This is a sample message.",
25
+ "For multiple lines, add more strings.",
26
+ "Default: ~") { |arg| options[:path] = arg }
27
+ opts.on("-h", "--help",
28
+ "Show this help message.") { stdout.puts opts; exit }
29
+ opts.parse!(arguments)
30
+
31
+ if mandatory_options && mandatory_options.find { |option| options[option.to_sym].nil? }
32
+ stdout.puts opts; exit
33
+ end
34
+ end
35
+
36
+ path = options[:path]
37
+
38
+ # do stuff
39
+ stdout.puts "To update this executable, look in lib/eudict/cli.rb"
40
+ end
41
+ end
42
+ end
@@ -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/eudict-gem.rb'}"
9
+ puts "Loading eudict-gem gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
@@ -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)
@@ -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)
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ # Time to add your specs!
4
+ # http://rspec.info/
5
+ describe "Place your specs here" do
6
+
7
+ it "find this spec in spec directory" do
8
+ # violated "Be sure to write your specs"
9
+ end
10
+
11
+ end
@@ -0,0 +1,15 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require 'eudict/cli'
3
+
4
+ describe Eudict::CLI, "execute" do
5
+ before(:each) do
6
+ @stdout_io = StringIO.new
7
+ Eudict::CLI.execute(@stdout_io, [])
8
+ @stdout_io.rewind
9
+ @stdout = @stdout_io.read
10
+ end
11
+
12
+ it "should print default output" do
13
+ @stdout.should =~ /To update this executable/
14
+ end
15
+ end
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1,10 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
5
+ gem 'rspec'
6
+ require 'spec'
7
+ end
8
+
9
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
10
+ require 'eudict-gem'
@@ -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,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eudict-translate
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - BKrsta
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-08-10 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: mechanize
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">"
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: hpricot
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">"
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :runtime
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: terminal-table
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">"
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ type: :runtime
62
+ version_requirements: *id003
63
+ - !ruby/object:Gem::Dependency
64
+ name: rubyforge
65
+ prerelease: false
66
+ requirement: &id004 !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 7
72
+ segments:
73
+ - 2
74
+ - 0
75
+ - 4
76
+ version: 2.0.4
77
+ type: :development
78
+ version_requirements: *id004
79
+ - !ruby/object:Gem::Dependency
80
+ name: hoe
81
+ prerelease: false
82
+ requirement: &id005 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ hash: 21
88
+ segments:
89
+ - 2
90
+ - 6
91
+ - 1
92
+ version: 2.6.1
93
+ type: :development
94
+ version_requirements: *id005
95
+ description: ""
96
+ email:
97
+ - bkrsta@gmail.com
98
+ executables:
99
+ - eudict
100
+ extensions: []
101
+
102
+ extra_rdoc_files:
103
+ - History.txt
104
+ - Manifest.txt
105
+ files:
106
+ - History.txt
107
+ - Manifest.txt
108
+ - README.rdoc
109
+ - Rakefile
110
+ - bin/eudict
111
+ - lib/eudict-gem.rb
112
+ - lib/eudict/cli.rb
113
+ - script/console
114
+ - script/destroy
115
+ - script/generate
116
+ - spec/eudict-gem_spec.rb
117
+ - spec/eudict_cli_spec.rb
118
+ - spec/spec.opts
119
+ - spec/spec_helper.rb
120
+ - tasks/rspec.rake
121
+ has_rdoc: true
122
+ homepage: http://github.com/bkrsta/eudict-translate
123
+ licenses: []
124
+
125
+ post_install_message:
126
+ rdoc_options:
127
+ - --main
128
+ - README.rdoc
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ none: false
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ hash: 3
137
+ segments:
138
+ - 0
139
+ version: "0"
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ none: false
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ hash: 3
146
+ segments:
147
+ - 0
148
+ version: "0"
149
+ requirements: []
150
+
151
+ rubyforge_project: eudict-translate
152
+ rubygems_version: 1.3.7
153
+ signing_key:
154
+ specification_version: 3
155
+ summary: ""
156
+ test_files: []
157
+