codic_parser 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.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +21 -0
- data/LICENSE.txt +22 -0
- data/README.md +42 -0
- data/Rakefile +1 -0
- data/bin/codic_parser +5 -0
- data/codic_parser.gemspec +26 -0
- data/lib/codic_parser/browse.rb +11 -0
- data/lib/codic_parser/cli.rb +29 -0
- data/lib/codic_parser/parser/mb_parser.rb +24 -0
- data/lib/codic_parser/parser/parser.rb +38 -0
- data/lib/codic_parser/parser_factory.rb +16 -0
- data/lib/codic_parser/version.rb +3 -0
- data/lib/codic_parser.rb +8 -0
- metadata +121 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d605c25633f325992904fdf7bc63f00d5626b57c
|
4
|
+
data.tar.gz: 299f458990e6073fb44e6b462d8c6f966c54ae9f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 82b3c96aaad481246300ed3e9c20d85b283eaba33e45d6b06418f6038391f13d3c43d1c4e0bbe6526ceffcc480faa9851581551ae4a832a341ece97cb636b508
|
7
|
+
data.tar.gz: 56db2d4b9ed9523dadd5bb5a86c92e5b03d14d1060370abafb196204a7611d88693fbd5cbf782c22de8d06c52bb08380c97fd050c39bb1e41ef462f3ffcdc76a
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
codic_parser (0.0.1)
|
5
|
+
nokogiri (~> 1.5.10)
|
6
|
+
thor
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
nokogiri (1.5.11)
|
12
|
+
rake (10.2.2)
|
13
|
+
thor (0.19.1)
|
14
|
+
|
15
|
+
PLATFORMS
|
16
|
+
ruby
|
17
|
+
|
18
|
+
DEPENDENCIES
|
19
|
+
bundler (~> 1.5)
|
20
|
+
codic_parser!
|
21
|
+
rake
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Shohei Yamasaki
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# CodicParser
|
2
|
+
|
3
|
+
CodicParserは[codic.jp](http://codic.jp)をコマンドラインより使えるようにしたコマンドラインツールです。
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
### RubyGems
|
8
|
+
$ gem install codic_parser
|
9
|
+
|
10
|
+
## Usage
|
11
|
+
|
12
|
+
### Get
|
13
|
+
```
|
14
|
+
$ codic_parser get query_string
|
15
|
+
> show word list and description.
|
16
|
+
|
17
|
+
$ codic_parser get -l query_string
|
18
|
+
> exclude description.
|
19
|
+
|
20
|
+
$ codic_parser get -e query_string
|
21
|
+
> show entry list.
|
22
|
+
|
23
|
+
$ codic_parser get -a query_string
|
24
|
+
> show word list and entry list.
|
25
|
+
|
26
|
+
```
|
27
|
+
### Browse
|
28
|
+
```
|
29
|
+
$ codic_parser browse
|
30
|
+
> open http://codic.jp
|
31
|
+
|
32
|
+
$ codic_parser browse query_string
|
33
|
+
> open http://codic.jp //検索結果ページ
|
34
|
+
|
35
|
+
```
|
36
|
+
## Contributing
|
37
|
+
|
38
|
+
1. Fork it ( http://github.com/<my-github-username>/codic_parser/fork )
|
39
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
40
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
41
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
42
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/codic_parser
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'codic_parser/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "codic_parser"
|
8
|
+
spec.version = CodicParser::VERSION
|
9
|
+
spec.authors = ["Shohei Yamasaki"]
|
10
|
+
spec.email = ["shyamasaki@gmail.com"]
|
11
|
+
spec.summary = %q{CodicParser is a command-line interface. Codic.jp via terminal.}
|
12
|
+
spec.description = %q{CodicParser is a command-line interface. Codic.jp via terminal.}
|
13
|
+
spec.homepage = "https://github.com/shoyan/codic_parser"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake", "~> 0"
|
23
|
+
|
24
|
+
spec.add_dependency 'thor', "~> 0"
|
25
|
+
spec.add_dependency 'nokogiri', '~> 1.5', '>= 1.5.10'
|
26
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "thor"
|
2
|
+
|
3
|
+
module CodicParser
|
4
|
+
class CLI < Thor
|
5
|
+
desc "get word", "request word for codic.jp"
|
6
|
+
option :all, :type => :boolean, :aliases => :a
|
7
|
+
option :nodesc, :type => :boolean, :aliases => :l
|
8
|
+
option :entryonly, :type => :boolean, :aliases => :e
|
9
|
+
def get(word)
|
10
|
+
@parser = CodicParser::ParserFactory.get(word)
|
11
|
+
|
12
|
+
if options[:entryonly]
|
13
|
+
@parser.entry_list
|
14
|
+
exit
|
15
|
+
end
|
16
|
+
|
17
|
+
@parser.word_list(options)
|
18
|
+
|
19
|
+
if options[:all]
|
20
|
+
@parser.all(options)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
desc "browse", "opened in a browser"
|
25
|
+
def browse(word = nil)
|
26
|
+
CodicParser::Browse.open(word)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module CodicParser
|
2
|
+
class MbParser
|
3
|
+
def initialize(word)
|
4
|
+
@doc = Nokogiri::HTML(open("http://codic.jp/search?q=#{URI::encode(word)}&via=is"))
|
5
|
+
end
|
6
|
+
|
7
|
+
def word_list(options = {})
|
8
|
+
@doc.css('.translation .post a').each do |link|
|
9
|
+
puts link.content
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def entry_list
|
14
|
+
@doc.css('section.entry-list li').each do |link|
|
15
|
+
puts link.content
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def all(options = {})
|
20
|
+
self.word_list(options)
|
21
|
+
self.entry_list
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module CodicParser
|
2
|
+
class Parser
|
3
|
+
def initialize(word)
|
4
|
+
@doc = Nokogiri::HTML(open("http://codic.jp/search?q=#{URI::encode(word)}&via=is"))
|
5
|
+
end
|
6
|
+
|
7
|
+
def word_list(options= {} )
|
8
|
+
text = []
|
9
|
+
desc = []
|
10
|
+
|
11
|
+
@doc.css("#relations li a.seltext").each do |link|
|
12
|
+
text.push(link.content)
|
13
|
+
end
|
14
|
+
@doc.css("#relations li span.digest").each do |link|
|
15
|
+
desc.push(link.content)
|
16
|
+
end
|
17
|
+
|
18
|
+
text.each_index do |i|
|
19
|
+
if options[:nodesc]
|
20
|
+
puts "#{text[i]}"
|
21
|
+
else
|
22
|
+
puts "#{text[i]} / #{desc[i]}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def entry_list
|
28
|
+
@doc.css('section.entry-list li').each do |link|
|
29
|
+
puts link.content
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def all(options = {})
|
34
|
+
self.word_list(options)
|
35
|
+
self.entry_list
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "codic_parser/parser/parser.rb"
|
2
|
+
require "codic_parser/parser/mb_parser.rb"
|
3
|
+
require "nokogiri"
|
4
|
+
require "open-uri"
|
5
|
+
|
6
|
+
module CodicParser
|
7
|
+
class ParserFactory
|
8
|
+
def self.get(word)
|
9
|
+
if /[a-zA-z0-9]/.match(word)
|
10
|
+
CodicParser::Parser.new(word)
|
11
|
+
else
|
12
|
+
CodicParser::MbParser.new(word)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/codic_parser.rb
ADDED
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: codic_parser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Shohei Yamasaki
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-01 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.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: thor
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: nokogiri
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.5'
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 1.5.10
|
65
|
+
type: :runtime
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - "~>"
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '1.5'
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 1.5.10
|
75
|
+
description: CodicParser is a command-line interface. Codic.jp via terminal.
|
76
|
+
email:
|
77
|
+
- shyamasaki@gmail.com
|
78
|
+
executables:
|
79
|
+
- codic_parser
|
80
|
+
extensions: []
|
81
|
+
extra_rdoc_files: []
|
82
|
+
files:
|
83
|
+
- Gemfile
|
84
|
+
- Gemfile.lock
|
85
|
+
- LICENSE.txt
|
86
|
+
- README.md
|
87
|
+
- Rakefile
|
88
|
+
- bin/codic_parser
|
89
|
+
- codic_parser.gemspec
|
90
|
+
- lib/codic_parser.rb
|
91
|
+
- lib/codic_parser/browse.rb
|
92
|
+
- lib/codic_parser/cli.rb
|
93
|
+
- lib/codic_parser/parser/mb_parser.rb
|
94
|
+
- lib/codic_parser/parser/parser.rb
|
95
|
+
- lib/codic_parser/parser_factory.rb
|
96
|
+
- lib/codic_parser/version.rb
|
97
|
+
homepage: https://github.com/shoyan/codic_parser
|
98
|
+
licenses:
|
99
|
+
- MIT
|
100
|
+
metadata: {}
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
requirements: []
|
116
|
+
rubyforge_project:
|
117
|
+
rubygems_version: 2.2.0
|
118
|
+
signing_key:
|
119
|
+
specification_version: 4
|
120
|
+
summary: CodicParser is a command-line interface. Codic.jp via terminal.
|
121
|
+
test_files: []
|