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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 238a4c54005ac74f56a4dffd5472eb9ed4d45a52
4
- data.tar.gz: cf791830067b9401519cb5ca6586db4c735332be
3
+ metadata.gz: 3cf4f7ba86b76c320266992119fdbf09581a36be
4
+ data.tar.gz: 013f90790868b4085b5fc907bb5199f6abd7066d
5
5
  SHA512:
6
- metadata.gz: 358238e8cf9cce971ad476a47d6089a26e74f8cd16eb94b0232461ee02d2dafa4ae904ba9671d863ec48f45058039913218b0768d838fa434a27beb80f16752c
7
- data.tar.gz: 43c46e9d040a9307c5fc0e1d68c1fe04186ecb67d59bb08c18db49de99dc2ae9df94fdb98e97e4d59fbc67689646960b2f85da4af8cc2068785b59c9e975eae6
6
+ metadata.gz: 12a46853fb846a440f924c3de71707a1cebc1eab82419665ea41079ffee48d54a744da4da093de1460cc39b5b3bfd90dead615385d4c6353baa23ae46fc33cf9
7
+ data.tar.gz: 9ec7f01b7cbfe59e2d36b52121af66438cd4a59e24e9289e43a8f42c1295a807b76d6348786ac89b8ad9eefb47291d3c07a86549d44070b1f08589f37b0e1fde
data/README.md CHANGED
@@ -1,11 +1,9 @@
1
1
  # CharacterToDescription
2
2
 
3
- The gem for converting a character into its description.
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
- ## Quick start
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
- def to_description
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
- class Dictionary
5
- @description_table = {}
4
+ DESCRIPTION_FOR_UNKNOWN = '説明がありません'
5
+ DICTIONARY_PATH = File.expand_path '../../descriptions.dic', __FILE__
6
6
 
7
- File.open File.expand_path('../../descriptions.dic', __FILE__), 'r' do |file|
8
- file.each_line do |line|
9
- next if line.match /^#|^\r\n$/
10
- fields = line.split "\t"
11
- character = fields[0]
12
- description = fields[1].chomp.gsub /[()]/, ''
13
- @description_table[character] = description
14
- end
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
- class << self
17
- def description(character)
18
- return nil if character.empty?
19
- character = character[0] if character.size > 1
20
- case character
21
- when /[a-z]/
22
- "Lower case #{character}"
23
- when /[A-Z]/
24
- "Upper case: #{character}"
25
- when /\p{Hiragana}/
26
- "ひらがなの「#{character}」"
27
- when /\p{Katakana}/
28
- "カタカナの「#{character}」"
29
- when /[一-龠]/
30
- @description_table[character]
31
- else
32
- "不明な文字"
33
- end
34
- end
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
@@ -1,3 +1,3 @@
1
1
  module CharacterToDescription
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  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.1.3
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-16 00:00:00.000000000 Z
11
+ date: 2016-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler