ls_table 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +8 -0
- data/LICENSE +22 -0
- data/Rakefile +4 -0
- data/lib/ls_table.rb +58 -0
- data/ls_table.gemspec +38 -0
- data/sig/ls_table.rbs +4 -0
- metadata +50 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1901dc8d51a1af9adb9571ce5678910874c9115be36eb87faa16a746f7fba512
|
4
|
+
data.tar.gz: 2b4d475b4a20b8a701dbc438b04f9b897bd1ed7ebaba5eb49ab0ecc45df61d0e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a6cf288358c70b760aacf9fea224602b7b68c87b39e4ca25d9fb6081c22baa49c5961c4cd6329cbce51c28314b282cf6da37cfb9c7fe2182c71453127259711b
|
7
|
+
data.tar.gz: c7b497ca7b5df3914b8d0257d894ddb3b5d7c403fb5200c53b9006c2ee6fbd25acf98129bdc20533ccda1a66f34e867b118df373020e29bc339692d32842af98
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2022 ccmywish
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/lib/ls_table.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# require_relative "ls_table/version"
|
2
|
+
|
3
|
+
module LsTable
|
4
|
+
VERSION = "0.1.0"
|
5
|
+
class Error < StandardError; end
|
6
|
+
end
|
7
|
+
|
8
|
+
|
9
|
+
def LsTable.ls(arr, cell_len: 9, cell_num: 8)
|
10
|
+
|
11
|
+
result_lines = []
|
12
|
+
|
13
|
+
return if arr.empty?
|
14
|
+
|
15
|
+
cell_delimiter = 1
|
16
|
+
|
17
|
+
one_line_cap = (cell_len + cell_delimiter) * cell_num # == 80
|
18
|
+
|
19
|
+
sentry = []
|
20
|
+
cell_num.times do |n|
|
21
|
+
sentry << (n + 1) * (cell_len + cell_delimiter)
|
22
|
+
end
|
23
|
+
# [10, 20, 30, 40, 50, 60, 70, 80]
|
24
|
+
|
25
|
+
si = 0
|
26
|
+
|
27
|
+
line = ""
|
28
|
+
arr.each do |e|
|
29
|
+
|
30
|
+
next if e.length > one_line_cap
|
31
|
+
|
32
|
+
while line.length + e.length >= sentry[si]
|
33
|
+
si += 1
|
34
|
+
|
35
|
+
if si > (sentry.size - 1)
|
36
|
+
yield line if block_given?
|
37
|
+
result_lines << line
|
38
|
+
line = "" ; si = 0
|
39
|
+
next
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
line << e
|
44
|
+
line = line.ljust(sentry[si])
|
45
|
+
|
46
|
+
if line.size == one_line_cap
|
47
|
+
yield line if block_given?
|
48
|
+
result_lines << line
|
49
|
+
line = "" ; si = 0
|
50
|
+
next
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
# All cells done
|
56
|
+
yield line if block_given?
|
57
|
+
result_lines << line
|
58
|
+
end
|
data/ls_table.gemspec
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/ls_table"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "ls_table"
|
7
|
+
spec.version = LsTable::VERSION
|
8
|
+
spec.authors = ["ccmywish"]
|
9
|
+
spec.email = ["ccmywish@qq.com"]
|
10
|
+
|
11
|
+
spec.summary = "ls to an array"
|
12
|
+
spec.description = "ls to an array"
|
13
|
+
spec.homepage = "https://github.com/ccmywish"
|
14
|
+
spec.required_ruby_version = ">= 2.6.0"
|
15
|
+
|
16
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
|
17
|
+
|
18
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
19
|
+
spec.metadata["source_code_uri"] = "https://github.com/ccmywish"
|
20
|
+
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
25
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
26
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features|doc)/|\.(?:git|travis|circleci)|appveyor)}) || f.match(/.*\.md/)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
# Uncomment to register a new dependency of your gem
|
34
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
35
|
+
|
36
|
+
# For more information and examples about making a new gem, check out our
|
37
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
38
|
+
end
|
data/sig/ls_table.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ls_table
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ccmywish
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-03-23 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: ls to an array
|
14
|
+
email:
|
15
|
+
- ccmywish@qq.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- Gemfile
|
21
|
+
- LICENSE
|
22
|
+
- Rakefile
|
23
|
+
- lib/ls_table.rb
|
24
|
+
- ls_table.gemspec
|
25
|
+
- sig/ls_table.rbs
|
26
|
+
homepage: https://github.com/ccmywish
|
27
|
+
licenses: []
|
28
|
+
metadata:
|
29
|
+
homepage_uri: https://github.com/ccmywish
|
30
|
+
source_code_uri: https://github.com/ccmywish
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 2.6.0
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
requirements: []
|
46
|
+
rubygems_version: 3.3.7
|
47
|
+
signing_key:
|
48
|
+
specification_version: 4
|
49
|
+
summary: ls to an array
|
50
|
+
test_files: []
|