miyabi 0.3.0 → 0.4.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/.envrc +2 -0
- data/.gitignore +2 -0
- data/.rubocop.yml +1 -0
- data/.rubocop_todo.yml +1 -22
- data/CHANGELOG.md +16 -0
- data/LICENSE.txt +1 -0
- data/README.md +13 -3
- data/Rakefile +4 -0
- data/TODO.org +2 -0
- data/lib/check.rb +1 -1
- data/lib/format.rb +1 -1
- data/lib/miyabi/check_string.rb +11 -12
- data/lib/miyabi/format_string.rb +37 -17
- data/lib/miyabi/format_string_online.rb +16 -0
- data/lib/miyabi/version.rb +1 -1
- data/manifest.scm +5 -11
- data/miyabi.gemspec +4 -4
- data/sig/miyabi.rbs +36 -0
- metadata +10 -21
- data/.travis.yml +0 -5
- data/bin/console +0 -14
- data/bin/setup +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: acad0974c78fe7cac1841d823ea439e671a69eb3dad915ef8adcfcfdd0f4fdda
|
4
|
+
data.tar.gz: 4bfc100695a36d2d22fc68295fa8cf0441d2e7bba02e2b300b06949e079ce87a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a19ce621920fa07fb6905f96891aeb26cb05987c8e5e6467042258ee94463fb9e6254b68fe7245d629a1ab7f929c1a711e446fbbf875574302e081fae0339e5f
|
7
|
+
data.tar.gz: b82e68c6a79e5fb0360abf73b1989bd95e012a6e6adac69411fa1672cac9709227b2e0a268e3c7319dc5406bb14da7bcafc7c47a7ded18658fa9a6df33c78e71
|
data/.envrc
ADDED
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/.rubocop_todo.yml
CHANGED
@@ -1,28 +1,7 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on
|
3
|
+
# on 2025-04-08 11:38:33 UTC using RuboCop version 1.48.1.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
7
7
|
# versions of RuboCop, may require this file to be generated again.
|
8
|
-
|
9
|
-
# Offense count: 5
|
10
|
-
# Configuration parameters: NamePrefix, ForbiddenPrefixes, AllowedMethods, MethodDefinitionMacros.
|
11
|
-
# NamePrefix: is_, has_, have_
|
12
|
-
# ForbiddenPrefixes: is_, has_, have_
|
13
|
-
# AllowedMethods: is_a?
|
14
|
-
# MethodDefinitionMacros: define_method, define_singleton_method
|
15
|
-
Naming/PredicateName:
|
16
|
-
Exclude:
|
17
|
-
- 'spec/**/*'
|
18
|
-
- 'lib/check.rb'
|
19
|
-
|
20
|
-
# Offense count: 3
|
21
|
-
# Configuration parameters: AllowedConstants.
|
22
|
-
Style/Documentation:
|
23
|
-
Exclude:
|
24
|
-
- 'spec/**/*'
|
25
|
-
- 'test/**/*'
|
26
|
-
- 'lib/check.rb'
|
27
|
-
- 'lib/format.rb'
|
28
|
-
- 'lib/miyabi.rb'
|
data/CHANGELOG.md
CHANGED
@@ -9,6 +9,22 @@ The format is based on [Keep a Changelog][cl], and this project adheres to [Sema
|
|
9
9
|
|
10
10
|
## [Unreleased]
|
11
11
|
|
12
|
+
## 0.4.0
|
13
|
+
|
14
|
+
Make `to_kanhira` method optional. If you still need this, install Nokogiri gem and:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
require "miyabi/format_string_online"
|
18
|
+
String.include(Miyabi::FormatStringOnline)
|
19
|
+
```
|
20
|
+
|
21
|
+
## 0.3.1
|
22
|
+
|
23
|
+
This is a maintenance release.
|
24
|
+
|
25
|
+
* Lint source codes.
|
26
|
+
* Add RBS file.
|
27
|
+
|
12
28
|
## [0.3.0]
|
13
29
|
|
14
30
|
### Added
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -45,7 +45,7 @@ require 'miyabi'
|
|
45
45
|
|
46
46
|
## Development
|
47
47
|
|
48
|
-
|
48
|
+
Run `rake spec` to run the tests.
|
49
49
|
|
50
50
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
51
51
|
|
@@ -53,7 +53,11 @@ If you use the GNU Guix, `guix shell` to enter the development environment, then
|
|
53
53
|
|
54
54
|
## Contributing
|
55
55
|
|
56
|
-
Bug reports and pull requests are welcome on
|
56
|
+
Bug reports and pull requests are welcome on
|
57
|
+
[GitHub](https://github.com/gemmaro/miyabi). This project is intended to be a
|
58
|
+
safe, welcoming space for collaboration, and contributors are expected to
|
59
|
+
adhere to the [Contributor Covenant](http://contributor-covenant.org) code of
|
60
|
+
conduct.
|
57
61
|
|
58
62
|
## License
|
59
63
|
|
@@ -61,4 +65,10 @@ The gem is available as open source under the terms of the [MIT License](http://
|
|
61
65
|
|
62
66
|
## Code of Conduct
|
63
67
|
|
64
|
-
Everyone interacting in the Miyabi project’s codebases, issue trackers, chat
|
68
|
+
Everyone interacting in the Miyabi project’s codebases, issue trackers, chat
|
69
|
+
rooms and mailing lists is expected to follow the [code of
|
70
|
+
conduct](https://github.com/gemmaro/miyabi/blob/master/CODE_OF_CONDUCT.md).
|
71
|
+
|
72
|
+
## Related Works
|
73
|
+
|
74
|
+
[jaconv](https://github.com/ikegami-yukino/jaconv) (Python library)
|
data/Rakefile
CHANGED
data/TODO.org
ADDED
data/lib/check.rb
CHANGED
data/lib/format.rb
CHANGED
data/lib/miyabi/check_string.rb
CHANGED
@@ -1,40 +1,39 @@
|
|
1
1
|
module Miyabi
|
2
2
|
module CheckString
|
3
|
-
def
|
3
|
+
def hiragana?
|
4
4
|
return true if self =~ /\p{hiragana}/
|
5
5
|
false
|
6
6
|
end
|
7
7
|
|
8
|
-
alias
|
9
|
-
alias hira?
|
8
|
+
alias is_hira? hiragana?
|
9
|
+
alias hira? hiragana?
|
10
10
|
|
11
|
-
def
|
11
|
+
def japanese?
|
12
12
|
return true if self =~ /\A(?:\p{Hiragana}|\p{Katakana}|[ー-]|[一-龠々])+\z/
|
13
13
|
false
|
14
14
|
end
|
15
15
|
|
16
|
-
alias
|
16
|
+
alias is_japanese? japanese?
|
17
17
|
|
18
|
-
def
|
18
|
+
def katakana?
|
19
19
|
return true if self =~ /\p{katakana}/
|
20
20
|
false
|
21
21
|
end
|
22
22
|
|
23
|
-
alias
|
24
|
-
# alias kana? is_kana?
|
23
|
+
alias is_kana? katakana?
|
25
24
|
|
26
|
-
def
|
25
|
+
def kanji?
|
27
26
|
return true if self =~ /^[一-龥]+$/
|
28
27
|
false
|
29
28
|
end
|
30
29
|
|
31
|
-
alias
|
30
|
+
alias is_kanji? kanji?
|
32
31
|
|
33
|
-
def
|
32
|
+
def roman?
|
34
33
|
return true if self =~ /^[a-zA-Z]+$/
|
35
34
|
false
|
36
35
|
end
|
37
36
|
|
38
|
-
alias
|
37
|
+
alias is_roman? roman?
|
39
38
|
end
|
40
39
|
end
|
data/lib/miyabi/format_string.rb
CHANGED
@@ -1,30 +1,38 @@
|
|
1
|
-
require
|
2
|
-
require 'nokogiri'
|
1
|
+
require "set"
|
3
2
|
|
4
3
|
module Miyabi
|
5
4
|
module FormatString
|
6
|
-
def
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
def hiragana_to_katakana(ignore: nil)
|
6
|
+
ignored = ignore ? ignore.chars.to_set : Set[]
|
7
|
+
result = +""
|
8
|
+
chars.each do |char|
|
9
|
+
if ignored.member?(char)
|
10
|
+
result << char
|
11
|
+
else
|
12
|
+
result << char.tr(TR_HIRAGANA, TR_KATAKANA)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
result
|
12
16
|
end
|
13
17
|
|
14
|
-
|
15
|
-
|
18
|
+
alias to_kana hiragana_to_katakana
|
19
|
+
alias to_katakana hiragana_to_katakana
|
20
|
+
|
21
|
+
def katakana_to_hiragana
|
22
|
+
tr(TR_KATAKANA, TR_HIRAGANA)
|
16
23
|
end
|
17
24
|
|
18
|
-
alias
|
25
|
+
alias to_hira katakana_to_hiragana
|
26
|
+
alias to_hiragana katakana_to_hiragana
|
19
27
|
|
20
|
-
|
21
|
-
|
22
|
-
end
|
28
|
+
TR_HIRAGANA = 'ぁ-んゔゕゖゝゞ'
|
29
|
+
private_constant :TR_HIRAGANA
|
23
30
|
|
24
|
-
|
31
|
+
TR_KATAKANA = 'ァ-ンヴヵヶヽヾ'
|
32
|
+
private_constant :TR_KATAKANA
|
25
33
|
|
26
34
|
def to_roman
|
27
|
-
s =
|
35
|
+
s = hiragana_to_katakana
|
28
36
|
KATAKANA_TO_ROMAN_MAPPING.each do |kana, roman|
|
29
37
|
s.gsub!(kana, roman)
|
30
38
|
end
|
@@ -151,9 +159,21 @@ module Miyabi
|
|
151
159
|
'ペ' => 'pe',
|
152
160
|
'ポ' => 'po',
|
153
161
|
'ヴ' => 'vu',
|
154
|
-
'ー' => '-'
|
162
|
+
'ー' => '-'
|
155
163
|
}
|
156
164
|
|
157
165
|
private_constant :KATAKANA_TO_ROMAN_MAPPING
|
166
|
+
|
167
|
+
def roman_to_katakana
|
168
|
+
str = dup
|
169
|
+
ROMAN_TO_KATAKANA_MAPPING.each do |roman, kana|
|
170
|
+
str.gsub!(kana, roman)
|
171
|
+
end
|
172
|
+
str
|
173
|
+
end
|
174
|
+
|
175
|
+
ROMAN_TO_KATAKANA_MAPPING = KATAKANA_TO_ROMAN_MAPPING.invert
|
176
|
+
|
177
|
+
private_constant :ROMAN_TO_KATAKANA_MAPPING
|
158
178
|
end
|
159
179
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'nokogiri'
|
3
|
+
|
4
|
+
module Miyabi::FormatStringOnline
|
5
|
+
def to_kanhira
|
6
|
+
http = Net::HTTP.new('yomikatawa.com', 443)
|
7
|
+
http.use_ssl = true
|
8
|
+
path = File.join('/kanji', self)
|
9
|
+
html = http.get(path).body
|
10
|
+
Nokogiri::HTML(html).search('#yomikata tbody tr td').first.inner_text
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module Miyabi
|
15
|
+
deprecate_constant :FormatStringOnline
|
16
|
+
end
|
data/lib/miyabi/version.rb
CHANGED
data/manifest.scm
CHANGED
@@ -1,11 +1,5 @@
|
|
1
|
-
(use-modules (
|
2
|
-
(gnu packages ruby)
|
3
|
-
|
4
|
-
(
|
5
|
-
|
6
|
-
(inherit ruby-nokogiri)
|
7
|
-
(arguments
|
8
|
-
(cons* #:ruby ruby-3.2
|
9
|
-
(package-arguments ruby-nokogiri)))))
|
10
|
-
|
11
|
-
(packages->manifest (list ruby-nokogiri' ruby-rspec ruby-3.2))
|
1
|
+
(use-modules (gnu packages ruby)
|
2
|
+
(gnu packages ruby-xyz)
|
3
|
+
(gnu packages ruby-check)
|
4
|
+
(guix profiles))
|
5
|
+
(packages->manifest (list ruby-nokogiri ruby-rspec ruby-3.1 ruby-rubocop))
|
data/miyabi.gemspec
CHANGED
@@ -5,12 +5,12 @@ require 'miyabi/version'
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = 'miyabi'
|
7
7
|
spec.version = Miyabi::VERSION
|
8
|
-
spec.authors = ['Hironori Akaishi']
|
9
|
-
spec.email = ['ah.gm3622@gmail.com']
|
8
|
+
spec.authors = ['Hironori Akaishi', 'gemmaro']
|
9
|
+
spec.email = ['ah.gm3622@gmail.com', 'gemmaro.dev@gmail.com']
|
10
10
|
|
11
11
|
spec.summary = 'kana,hira,kanji formatter'
|
12
12
|
spec.description = 'Format Japanese characters'
|
13
|
-
spec.homepage = 'https://github.com/
|
13
|
+
spec.homepage = 'https://github.com/gemmaro/miyabi'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
spec.metadata['rubygems_mfa_required'] = 'true'
|
16
16
|
|
@@ -20,6 +20,6 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.require_paths = ['lib']
|
21
21
|
|
22
22
|
spec.required_ruby_version = '>= 3.0'
|
23
|
-
|
23
|
+
|
24
24
|
spec.add_development_dependency 'rspec', '~> 3.12'
|
25
25
|
end
|
data/sig/miyabi.rbs
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# TypeProf 0.21.3
|
2
|
+
|
3
|
+
# Classes
|
4
|
+
class String
|
5
|
+
include Miyabi::FormatString
|
6
|
+
include Miyabi::CheckString
|
7
|
+
end
|
8
|
+
|
9
|
+
module Miyabi
|
10
|
+
VERSION: String
|
11
|
+
|
12
|
+
module CheckString
|
13
|
+
def hiragana?: -> bool
|
14
|
+
alias is_hira? hiragana?
|
15
|
+
alias hira? hiragana?
|
16
|
+
def japanese?: -> bool
|
17
|
+
alias is_japanese? japanese?
|
18
|
+
def katakana?: -> bool
|
19
|
+
alias is_kana? katakana?
|
20
|
+
def kanji?: -> bool
|
21
|
+
alias is_kanji? kanji?
|
22
|
+
def roman?: -> bool
|
23
|
+
alias is_roman? roman?
|
24
|
+
end
|
25
|
+
|
26
|
+
module FormatString
|
27
|
+
KATAKANA_TO_ROMAN_MAPPING: Hash[String, String]
|
28
|
+
|
29
|
+
def to_kanhira: -> String
|
30
|
+
def to_kana: -> String
|
31
|
+
alias to_katakana to_kana
|
32
|
+
def to_hira: -> String
|
33
|
+
alias to_hiragana to_hira
|
34
|
+
def to_roman: -> String
|
35
|
+
end
|
36
|
+
end
|
metadata
CHANGED
@@ -1,29 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: miyabi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hironori Akaishi
|
8
|
+
- gemmaro
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2025-07-21 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: nokogiri
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.14'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.14'
|
27
14
|
- !ruby/object:Gem::Dependency
|
28
15
|
name: rspec
|
29
16
|
requirement: !ruby/object:Gem::Requirement
|
@@ -41,32 +28,34 @@ dependencies:
|
|
41
28
|
description: Format Japanese characters
|
42
29
|
email:
|
43
30
|
- ah.gm3622@gmail.com
|
31
|
+
- gemmaro.dev@gmail.com
|
44
32
|
executables: []
|
45
33
|
extensions: []
|
46
34
|
extra_rdoc_files: []
|
47
35
|
files:
|
36
|
+
- ".envrc"
|
48
37
|
- ".gitignore"
|
49
38
|
- ".rspec"
|
50
39
|
- ".rubocop.yml"
|
51
40
|
- ".rubocop_todo.yml"
|
52
|
-
- ".travis.yml"
|
53
41
|
- CHANGELOG.md
|
54
42
|
- CODE_OF_CONDUCT.md
|
55
43
|
- Gemfile
|
56
44
|
- LICENSE.txt
|
57
45
|
- README.md
|
58
46
|
- Rakefile
|
59
|
-
-
|
60
|
-
- bin/setup
|
47
|
+
- TODO.org
|
61
48
|
- lib/check.rb
|
62
49
|
- lib/format.rb
|
63
50
|
- lib/miyabi.rb
|
64
51
|
- lib/miyabi/check_string.rb
|
65
52
|
- lib/miyabi/format_string.rb
|
53
|
+
- lib/miyabi/format_string_online.rb
|
66
54
|
- lib/miyabi/version.rb
|
67
55
|
- manifest.scm
|
68
56
|
- miyabi.gemspec
|
69
|
-
|
57
|
+
- sig/miyabi.rbs
|
58
|
+
homepage: https://github.com/gemmaro/miyabi
|
70
59
|
licenses:
|
71
60
|
- MIT
|
72
61
|
metadata:
|
@@ -86,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
75
|
- !ruby/object:Gem::Version
|
87
76
|
version: '0'
|
88
77
|
requirements: []
|
89
|
-
rubygems_version: 3.
|
78
|
+
rubygems_version: 3.3.27
|
90
79
|
signing_key:
|
91
80
|
specification_version: 4
|
92
81
|
summary: kana,hira,kanji formatter
|
data/.travis.yml
DELETED
data/bin/console
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'bundler/setup'
|
4
|
-
require 'miyabi'
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require 'irb'
|
14
|
-
IRB.start(__FILE__)
|