jisho_helper 0.1.0
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/MIT-LICENSE +20 -0
- data/README.md +28 -0
- data/Rakefile +34 -0
- data/lib/jisho_helper.rb +20 -0
- data/lib/jisho_helper/jisho_breen.rb +43 -0
- data/lib/jisho_helper/jisho_jisho.rb +26 -0
- data/lib/jisho_helper/jisho_result.rb +18 -0
- data/lib/jisho_helper/jisho_tere.rb +42 -0
- data/lib/jisho_helper/version.rb +3 -0
- data/lib/tasks/jisho_helper_tasks.rake +4 -0
- metadata +55 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0396fc4f4a5cdcb46854e2d0904f5eb22f4837da
|
4
|
+
data.tar.gz: 5c5c2a7fac3aa5b21211661a32c2fdec18fc1050
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0b1acb20931f9715d5abdd5f05fb954b28c1b33cd112f20f51beff7d4c82b54b623700dccf4042477af7e060af3035c7b70cb1dd7eb0864694ebb4a059fce85a
|
7
|
+
data.tar.gz: d4f58814ee1979e909e31f2db67415b4dc451b7794a03ead645c373f73b4da7c4cdc8713738befd6d2ec6123527dcc0c289d05ca9b2713a3cf5bddd13ca39b3d
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2017
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# JishoHelper
|
2
|
+
Short description and motivation.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
How to use my plugin.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'jisho_helper'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
```bash
|
21
|
+
$ gem install jisho_helper
|
22
|
+
```
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
Contribution directions go here.
|
26
|
+
|
27
|
+
## License
|
28
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'JishoHelper'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
require 'bundler/gem_tasks'
|
23
|
+
|
24
|
+
require 'rake/testtask'
|
25
|
+
|
26
|
+
Rake::TestTask.new(:test) do |t|
|
27
|
+
t.libs << 'lib'
|
28
|
+
t.libs << 'test'
|
29
|
+
t.pattern = 'test/**/*_test.rb'
|
30
|
+
t.verbose = false
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
task default: :test
|
data/lib/jisho_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module JishoHelper
|
2
|
+
require 'rubygems'
|
3
|
+
require 'nokogiri'
|
4
|
+
require 'open-uri'
|
5
|
+
require 'json'
|
6
|
+
require 'erb'
|
7
|
+
require 'uri'
|
8
|
+
include ERB::Util
|
9
|
+
require 'jisho_helper/jisho_jisho'
|
10
|
+
require 'jisho_helper/jisho_result'
|
11
|
+
require 'jisho_helper/jisho_breen'
|
12
|
+
require 'jisho_helper/jisho_tere'
|
13
|
+
|
14
|
+
def look_up keyword
|
15
|
+
jisho = JishoHelper::JishoJisho.new(keyword)
|
16
|
+
tere = JishoHelper::JishoTere.new(keyword)
|
17
|
+
breen = JishoHelper::JishoBreen.new(jisho.kanji)
|
18
|
+
result = JishoHelper::JishoResult.new(jisho.kana, jisho.kanji, tere.entry, breen.example1, breen.example2 ,keyword)
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
class JishoHelper::JishoBreen
|
2
|
+
attr_reader :example1, :example2
|
3
|
+
|
4
|
+
def initialize keyword
|
5
|
+
enc_jp = keyword.encode(Encoding::EucJP)
|
6
|
+
url_safe_word = URI.escape(enc_jp)
|
7
|
+
word_url = breen_url url_safe_word
|
8
|
+
raw_example = get_info(word_url)
|
9
|
+
example = raw_example.search('pre').children[0]
|
10
|
+
|
11
|
+
unless example.nil?
|
12
|
+
assign_examples example.text
|
13
|
+
else
|
14
|
+
@example1 = 'N/A'
|
15
|
+
@example2 = 'N/A'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def assign_examples example
|
20
|
+
example = example.split
|
21
|
+
example.each_with_index do |letter, i|
|
22
|
+
break if !@example1.nil? && !@example2.nil?
|
23
|
+
if letter == "A:"
|
24
|
+
if i == 0
|
25
|
+
@example1 = example[i+1]
|
26
|
+
else
|
27
|
+
@example2 = example[i+1]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def get_info url
|
34
|
+
json_data = Nokogiri::HTML(open(url).read)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def breen_url keyword
|
40
|
+
enc_word = URI.encode(keyword)
|
41
|
+
"http://nihongo.monash.edu/cgi-bin/wwwjdic?1ZEE" + keyword +"=1=kana"
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class JishoHelper::JishoJisho
|
2
|
+
attr_reader :kana, :kanji
|
3
|
+
|
4
|
+
def initialize keyword
|
5
|
+
word_url = jisho_url keyword
|
6
|
+
json_data = JSON.parse(get_info(word_url))
|
7
|
+
|
8
|
+
unless json_data['data'].empty?
|
9
|
+
@kanji = json_data['data'][0]['japanese'][0]['word']
|
10
|
+
@kana = json_data['data'][0]['japanese'][0]['reading']
|
11
|
+
else
|
12
|
+
@kanji = 'N/A'
|
13
|
+
@kana = 'N/A'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_info url
|
18
|
+
json_data = Nokogiri::HTML(open(url).read)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def jisho_url keyword
|
24
|
+
"http://beta.jisho.org/api/v1/search/words?keyword=" + keyword
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'pry'
|
3
|
+
require 'nokogiri'
|
4
|
+
require 'open-uri'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
class JishoHelper::JishoResult
|
8
|
+
attr_accessor :kanji, :kana, :english, :def, :example1, :example2
|
9
|
+
|
10
|
+
def initialize kana, kanji, _def, example1, example2, english
|
11
|
+
@english = english
|
12
|
+
@kanji = kanji
|
13
|
+
@kana = kana
|
14
|
+
@def = _def
|
15
|
+
@example1 = example1
|
16
|
+
@example2 = example2
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
class JishoHelper::JishoTere
|
2
|
+
attr_reader :entry
|
3
|
+
|
4
|
+
def initialize keyword
|
5
|
+
id_url = tere_url keyword
|
6
|
+
id_doc = parse_xml id_url
|
7
|
+
|
8
|
+
unless id_doc.search('ItemID').empty?
|
9
|
+
id = id_doc.search('ItemID').first.inner_text
|
10
|
+
unless id.to_i == 0
|
11
|
+
word_url = tere_id_url id
|
12
|
+
word_doc = parse_xml word_url
|
13
|
+
word = word_doc.search('Body').children[1].text rescue nil
|
14
|
+
word.gsub!(/(\r\n|\r|\n|\t|\s)/, '')
|
15
|
+
@entry = word
|
16
|
+
end
|
17
|
+
else
|
18
|
+
@entry = "N/A"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def get_tere_id doc
|
25
|
+
item_id = doc.search('ItemID').first.inner_text rescue nil
|
26
|
+
return nil unless item_id
|
27
|
+
end
|
28
|
+
|
29
|
+
def parse_xml url
|
30
|
+
xml = open(url).read
|
31
|
+
doc = Nokogiri::XML(xml)
|
32
|
+
end
|
33
|
+
|
34
|
+
def tere_url keyword
|
35
|
+
enc_word = URI.encode(keyword)
|
36
|
+
url = "http://public.dejizo.jp/NetDicV09.asmx/SearchDicItemLite?Dic=EJdict&Word=#{enc_word}&Scope=HEADWORD&Match=EXACT&Merge=OR&Prof=XHTML&PageSize=20&PageIndex=0"
|
37
|
+
end
|
38
|
+
|
39
|
+
def tere_id_url id
|
40
|
+
"http://public.dejizo.jp/NetDicV09.asmx/GetDicItemLite?Dic=EJdict&Item=#{id}&Loc=&Prof=XHTML"
|
41
|
+
end
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jisho_helper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rory Brookes
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-08-10 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: This gem takes an English word and returns with the translation, dictionary
|
14
|
+
definition and example sentence.
|
15
|
+
email:
|
16
|
+
- rorybrookes89@hotmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- MIT-LICENSE
|
22
|
+
- README.md
|
23
|
+
- Rakefile
|
24
|
+
- lib/jisho_helper.rb
|
25
|
+
- lib/jisho_helper/jisho_breen.rb
|
26
|
+
- lib/jisho_helper/jisho_jisho.rb
|
27
|
+
- lib/jisho_helper/jisho_result.rb
|
28
|
+
- lib/jisho_helper/jisho_tere.rb
|
29
|
+
- lib/jisho_helper/version.rb
|
30
|
+
- lib/tasks/jisho_helper_tasks.rake
|
31
|
+
homepage:
|
32
|
+
licenses:
|
33
|
+
- MIT
|
34
|
+
metadata: {}
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
requirements: []
|
50
|
+
rubyforge_project:
|
51
|
+
rubygems_version: 2.5.1
|
52
|
+
signing_key:
|
53
|
+
specification_version: 4
|
54
|
+
summary: An EtoJ language gem
|
55
|
+
test_files: []
|