alc-cmd 0.0.2 → 0.0.3

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.
data/.gitignore CHANGED
@@ -14,4 +14,4 @@ rdoc
14
14
  spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
- tmp
17
+ tmp/*
data/Gemfile CHANGED
@@ -2,3 +2,4 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in alc-cmd.gemspec
4
4
  gemspec
5
+ gem 'mechanize'
data/README.md CHANGED
@@ -18,7 +18,7 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- $ alc-cmd test
21
+ $ alc-cmd s search word
22
22
 
23
23
  ## Contributing
24
24
 
data/alc-cmd.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
10
10
  gem.email = ["kyamada@sonix.asia"]
11
11
  gem.description = %q{Command-line tool to translate English to Japanese }
12
12
  gem.summary = %q{Use SPACE ALC (http://eow.alc.co.jp/) from command line.}
13
- gem.homepage = ""
13
+ gem.homepage = "https://github.com/k-yamada/alc-cmd"
14
14
 
15
15
  gem.files = `git ls-files`.split($/)
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -18,4 +18,5 @@ Gem::Specification.new do |gem|
18
18
  gem.require_paths = ["lib"]
19
19
 
20
20
  gem.add_dependency 'thor'
21
+ gem.add_dependency 'mechanize'
21
22
  end
data/bin/alc-cmd CHANGED
@@ -1,5 +1,13 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'alc-cmd'
4
+ require 'thor'
4
5
 
5
- Alc::Cmd::CLI.start
6
+ result_text = Alc::Cmd::CLI.start
7
+
8
+ tmp_file_name = "/tmp/alc.temp" + Time.now.to_f.ceil.to_s
9
+ File.open("#{tmp_file_name}", "w") do |file|
10
+ file.write(result_text)
11
+ end
12
+ system("less -R #{tmp_file_name}")
13
+ system("rm -rf #{tmp_file_name}")
data/lib/alc-cmd/cli.rb CHANGED
@@ -1,10 +1,28 @@
1
+ # encoding: UTF-8
2
+ $LOAD_PATH << File.dirname(__FILE__)
1
3
  require 'thor'
4
+ require 'eijiro'
2
5
 
3
6
  module Alc; module Cmd
4
7
  class CLI < Thor
5
- desc "red WORD", "red words print."
6
- def red(word)
7
- say(word, :red)
8
+
9
+ desc "s [WORD1 WORD2]", "serach words"
10
+ def s(*words)
11
+
12
+ Eijiro.new.search(words)
13
+ #result = ""
14
+ #eijiro = Eijiro.new(words)
15
+
16
+ #eijiro.get_search_assistances.each do |assistance|
17
+ # result << set_color(assistance, :green) + "\n"
18
+ #end
19
+
20
+ #meanings = eijiro.get_meanings
21
+ #eijiro.get_titles.each_with_index do |title, index|
22
+ # result << set_color(title, :yellow) + "\n"
23
+ # result << set_color(meanings[index]) + "\n"
24
+ #end
25
+ #result
8
26
  end
9
27
 
10
28
  end
@@ -0,0 +1,66 @@
1
+ require 'thor'
2
+ require 'mechanize'
3
+ require 'uri'
4
+
5
+ module Alc; module Cmd
6
+ class Eijiro < Thor::Shell::Color
7
+ BASE_URI = "http://eow.alc.co.jp/"
8
+ CHAR_CODE = "/UTF-8/"
9
+
10
+ def initialize()
11
+ @agent = Mechanize.new
12
+ end
13
+
14
+ def search(words)
15
+ @agent.get(make_uri_from_words(words))
16
+ @words = words
17
+ result = ""
18
+ get_search_assistances.each do |assistance|
19
+ result << set_color(assistance, :green) + "\n"
20
+ end
21
+
22
+ meanings = get_meanings
23
+ get_titles.each_with_index do |title, index|
24
+ result << set_color(title, :yellow) + "\n"
25
+ result << set_color(meanings[index]) + "\n"
26
+ end
27
+ result
28
+ end
29
+
30
+ def make_uri_from_words(words)
31
+ return BASE_URI + make_query_from_words(words) + CHAR_CODE
32
+ end
33
+
34
+ def make_query_from_words(words)
35
+ return words.map { |param| URI.encode(param) }.join('+')
36
+ end
37
+
38
+ def get_search_assistances
39
+ assistances = []
40
+ @agent.page.search('div.sas strong').map do |h|
41
+ assistances << h.inner_text.chomp("\t\t\t\t\t\t")
42
+ end
43
+ assistances
44
+ end
45
+
46
+ def get_titles
47
+ return @agent.page.search('li span.midashi').map do |midashi|
48
+ inner_text = midashi.inner_text
49
+ end
50
+ end
51
+
52
+ def get_meanings
53
+ meanings = Array.new
54
+ @agent.page.search('li div').each do |div|
55
+ lis = div.search('li')
56
+ if lis.size != 0
57
+ meanings << lis.inject('') { |text, li| text + " " + li.inner_text + "\n" }
58
+ else
59
+ meanings << " " + div.inner_text
60
+ end
61
+ end
62
+ return meanings
63
+ end
64
+
65
+ end
66
+ end; end
@@ -1,5 +1,5 @@
1
1
  module Alc
2
2
  module Cmd
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alc-cmd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -27,6 +27,22 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: mechanize
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
30
46
  description: ! 'Command-line tool to translate English to Japanese '
31
47
  email:
32
48
  - kyamada@sonix.asia
@@ -44,8 +60,9 @@ files:
44
60
  - bin/alc-cmd
45
61
  - lib/alc-cmd.rb
46
62
  - lib/alc-cmd/cli.rb
63
+ - lib/alc-cmd/eijiro.rb
47
64
  - lib/alc-cmd/version.rb
48
- homepage: ''
65
+ homepage: https://github.com/k-yamada/alc-cmd
49
66
  licenses: []
50
67
  post_install_message:
51
68
  rdoc_options: []