j-law-ruby 0.0.3-arm64-darwin-23
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 +7 -0
- data/README.md +109 -0
- data/lib/j_law_ruby/build_support.rb +129 -0
- data/lib/j_law_ruby/c_ffi.rb +662 -0
- data/lib/j_law_ruby/native/libj_law_c_ffi.dylib +0 -0
- data/lib/j_law_ruby.rb +532 -0
- metadata +67 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: c2ba61bed3130192d5b8df9f58dc7002729fecaaf9d536b2c4425578ded90f74
|
|
4
|
+
data.tar.gz: 1047e5e69952e609072899b6abfc26fb25ba94a2d2b3d9d8a9cb8eba1a427408
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 5049ca6b3b91621c57fc8f260dfdc803f8fc957682db07eb2122572f20a94043789715ee878bf239346e36267ddb8d346532b27ffe4dbe43741f619ce8359de8
|
|
7
|
+
data.tar.gz: 337db412a37f7f7476ffc8671f446ba5f47406c3ed172eb65b95d3ce61ac8d597fa158ba8123a99a213afef82eecfc78333e44e87ebc2508b534a10d726b1d70
|
data/README.md
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# j_law_ruby
|
|
2
|
+
|
|
3
|
+
日本法令計算の PoC を Ruby から試すためのバインディングです。
|
|
4
|
+
|
|
5
|
+
内部では `j-law-c-ffi` の C ABI を `ffi` gem 経由で呼び出し、Rust コアの整数演算ロジックを Ruby から利用します。
|
|
6
|
+
|
|
7
|
+
> [!WARNING]
|
|
8
|
+
> **PoC / アルファ版に関する注意事項**
|
|
9
|
+
>
|
|
10
|
+
> - 本ライブラリは現在 **`v0.0.1` のアルファ版**です。API と配布形態は予告なく変更される場合があります。
|
|
11
|
+
> - この binding が返す計算結果について、法的正確性、完全性、最新性、個別事案への適合性は保証しません。
|
|
12
|
+
> - コードの一部には **AI 生成 / AI 補助**による実装が含まれ、人手による全面レビューは完了していません。
|
|
13
|
+
> - 税務申告や契約実務の唯一の根拠として使用せず、一次資料と専門家で検証してください。
|
|
14
|
+
> - 詳細は [プロジェクトステータスと免責](../../docs/project-status.md) を参照してください。
|
|
15
|
+
|
|
16
|
+
## 対応機能
|
|
17
|
+
|
|
18
|
+
- `JLawRuby::ConsumptionTax.calc_consumption_tax`
|
|
19
|
+
- `JLawRuby::RealEstate.calc_brokerage_fee`
|
|
20
|
+
- `JLawRuby::IncomeTax.calc_income_tax`
|
|
21
|
+
- `JLawRuby::IncomeTax.calc_income_deductions`
|
|
22
|
+
- `JLawRuby::IncomeTax.calc_income_tax_assessment`
|
|
23
|
+
- `JLawRuby::StampTax.calc_stamp_tax`
|
|
24
|
+
- `JLawRuby::WithholdingTax.calc_withholding_tax`
|
|
25
|
+
|
|
26
|
+
## インストール
|
|
27
|
+
|
|
28
|
+
CI と publish workflow で検証している Ruby の範囲は `3.1` から `4.0` です。
|
|
29
|
+
RubyGems では `linux/x86_64` `linux/aarch64` `macos/x86_64` `macos/arm64` `windows/amd64`
|
|
30
|
+
向けの build 済み platform gem を配布します。これらの環境では Rust toolchain は不要です。
|
|
31
|
+
その他の環境では source gem にフォールバックし、`gem install` 時に Rust `1.94.0`
|
|
32
|
+
toolchain を使って `j-law-c-ffi` をビルドします。
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
gem install j_law_ruby
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
source gem を明示的に使う場合は次を実行します。
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
gem install j_law_ruby --platform ruby
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
開発環境では次を実行します。
|
|
45
|
+
|
|
46
|
+
```sh
|
|
47
|
+
cd crates/j-law-ruby
|
|
48
|
+
bundle install
|
|
49
|
+
bundle exec rake compile
|
|
50
|
+
bundle exec rake test
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## クイックスタート
|
|
54
|
+
|
|
55
|
+
```ruby
|
|
56
|
+
require "date"
|
|
57
|
+
require "j_law_ruby"
|
|
58
|
+
|
|
59
|
+
date = Date.new(2024, 8, 1)
|
|
60
|
+
|
|
61
|
+
puts JLawRuby::ConsumptionTax.calc_consumption_tax(100_000, Date.new(2024, 1, 1), false).tax_amount
|
|
62
|
+
puts JLawRuby::RealEstate.calc_brokerage_fee(5_000_000, date, false, false).total_with_tax
|
|
63
|
+
|
|
64
|
+
assessment = JLawRuby::IncomeTax.calc_income_tax_assessment(
|
|
65
|
+
8_000_000,
|
|
66
|
+
Date.new(2024, 1, 1),
|
|
67
|
+
social_insurance_premium_paid: 600_000
|
|
68
|
+
)
|
|
69
|
+
puts assessment.tax.total_tax
|
|
70
|
+
|
|
71
|
+
puts JLawRuby::StampTax.calc_stamp_tax(:article1_real_estate_transfer, 5_000_000, date).tax_amount
|
|
72
|
+
|
|
73
|
+
puts JLawRuby::WithholdingTax.calc_withholding_tax(
|
|
74
|
+
1_500_000,
|
|
75
|
+
Date.new(2026, 1, 1),
|
|
76
|
+
:professional_fee
|
|
77
|
+
).tax_amount
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## API メモ
|
|
81
|
+
|
|
82
|
+
- すべての金額は整数円です。
|
|
83
|
+
- すべての API は `Date` / `DateTime` を受け取り、型不一致は `TypeError` を送出します。
|
|
84
|
+
- 法令適用外日付や入力不正は `RuntimeError` を送出します。
|
|
85
|
+
- `calc_stamp_tax()` の `document_code` / `flags` は `Symbol` または `String` を受け取ります。
|
|
86
|
+
- `calc_withholding_tax()` の `category` は `:manuscript_and_lecture` / `:professional_fee` / `:exclusive_contract_fee` などを指定します。
|
|
87
|
+
|
|
88
|
+
## Gem ビルド
|
|
89
|
+
|
|
90
|
+
```sh
|
|
91
|
+
cd crates/j-law-ruby
|
|
92
|
+
bundle install
|
|
93
|
+
bundle exec rake build_source_gem
|
|
94
|
+
bundle exec rake build_binary_gem
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
`rake build` は `build_source_gem` のエイリアスです。
|
|
98
|
+
`build_source_gem` は source gem 用に必要な Rust ソースを `vendor/rust/` へ同期してから gem を生成します。
|
|
99
|
+
`build_binary_gem` は共有ライブラリを事前にビルドして、platform gem に同梱します。
|
|
100
|
+
|
|
101
|
+
## 関連ドキュメント
|
|
102
|
+
|
|
103
|
+
- [プロジェクトステータスと免責](../../docs/project-status.md)
|
|
104
|
+
- [リポジトリ README](../../README.md)
|
|
105
|
+
- [利用ガイド](../../docs/usage.md)
|
|
106
|
+
|
|
107
|
+
## ライセンス
|
|
108
|
+
|
|
109
|
+
[MIT License](../../LICENSE)
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "rbconfig"
|
|
4
|
+
|
|
5
|
+
module JLawRuby
|
|
6
|
+
module BuildSupport
|
|
7
|
+
module_function
|
|
8
|
+
|
|
9
|
+
BINARY_GEM_ENV = "JLAW_RUBY_BINARY_GEM"
|
|
10
|
+
FORCE_CARGO_BUILD_ENV = "JLAW_RUBY_FORCE_CARGO_BUILD"
|
|
11
|
+
|
|
12
|
+
def cargo_profile
|
|
13
|
+
ENV.fetch("JLAW_RUBY_CARGO_PROFILE", "release")
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def binary_gem_build?
|
|
17
|
+
ENV[BINARY_GEM_ENV] == "1"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def force_cargo_build?
|
|
21
|
+
ENV[FORCE_CARGO_BUILD_ENV] == "1"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def gem_platform
|
|
25
|
+
require "rubygems/platform"
|
|
26
|
+
|
|
27
|
+
Gem::Platform.local
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def make_command
|
|
31
|
+
RbConfig::CONFIG.fetch("MAKE", "make")
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def shared_library_filename
|
|
35
|
+
case RbConfig::CONFIG["host_os"]
|
|
36
|
+
when /mswin|mingw|cygwin/
|
|
37
|
+
"j_law_c_ffi.dll"
|
|
38
|
+
when /darwin/
|
|
39
|
+
"libj_law_c_ffi.dylib"
|
|
40
|
+
else
|
|
41
|
+
"libj_law_c_ffi.so"
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def native_dir(gem_root)
|
|
46
|
+
File.join(gem_root, "lib", "j_law_ruby", "native")
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def packaged_shared_library_path(gem_root)
|
|
50
|
+
File.join(native_dir(gem_root), shared_library_filename)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def packaged_shared_library?(gem_root)
|
|
54
|
+
File.file?(packaged_shared_library_path(gem_root))
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def vendored_workspace_root(gem_root)
|
|
58
|
+
File.join(gem_root, "vendor", "rust")
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def vendored_manifest_path(gem_root)
|
|
62
|
+
File.join(vendored_workspace_root(gem_root), "Cargo.toml")
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def repo_workspace_root(gem_root)
|
|
66
|
+
File.expand_path("../..", gem_root)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def repo_manifest_path(gem_root)
|
|
70
|
+
File.join(repo_workspace_root(gem_root), "Cargo.toml")
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def manifest_path(gem_root)
|
|
74
|
+
vendored_manifest = vendored_manifest_path(gem_root)
|
|
75
|
+
return vendored_manifest if File.file?(vendored_manifest)
|
|
76
|
+
|
|
77
|
+
repo_manifest = repo_manifest_path(gem_root)
|
|
78
|
+
return repo_manifest if File.file?(repo_manifest)
|
|
79
|
+
|
|
80
|
+
nil
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def built_shared_library_path(manifest_path, profile)
|
|
84
|
+
File.join(File.dirname(manifest_path), "target", profile, shared_library_filename)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def shared_library_candidates(gem_root)
|
|
88
|
+
candidates = []
|
|
89
|
+
env_path = ENV["JLAW_RUBY_C_FFI_LIB"]
|
|
90
|
+
candidates << env_path unless env_path.nil? || env_path.empty?
|
|
91
|
+
candidates << packaged_shared_library_path(gem_root)
|
|
92
|
+
|
|
93
|
+
[vendored_manifest_path(gem_root), repo_manifest_path(gem_root)].each do |manifest|
|
|
94
|
+
next unless File.file?(manifest)
|
|
95
|
+
|
|
96
|
+
candidates << built_shared_library_path(manifest, "release")
|
|
97
|
+
candidates << built_shared_library_path(manifest, "debug")
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
candidates.uniq
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def resolve_shared_library_path(gem_root)
|
|
104
|
+
shared_library_candidates(gem_root).find { |path| File.file?(path) }
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def should_build_shared_library?(gem_root)
|
|
108
|
+
return true if force_cargo_build?
|
|
109
|
+
|
|
110
|
+
!packaged_shared_library?(gem_root)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def write_stub_makefile(path = "Makefile")
|
|
114
|
+
File.write(
|
|
115
|
+
path,
|
|
116
|
+
<<~MAKEFILE
|
|
117
|
+
all:
|
|
118
|
+
\t@true
|
|
119
|
+
|
|
120
|
+
install:
|
|
121
|
+
\t@true
|
|
122
|
+
|
|
123
|
+
clean:
|
|
124
|
+
\t@true
|
|
125
|
+
MAKEFILE
|
|
126
|
+
)
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
end
|