cerata 0.9.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 +7 -0
- data/CHANGELOG.md +8 -0
- data/LICENSE.txt +24 -0
- data/README.md +48 -0
- data/cerata.gemspec +49 -0
- data/lib/cerata.rb +111 -0
- metadata +68 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 109c18b0034c335e203eaf8255256048eedc3f2c77bd3f3cd7899a8aa7cd8b58
|
4
|
+
data.tar.gz: ce462c5db25546fcfc019289e02ad7823eb8f8beb237fc1d2cd117e426f20745
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 70dd0f0bdf8ad040caa48e34d6e4f783a1927af000103775b52646ecd59cada9747bff8f7f6bd2c08352a624f7ee6704992ff2213ab79e3331e5f682b7888067
|
7
|
+
data.tar.gz: 588f03dfb8346b88ed31b05a4cc9a26861a78aa74694f656f5ba212a5d1e0a126a01a88ec250c6da64a1855da06a0b5c0eda14ab50cceb6005e612191ecd538a
|
data/CHANGELOG.md
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
|
2
|
+
Copyright (c) 2024-2025, John Mettraux, jmettraux+flor@gmail.com
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
6
|
+
in the Software without restriction, including without limitation the rights
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
9
|
+
furnished to do so, subject to the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be included in
|
12
|
+
all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
THE SOFTWARE.
|
21
|
+
|
22
|
+
|
23
|
+
Made in Japan
|
24
|
+
|
data/README.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
|
2
|
+
# cerata
|
3
|
+
|
4
|
+
[](https://github.com/floraison/cerata/actions)
|
5
|
+
[](https://badge.fury.io/rb/cerata)
|
6
|
+
|
7
|
+
Tabula cerata formatting for floraison and flor, data to string formatting.
|
8
|
+
|
9
|
+
## `Cerata.horizontal_a_to_s(array, indent='')`
|
10
|
+
|
11
|
+
TODO
|
12
|
+
|
13
|
+
## `Cerata.horizontal_h_to_s(hash, indent='')`
|
14
|
+
|
15
|
+
TODO
|
16
|
+
|
17
|
+
## `Cerata.vertical_h_to_s(hash, indent='')`
|
18
|
+
|
19
|
+
TODO
|
20
|
+
|
21
|
+
## `Cerata.table_to_s(array_of_hashes, indent='')`
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require 'cerata'
|
25
|
+
|
26
|
+
a = [
|
27
|
+
{ name: 'Haddock', age: 52 },
|
28
|
+
{ name: 'Tintin', age: 31, weight: 60 },
|
29
|
+
{ name: 'Castafiore', id: 123, age: 59, height: 163 },
|
30
|
+
{ name: 'Milou', id: 12, age: 3, height: 20 } ]
|
31
|
+
|
32
|
+
puts Cerata.table_to_s(a)
|
33
|
+
# =>
|
34
|
+
%{
|
35
|
+
[
|
36
|
+
{ name: "Haddock" , age: 52, },
|
37
|
+
{ name: "Tintin" , age: 31, weight: 60, },
|
38
|
+
{ name: "Castafiore", age: 59, id: 123, height: 163 },
|
39
|
+
{ name: "Milou" , age: 3, id: 12, height: 20 },
|
40
|
+
]
|
41
|
+
}
|
42
|
+
```
|
43
|
+
|
44
|
+
|
45
|
+
## LICENSE
|
46
|
+
|
47
|
+
MIT, see [LICENSE.txt](LICENSE.txt)
|
48
|
+
|
data/cerata.gemspec
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
|
2
|
+
Gem::Specification.new do |s|
|
3
|
+
|
4
|
+
s.name = 'cerata'
|
5
|
+
|
6
|
+
s.version = File.read(
|
7
|
+
File.expand_path('../lib/cerata.rb', __FILE__)
|
8
|
+
).match(/ VERSION *= *['"]([^'"]+)/)[1]
|
9
|
+
|
10
|
+
s.platform = Gem::Platform::RUBY
|
11
|
+
s.authors = [ 'John Mettraux' ]
|
12
|
+
s.email = [ 'jmettraux+flor@gmail.com' ]
|
13
|
+
s.homepage = "https://github.com/floraison/#{s.name}"
|
14
|
+
s.license = 'MIT'
|
15
|
+
s.summary = 'tabula cerata formatting for floraison and flor'
|
16
|
+
|
17
|
+
s.description = %{
|
18
|
+
Tabula cerata formatting for floraison and flor, data to string formatting.
|
19
|
+
}.strip
|
20
|
+
|
21
|
+
s.metadata = {
|
22
|
+
'changelog_uri' => s.homepage + '/blob/master/CHANGELOG.md',
|
23
|
+
'bug_tracker_uri' => s.homepage + '/issues',
|
24
|
+
'documentation_uri' => s.homepage,
|
25
|
+
'homepage_uri' => s.homepage,
|
26
|
+
'source_code_uri' => s.homepage,
|
27
|
+
#'mailing_list_uri' => 'https://groups.google.com/forum/#!forum/floraison',
|
28
|
+
#'wiki_uri' => s.homepage + '/wiki',
|
29
|
+
'rubygems_mfa_required' => 'true',
|
30
|
+
}
|
31
|
+
|
32
|
+
#s.files = `git ls-files`.split("\n")
|
33
|
+
s.files = Dir[
|
34
|
+
'{README,CHANGELOG,CREDITS,LICENSE}.{md,txt}',
|
35
|
+
#'Makefile',
|
36
|
+
'lib/**/*.rb', #'spec/**/*.rb', 'test/**/*.rb',
|
37
|
+
"#{s.name}.gemspec",
|
38
|
+
]
|
39
|
+
|
40
|
+
#s.add_runtime_dependency 'tzinfo'
|
41
|
+
# this dependency appears in 'et-orbi'
|
42
|
+
|
43
|
+
#s.add_runtime_dependency 'colorato', '~> 1.0'
|
44
|
+
|
45
|
+
s.add_development_dependency 'probatio', '~> 1.0'
|
46
|
+
|
47
|
+
s.require_path = 'lib'
|
48
|
+
end
|
49
|
+
|
data/lib/cerata.rb
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
|
2
|
+
#
|
3
|
+
# cerata.rb
|
4
|
+
|
5
|
+
require 'stringio'
|
6
|
+
|
7
|
+
|
8
|
+
module Cerata
|
9
|
+
|
10
|
+
VERSION = '0.9.0'
|
11
|
+
|
12
|
+
module NoVal; end
|
13
|
+
|
14
|
+
class << self
|
15
|
+
|
16
|
+
# TODO deal with double width characters...
|
17
|
+
|
18
|
+
def horizontal_a_to_s(a, indent='')
|
19
|
+
|
20
|
+
return '[]' if a.empty?
|
21
|
+
|
22
|
+
o = StringIO.new
|
23
|
+
|
24
|
+
o << indent << '[ '
|
25
|
+
a1 = a.dup; while e = a1.shift
|
26
|
+
o << e.inspect
|
27
|
+
o << ', ' if a1.any?
|
28
|
+
end
|
29
|
+
o << ' ]'
|
30
|
+
|
31
|
+
o.string
|
32
|
+
end
|
33
|
+
|
34
|
+
def horizontal_h_to_s(h, indent='')
|
35
|
+
|
36
|
+
return '{}' if h.empty?
|
37
|
+
|
38
|
+
o = StringIO.new
|
39
|
+
|
40
|
+
o << indent << '{ '
|
41
|
+
kvs = h.to_a; while kv = kvs.shift
|
42
|
+
o << "#{kv.first}: " << kv[1].inspect
|
43
|
+
o << ', ' if kvs.any?
|
44
|
+
end
|
45
|
+
o << ' }'
|
46
|
+
|
47
|
+
o.string
|
48
|
+
end
|
49
|
+
|
50
|
+
def vertical_h_to_s(h, indent='')
|
51
|
+
|
52
|
+
return '{}' if h.empty?
|
53
|
+
|
54
|
+
o = StringIO.new
|
55
|
+
|
56
|
+
o << indent << "{\n"
|
57
|
+
h.each { |k, v| o << indent << "#{k}: " << v.inspect << ",\n" }
|
58
|
+
o << indent << '}'
|
59
|
+
|
60
|
+
o.string
|
61
|
+
end
|
62
|
+
|
63
|
+
# A "table" here is an array of hashes
|
64
|
+
#
|
65
|
+
# This method emits a Ruby readable vertically aligned table-like
|
66
|
+
# representation of the a input.
|
67
|
+
# Beware: it turns all keys to symbols.
|
68
|
+
#
|
69
|
+
def table_to_s(a, indent='')
|
70
|
+
|
71
|
+
return '[]' if a.empty?
|
72
|
+
|
73
|
+
all_keys =
|
74
|
+
a.collect(&:keys).flatten.uniq.map(&:to_s)
|
75
|
+
key_widths =
|
76
|
+
all_keys.inject({}) { |h, k| h[k] = k.length + 1; h }
|
77
|
+
# +1 for the colon between key and value...
|
78
|
+
val_widths =
|
79
|
+
a.inject({}) { |w, h|
|
80
|
+
h.each { |k, v|
|
81
|
+
k = k.to_s; w[k] = [ w[k] || 0, v.inspect.length ].max }
|
82
|
+
w }
|
83
|
+
|
84
|
+
o = StringIO.new
|
85
|
+
|
86
|
+
o << indent << "[\n"
|
87
|
+
|
88
|
+
a.each do |h|
|
89
|
+
o << indent << '{ '
|
90
|
+
all_keys.each_with_index do |k, i|
|
91
|
+
sk = k.to_sym
|
92
|
+
v =
|
93
|
+
h.has_key?(k) ? h[k].inspect :
|
94
|
+
h.has_key?(sk) ? h[sk].inspect :
|
95
|
+
NoVal
|
96
|
+
kl, vl = key_widths[k], val_widths[k]
|
97
|
+
kf = "%#{kl}s"
|
98
|
+
vf = v.is_a?(String) && (v[0, 1] == '"') ? "%-#{vl}s" : "%#{vl}s"
|
99
|
+
o << ("#{kf} #{vf}" % (v == NoVal ? [ '', '' ] : [ k + ':', v ]))
|
100
|
+
o << (v == NoVal ? ' ' : ', ') if i < all_keys.length - 1
|
101
|
+
end
|
102
|
+
o << " },\n"
|
103
|
+
end
|
104
|
+
|
105
|
+
o << indent << ']'
|
106
|
+
|
107
|
+
o.string
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cerata
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- John Mettraux
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-12-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: probatio
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
description: Tabula cerata formatting for floraison and flor, data to string formatting.
|
28
|
+
email:
|
29
|
+
- jmettraux+flor@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- CHANGELOG.md
|
35
|
+
- LICENSE.txt
|
36
|
+
- README.md
|
37
|
+
- cerata.gemspec
|
38
|
+
- lib/cerata.rb
|
39
|
+
homepage: https://github.com/floraison/cerata
|
40
|
+
licenses:
|
41
|
+
- MIT
|
42
|
+
metadata:
|
43
|
+
changelog_uri: https://github.com/floraison/cerata/blob/master/CHANGELOG.md
|
44
|
+
bug_tracker_uri: https://github.com/floraison/cerata/issues
|
45
|
+
documentation_uri: https://github.com/floraison/cerata
|
46
|
+
homepage_uri: https://github.com/floraison/cerata
|
47
|
+
source_code_uri: https://github.com/floraison/cerata
|
48
|
+
rubygems_mfa_required: 'true'
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
requirements: []
|
64
|
+
rubygems_version: 3.5.16
|
65
|
+
signing_key:
|
66
|
+
specification_version: 4
|
67
|
+
summary: tabula cerata formatting for floraison and flor
|
68
|
+
test_files: []
|