asa_json 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7ebf54877ef33a90f2cdfb68542fb9dd5c957d5a5d7a361ef1385229de355df3
4
+ data.tar.gz: 6894d8dc2b150798be29ca6afb1cf45e7a44a10bf22e5b0fa668dd5cd1c337cc
5
+ SHA512:
6
+ metadata.gz: cc8e2878f2d97945e44b4525ef84da376726fa2056ad8270db585caa971c4b301304c625054f4704acecda79bec12f7b949a31963bd4e7b85202e4395ac7bc21
7
+ data.tar.gz: b2d5b35db04728ea82762f338278738c480b1043991ae43575e4abfbb7bf34b7f3ab8016d1cda7ddbbe46573d069e6af8f1d6fc2ed23a5f9e927f0880893c0fc
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2025-03-15
4
+
5
+ - Initial release
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 arthur87
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.base.md ADDED
@@ -0,0 +1,44 @@
1
+ <!---------------------------->
2
+ <!-- multilingual suffix: en, ja -->
3
+ <!-- no suffix: en -->
4
+ <!---------------------------->
5
+
6
+ <!-- $ mmg README.base.md -->
7
+
8
+ # asa_json
9
+
10
+ asa_json is a library for conveniently JSON.
11
+ It supports reading and writing json and jsonl files.
12
+
13
+ # Usage
14
+
15
+ See spec files.
16
+
17
+ ## Read JSONL
18
+
19
+ ```
20
+ pp AsaJson.read_jsonl("#{__dir__}/test.jsonl")
21
+ ```
22
+
23
+ The output result is here.
24
+
25
+ ```
26
+ [{"id"=>1, "name"=>"cerulean", "year"=>2000, "color"=>"#98B2D1", "pantone_value"=>"15-4020"},
27
+ {"id"=>2, "name"=>"fuchsia rose", "year"=>2001, "color"=>"#C74375", "pantone_value"=>"17-2031"},
28
+ {"id"=>3, "name"=>"true red", "year"=>2002, "color"=>"#BF1932", "pantone_value"=>"19-1664"}]
29
+ ```
30
+
31
+ ## Write JSONL
32
+
33
+ ```
34
+ test = [
35
+ { 'id' => 1, 'name' => 'cerulean', 'year' => 2000, 'color' => '#98B2D1', 'pantone_value' => '15-4020' },
36
+ { 'id' => 2, 'name' => 'fuchsia rose', 'year' => 2001, 'color' => '#C74375',
37
+ 'pantone_value' => '17-2031' },
38
+ { 'id' => 3, 'name' => 'true red', 'year' => 2002, 'color' => '#BF1932', 'pantone_value' => '19-1664' }
39
+ ]
40
+
41
+ AsaJson.write_jsonl("#{__dir__}/output.jsonl", test)
42
+ ```
43
+
44
+ json uses read_json and write_json.
data/README.ja.md ADDED
@@ -0,0 +1,39 @@
1
+
2
+
3
+ # asa_json
4
+
5
+ asa_json is a library for conveniently JSON.
6
+ It supports reading and writing json and jsonl files.
7
+
8
+ # Usage
9
+
10
+ See spec files.
11
+
12
+ ## Read JSONL
13
+
14
+ ```
15
+ pp AsaJson.read_jsonl("#{__dir__}/test.jsonl")
16
+ ```
17
+
18
+ The output result is here.
19
+
20
+ ```
21
+ [{"id"=>1, "name"=>"cerulean", "year"=>2000, "color"=>"#98B2D1", "pantone_value"=>"15-4020"},
22
+ {"id"=>2, "name"=>"fuchsia rose", "year"=>2001, "color"=>"#C74375", "pantone_value"=>"17-2031"},
23
+ {"id"=>3, "name"=>"true red", "year"=>2002, "color"=>"#BF1932", "pantone_value"=>"19-1664"}]
24
+ ```
25
+
26
+ ## Write JSONL
27
+
28
+ ```
29
+ test = [
30
+ { 'id' => 1, 'name' => 'cerulean', 'year' => 2000, 'color' => '#98B2D1', 'pantone_value' => '15-4020' },
31
+ { 'id' => 2, 'name' => 'fuchsia rose', 'year' => 2001, 'color' => '#C74375',
32
+ 'pantone_value' => '17-2031' },
33
+ { 'id' => 3, 'name' => 'true red', 'year' => 2002, 'color' => '#BF1932', 'pantone_value' => '19-1664' }
34
+ ]
35
+
36
+ AsaJson.write_jsonl("#{__dir__}/output.jsonl", test)
37
+ ```
38
+
39
+ json uses read_json and write_json.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+
2
+
3
+ # asa_json
4
+
5
+ asa_json is a library for conveniently JSON.
6
+ It supports reading and writing json and jsonl files.
7
+
8
+ # Usage
9
+
10
+ See spec files.
11
+
12
+ ## Read JSONL
13
+
14
+ ```
15
+ pp AsaJson.read_jsonl("#{__dir__}/test.jsonl")
16
+ ```
17
+
18
+ The output result is here.
19
+
20
+ ```
21
+ [{"id"=>1, "name"=>"cerulean", "year"=>2000, "color"=>"#98B2D1", "pantone_value"=>"15-4020"},
22
+ {"id"=>2, "name"=>"fuchsia rose", "year"=>2001, "color"=>"#C74375", "pantone_value"=>"17-2031"},
23
+ {"id"=>3, "name"=>"true red", "year"=>2002, "color"=>"#BF1932", "pantone_value"=>"19-1664"}]
24
+ ```
25
+
26
+ ## Write JSONL
27
+
28
+ ```
29
+ test = [
30
+ { 'id' => 1, 'name' => 'cerulean', 'year' => 2000, 'color' => '#98B2D1', 'pantone_value' => '15-4020' },
31
+ { 'id' => 2, 'name' => 'fuchsia rose', 'year' => 2001, 'color' => '#C74375',
32
+ 'pantone_value' => '17-2031' },
33
+ { 'id' => 3, 'name' => 'true red', 'year' => 2002, 'color' => '#BF1932', 'pantone_value' => '19-1664' }
34
+ ]
35
+
36
+ AsaJson.write_jsonl("#{__dir__}/output.jsonl", test)
37
+ ```
38
+
39
+ json uses read_json and write_json.
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ task default: %i[]
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AsaJson
4
+ VERSION = '0.1.0'
5
+ end
data/lib/asa_json.rb ADDED
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'asa_json/version'
4
+ require 'json'
5
+
6
+ module AsaJson
7
+ class Error < StandardError; end
8
+ # Your code goes here...
9
+
10
+ # JSONLファイルの読み取り
11
+ def self.read_jsonl(file, json_options = {})
12
+ result = []
13
+ File.open(file, 'r') do |f|
14
+ f.each_line do |line|
15
+ result << JSON.parse(line, json_options)
16
+ end
17
+ end
18
+ result
19
+ end
20
+
21
+ # JSONLファイルの書き込み
22
+ def self.write_jsonl(file, lines)
23
+ File.open(file, 'w') do |f|
24
+ lines.each do |line|
25
+ f.write("#{line.to_json}\n")
26
+ end
27
+ end
28
+ end
29
+
30
+ # JSONファイルの読み取り
31
+ def self.read_json(file, json_options = {})
32
+ result = nil
33
+ File.open(file, 'r') do |f|
34
+ result = JSON.parse(f.read, json_options)
35
+ end
36
+ end
37
+
38
+ # JSONファイルの書き込み
39
+ def self.write_json(file, data)
40
+ File.open(file, 'w') do |f|
41
+ f.write(JSON.pretty_generate(data))
42
+ end
43
+ end
44
+ end
data/sig/asa_json.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module AsaJson
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: asa_json
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - arthur87
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 2025-03-15 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: rubocop
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :development
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
26
+ description: asa_json is a library for conveniently JSON.
27
+ email:
28
+ - arthur87@users.noreply.github.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - CHANGELOG.md
34
+ - LICENSE
35
+ - README.base.md
36
+ - README.ja.md
37
+ - README.md
38
+ - Rakefile
39
+ - lib/asa_json.rb
40
+ - lib/asa_json/version.rb
41
+ - sig/asa_json.rbs
42
+ homepage: https://github.com/arthur87/asa_json
43
+ licenses:
44
+ - MIT
45
+ metadata:
46
+ homepage_uri: https://github.com/arthur87/asa_json
47
+ source_code_uri: https://github.com/arthur87/asa_json
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 3.1.0
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubygems_version: 3.6.3
63
+ specification_version: 4
64
+ summary: asa_json is a library for conveniently JSON.
65
+ test_files: []