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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7aa5c7a720c07edaca1106bb0d03fed3c3f2b878ac85d8e15f3caa0c81334e98
4
- data.tar.gz: 49f88b1bf2389574bebe53bcf61daffd85db84b3fc6d52fd06bf11561079335a
3
+ metadata.gz: acad0974c78fe7cac1841d823ea439e671a69eb3dad915ef8adcfcfdd0f4fdda
4
+ data.tar.gz: 4bfc100695a36d2d22fc68295fa8cf0441d2e7bba02e2b300b06949e079ce87a
5
5
  SHA512:
6
- metadata.gz: 5c41fbd306450e975f89397db4083dac2619aa4530a2e0c8e0f76a5cc048ea8b9f872db3ea0fe5ebe90e6f60f9abfcb47f5de34fe39508a2f3270a0262da80ef
7
- data.tar.gz: 320087ecb218ff8ebfa57d3d45372f5a172d259a557068f63b56d3312e81c40a597a53fa3091e8be51b4b3b6f3ed813f54b17205b97c28db6a2b8124f922e2e1
6
+ metadata.gz: a19ce621920fa07fb6905f96891aeb26cb05987c8e5e6467042258ee94463fb9e6254b68fe7245d629a1ab7f929c1a711e446fbbf875574302e081fae0339e5f
7
+ data.tar.gz: b82e68c6a79e5fb0360abf73b1989bd95e012a6e6adac69411fa1672cac9709227b2e0a268e3c7319dc5406bb14da7bcafc7c47a7ded18658fa9a6df33c78e71
data/.envrc ADDED
@@ -0,0 +1,2 @@
1
+ watch_file manifest.scm
2
+ use guix
data/.gitignore CHANGED
@@ -10,3 +10,5 @@
10
10
 
11
11
  # rspec failure tracking
12
12
  .rspec_status
13
+
14
+ /sig/miyabi.gen.rbs
data/.rubocop.yml CHANGED
@@ -3,6 +3,7 @@ inherit_from: .rubocop_todo.yml
3
3
  AllCops:
4
4
  NewCops: enable
5
5
  TargetRubyVersion: 3.0
6
+ DisabledByDefault: true
6
7
 
7
8
  Style/FrozenStringLiteralComment:
8
9
  Enabled: true
data/.rubocop_todo.yml CHANGED
@@ -1,28 +1,7 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2023-05-13 02:36:18 UTC using RuboCop version 1.50.2.
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
@@ -1,6 +1,7 @@
1
1
  The MIT License (MIT)
2
2
 
3
3
  Copyright (c) 2017 Hironori Akaishi
4
+ Copyright (c) 2023, 2024, 2025 gemmaro
4
5
 
5
6
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
7
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -45,7 +45,7 @@ require 'miyabi'
45
45
 
46
46
  ## Development
47
47
 
48
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
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 GitHub at https://github.com/h-akaishi/miyabi. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
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 rooms and mailing lists is expected to follow the [code of conduct](https://github.com/h-akaishi/miyabi/blob/master/CODE_OF_CONDUCT.md).
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
@@ -4,3 +4,7 @@ require 'rspec/core/rake_task'
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
6
  task default: :spec
7
+
8
+ task :gensig do
9
+ sh 'typeprof', '-r', 'nokogiri', '-o', 'sig/miyabi.gen.rbs', 'sig/miyabi.rbs', *Dir['lib/**/*.rb']
10
+ end
data/TODO.org ADDED
@@ -0,0 +1,2 @@
1
+ * TODO jaconvを参考にする
2
+ https://github.com/ikegami-yukino/jaconv/blob/b82abca9d8e29c3cad33825926900bea6c7e170f/test_jaconv.py#L44
data/lib/check.rb CHANGED
@@ -1,4 +1,4 @@
1
- require_relative "miyabi/check_string"
1
+ require_relative 'miyabi/check_string'
2
2
 
3
3
  class String
4
4
  include ::Miyabi::CheckString
data/lib/format.rb CHANGED
@@ -1,4 +1,4 @@
1
- require_relative "miyabi/format_string"
1
+ require_relative 'miyabi/format_string'
2
2
 
3
3
  class String
4
4
  include ::Miyabi::FormatString
@@ -1,40 +1,39 @@
1
1
  module Miyabi
2
2
  module CheckString
3
- def is_hira?
3
+ def hiragana?
4
4
  return true if self =~ /\p{hiragana}/
5
5
  false
6
6
  end
7
7
 
8
- alias hiragana? is_hira?
9
- alias hira? is_hira?
8
+ alias is_hira? hiragana?
9
+ alias hira? hiragana?
10
10
 
11
- def is_japanese?
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 japanese? is_japanese?
16
+ alias is_japanese? japanese?
17
17
 
18
- def is_kana?
18
+ def katakana?
19
19
  return true if self =~ /\p{katakana}/
20
20
  false
21
21
  end
22
22
 
23
- alias katakana? is_kana?
24
- # alias kana? is_kana?
23
+ alias is_kana? katakana?
25
24
 
26
- def is_kanji?
25
+ def kanji?
27
26
  return true if self =~ /^[一-龥]+$/
28
27
  false
29
28
  end
30
29
 
31
- alias kanji? is_kanji?
30
+ alias is_kanji? kanji?
32
31
 
33
- def is_roman?
32
+ def roman?
34
33
  return true if self =~ /^[a-zA-Z]+$/
35
34
  false
36
35
  end
37
36
 
38
- alias roman? is_roman?
37
+ alias is_roman? roman?
39
38
  end
40
39
  end
@@ -1,30 +1,38 @@
1
- require 'net/http'
2
- require 'nokogiri'
1
+ require "set"
3
2
 
4
3
  module Miyabi
5
4
  module FormatString
6
- def to_kanhira
7
- http = Net::HTTP.new('yomikatawa.com', 443)
8
- http.use_ssl = true
9
- path = File.join('/kanji', self)
10
- html = http.get(path).body
11
- Nokogiri::HTML(html).search('#yomikata tbody tr td').first.inner_text
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
- def to_kana
15
- self.tr('ぁ-ん','ァ-ン')
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 to_katakana to_kana
25
+ alias to_hira katakana_to_hiragana
26
+ alias to_hiragana katakana_to_hiragana
19
27
 
20
- def to_hira
21
- self.tr('ァ-ン','ぁ-ん')
22
- end
28
+ TR_HIRAGANA = 'ぁ-んゔゕゖゝゞ'
29
+ private_constant :TR_HIRAGANA
23
30
 
24
- alias to_hiragana to_hira
31
+ TR_KATAKANA = 'ァ-ンヴヵヶヽヾ'
32
+ private_constant :TR_KATAKANA
25
33
 
26
34
  def to_roman
27
- s = to_kana
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
@@ -1,3 +1,3 @@
1
1
  module Miyabi
2
- VERSION = '0.3.0'
2
+ VERSION = '0.4.0'
3
3
  end
data/manifest.scm CHANGED
@@ -1,11 +1,5 @@
1
- (use-modules (guix packages)
2
- (gnu packages ruby))
3
-
4
- (define-public ruby-nokogiri'
5
- (package
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/isy/miyabi'
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
- spec.add_dependency 'nokogiri', '~> 1.14'
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.3.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: 2023-06-26 00:00:00.000000000 Z
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
- - bin/console
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
- homepage: https://github.com/isy/miyabi
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.4.10
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
@@ -1,5 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.3.4
5
- before_install: gem install bundler -v 1.15.4
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__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here