jisho_sort 0.0.7 → 0.0.8

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
  SHA256:
3
- metadata.gz: 6ecbfaf60983094a2c4a7c0d5e3db922ffe491e68bdd3997c3e8964046a12716
4
- data.tar.gz: 8d7df8218ac18575048d1e1c4c591b38f35b33682f81c5d58f43736e04095964
3
+ metadata.gz: ca61b6d749edd12c597606316a44da80efb59806642ef8b22182652e7c9c2f8e
4
+ data.tar.gz: 41265fbae2e6275ae5ec2b8d1ed01d712daf332864807ed2f734f87c45bcb3b9
5
5
  SHA512:
6
- metadata.gz: f7ac05f65483756d2c2afd80ea286ab8897821aaa1e114c1677e3a5e952252ff6050f482da7f488d75ff08f3403b654ad8e9ae50952d2633c0160e7cc6c149a7
7
- data.tar.gz: 4509ef0ba6ae82a7bca61e6b5387ecbe8d781d928ee96c2892abb38f0fb54d6a2475e1ff4009cd3e993dd862e8a1b229e3c06842f223a293e84c103e4a708ff1
6
+ metadata.gz: 84556ba88712ed6f2ca2d6f0c1253d8bf091deb7eead4bb8cee085fe0a06369c95c8efbc69ac8c86f108a072d81380d383fc4c918e96d731d6f55f9708da62ab
7
+ data.tar.gz: acfc34f3e0502d897d610b6fdbf6431db0f1514d9973250d1bd100f7bc76c463009bfca79a1db23d5b843f38bc39a6b15e7601af8065c95f38f0c9ac0a3c6230
@@ -4,10 +4,10 @@ module JishoSort
4
4
  #
5
5
  # @param other [String] The object to compare with.
6
6
  # @return [Integer] Returns -1 if the current object's furigana is less than the other's, 0 if they are equal, and 1 if it is greater.
7
- def compare_by_furigana(other)
7
+ def compare_by_furigana(other, options = {})
8
8
  raise ArgumentError unless other.instance_of?(String)
9
9
 
10
- furigana <=> other.furigana
10
+ furigana(options) <=> other.furigana(options)
11
11
  end
12
12
  end
13
13
  end
@@ -11,10 +11,10 @@ module Enumerable
11
11
  # @yieldparam b [String] The second string to compare.
12
12
  # @return [Array<String>] The sorted array.
13
13
  # @raise [ArgumentError] If no block is given and any element is not a String.
14
- def jisho_sort(&block)
14
+ def jisho_sort(options = {}, &block)
15
15
  raise ArgumentError if block.nil? && !all? { |item| item.instance_of?(String) }
16
16
 
17
- return sort { |a, b| a.compare_by_furigana(b) } if block.nil?
17
+ return sort { |a, b| a.compare_by_furigana(b, options) } if block.nil?
18
18
 
19
19
  sort(&block)
20
20
  end
@@ -26,9 +26,9 @@ module Enumerable
26
26
  # @yieldreturn [String] The string whose japanese pronunciation will be used for sorting.
27
27
  # @return [Array] A new array with the elements sorted by the japanese pronunciation of the strings.
28
28
  # @raise [ArgumentError] If any element does not yield a String.
29
- def jisho_sort_by
29
+ def jisho_sort_by(options = {})
30
30
  raise ArgumentError unless all? { |item| yield(item).instance_of?(String) }
31
31
 
32
- sort_by{ |item| yield(item).furigana }
32
+ sort_by { |item| yield(item).furigana(options) }
33
33
  end
34
34
  end
@@ -3,24 +3,23 @@ require 'natto'
3
3
  module JishoSort
4
4
  module Tokenizable
5
5
  NATTO_KATAKANA_TYPE = 7
6
- NATTO_FURIGANA_INDEX = 7
7
6
 
8
- def furigana
9
- tokenize
7
+ def furigana(options = {})
8
+ tokenize(options)
10
9
  end
11
10
 
12
11
  private
13
12
 
14
- def tokenize
15
- call_natto_parser
13
+ def tokenize(options = {})
14
+ call_natto_parser(options)
16
15
  end
17
16
 
18
- def call_natto_parser
17
+ def call_natto_parser(options = {})
19
18
  strings = separate_ascii_string_from_others
20
19
 
21
20
  # Extract the elements of furigana within this gem.
22
21
  # When specifying a format in the argument of Natto::MeCab.new, the error `MECAB_NBEST request type is not set (Natto::MeCabError)` occurs.
23
- nm = Natto::MeCab.new
22
+ nm = Natto::MeCab.new(options.merge({ output_format_type: :yomi }))
24
23
  memo = []
25
24
  strings.each do |s|
26
25
  next memo << s if s.ascii_only?
@@ -29,9 +28,7 @@ module JishoSort
29
28
  next if n.is_eos?
30
29
  next memo << n.surface if n.char_type == NATTO_KATAKANA_TYPE
31
30
 
32
- n_furigana = n.feature.split(',')[NATTO_FURIGANA_INDEX]
33
-
34
- memo << n_furigana
31
+ memo << n.feature
35
32
  end
36
33
  end
37
34
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jisho_sort
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - fvknk97034