character_to_description 0.1.3 → 0.2.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 +4 -4
- data/README.md +11 -8
- data/lib/character_to_description.rb +39 -29
- data/lib/character_to_description/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3cf4f7ba86b76c320266992119fdbf09581a36be
|
|
4
|
+
data.tar.gz: 013f90790868b4085b5fc907bb5199f6abd7066d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 12a46853fb846a440f924c3de71707a1cebc1eab82419665ea41079ffee48d54a744da4da093de1460cc39b5b3bfd90dead615385d4c6353baa23ae46fc33cf9
|
|
7
|
+
data.tar.gz: 9ec7f01b7cbfe59e2d36b52121af66438cd4a59e24e9289e43a8f42c1295a807b76d6348786ac89b8ad9eefb47291d3c07a86549d44070b1f08589f37b0e1fde
|
data/README.md
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
# CharacterToDescription
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
This gem converts a character into its description by using the dictionary for NVDA, the screen reader for Windows.
|
|
3
|
+
This gem converts a Japanese character into its description by using the dictionary for NVDA, the screen reader for Windows.
|
|
6
4
|
There are many characters that are pronounced as the same in Japanese so that this gem currently targets to Japanese characters.
|
|
7
5
|
|
|
8
|
-
##
|
|
6
|
+
## Usage
|
|
9
7
|
|
|
10
8
|
Install the gem by the following command:
|
|
11
9
|
|
|
@@ -19,12 +17,17 @@ Now you can convert a character into its description.
|
|
|
19
17
|
require 'character_to_description'
|
|
20
18
|
|
|
21
19
|
class String
|
|
22
|
-
|
|
23
|
-
CharacterToDescription::Dictionary.description self
|
|
24
|
-
end
|
|
20
|
+
include CharacterToDescription
|
|
25
21
|
end
|
|
26
22
|
|
|
27
|
-
puts 'あ'.to_description
|
|
23
|
+
puts 'あ'.to_description #=> ひらがなの「あ」
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
If you want to overwrite the built-in dictionary, you can modify `CharacterToDescription.user_dictionary`.
|
|
27
|
+
|
|
28
|
+
```ruby
|
|
29
|
+
CharacterToDescription.user_dictionary['あ'] = 'Hiragana letter'
|
|
30
|
+
p 'あ'.to_description #=> "Hiragana letter"
|
|
28
31
|
```
|
|
29
32
|
|
|
30
33
|
## Development
|
|
@@ -1,37 +1,47 @@
|
|
|
1
1
|
require "character_to_description/version"
|
|
2
2
|
|
|
3
3
|
module CharacterToDescription
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
DESCRIPTION_FOR_UNKNOWN = '説明がありません'
|
|
5
|
+
DICTIONARY_PATH = File.expand_path '../../descriptions.dic', __FILE__
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
@dictionary = {}
|
|
8
|
+
@user_dictionary = {}
|
|
9
|
+
|
|
10
|
+
File.open(DICTIONARY_PATH, 'r') do |file|
|
|
11
|
+
file.each_line do |line|
|
|
12
|
+
next if line.match /^#|^\r\n$/
|
|
13
|
+
fields = line.split "\t"
|
|
14
|
+
character = fields[0]
|
|
15
|
+
description = fields[1].chomp.gsub /[()]/, ''
|
|
16
|
+
@dictionary[character] = description
|
|
15
17
|
end
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
class << self
|
|
21
|
+
attr_reader :dictionary
|
|
22
|
+
attr_accessor :user_dictionary
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def to_description
|
|
26
|
+
character = self[0]
|
|
27
|
+
description = CharacterToDescription.user_dictionary[character]
|
|
28
|
+
|
|
29
|
+
return description unless description.nil?
|
|
30
|
+
|
|
31
|
+
case character
|
|
32
|
+
when /[a-z]/
|
|
33
|
+
"Lower case #{character}"
|
|
34
|
+
when /[A-Z]/
|
|
35
|
+
"Upper case: #{character}"
|
|
36
|
+
when /\p{Hiragana}/
|
|
37
|
+
"ひらがなの「#{character}」"
|
|
38
|
+
when /\p{Katakana}/
|
|
39
|
+
"カタカナの「#{character}」"
|
|
40
|
+
when /[一-龠]/
|
|
41
|
+
CharacterToDescription.dictionary[character]
|
|
42
|
+
else
|
|
43
|
+
CharacterToDescription::DESCRIPTION_FOR_UNKNOWN
|
|
35
44
|
end
|
|
36
45
|
end
|
|
46
|
+
alias_method :to_d, :to_description
|
|
37
47
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: character_to_description
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Yoshiyuki Koyanagi
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-05-
|
|
11
|
+
date: 2016-05-21 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|