simple_tabler 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/simple_tabler/row.rb +17 -0
- data/lib/simple_tabler/separation.rb +13 -0
- data/lib/simple_tabler/table.rb +54 -0
- data/lib/simple_tabler/version.rb +1 -1
- data/lib/simple_tabler.rb +4 -4
- metadata +5 -3
- data/lib/table_from_array.rb +0 -52
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44a72428a6ffcde30829295de518515e75ac45e37191da308d408816cb947e35
|
4
|
+
data.tar.gz: f56beee33953317bf4537d338b2d7554b6ecdb507ee16124db4d932f9395ae4b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b33eae196087e668fafda9b084aeff2faec09d9545e4b97576135a6ffb7348456032e73aa33a8269abbceef9e25f551b6cf9fe61830e15d65830deafc721573d
|
7
|
+
data.tar.gz: 8379f7cbb060619033b50ffb08ac908205ea4ed40fc47fae45e414e2750f0d11f4b0bd6ee112187b9d26a0a343d07720c07f4b2c6937d8d1e5e3f22d658a74f9
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class Row
|
2
|
+
attr_reader :materials, :line_number, :scale
|
3
|
+
|
4
|
+
def initialize(materials, line_number, scale)
|
5
|
+
@materials = materials
|
6
|
+
@line_number = line_number
|
7
|
+
@scale = scale
|
8
|
+
end
|
9
|
+
|
10
|
+
def content
|
11
|
+
materials.inject("|") do |content, material|
|
12
|
+
string = material[scale*line_number...scale*(line_number+1)].to_s
|
13
|
+
spaces = " " * (scale - string.size)
|
14
|
+
content + string + spaces + "|"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require_relative "row"
|
2
|
+
require_relative "separation"
|
3
|
+
|
4
|
+
class Table
|
5
|
+
attr_accessor :content_array_of_table
|
6
|
+
attr_reader :cell_size, :scale
|
7
|
+
|
8
|
+
def initialize(array, column_names, scale)
|
9
|
+
@content_array_of_table = []
|
10
|
+
@cell_size = array[0].size
|
11
|
+
@scale = scale
|
12
|
+
add_header(column_names)
|
13
|
+
add_content(array)
|
14
|
+
end
|
15
|
+
|
16
|
+
def content
|
17
|
+
self.content_array_of_table.inject(""){|result, content| result + content + "\n" }
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
def add_row(row_materials)
|
22
|
+
number_of_lines = (max_length_of_array_element(row_materials).to_f / scale).ceil
|
23
|
+
(0...number_of_lines).each do |i|
|
24
|
+
row = Row.new(row_materials, i, @scale)
|
25
|
+
self.content_array_of_table << row.content
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def max_length_of_array_element(array)
|
30
|
+
array.map{|element| element.to_s.size}.max
|
31
|
+
end
|
32
|
+
|
33
|
+
def add_header(column_names=nil)
|
34
|
+
if column_names
|
35
|
+
add_separation("=")
|
36
|
+
add_row(column_names)
|
37
|
+
add_separation("=")
|
38
|
+
else
|
39
|
+
add_separation("-")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def add_content(table_materials)
|
44
|
+
table_materials.each do |row_materials|
|
45
|
+
add_row(row_materials)
|
46
|
+
add_separation("-")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def add_separation(mark)
|
51
|
+
separation = Separation.new(mark, cell_size, scale)
|
52
|
+
self.content_array_of_table << separation.content
|
53
|
+
end
|
54
|
+
end
|
data/lib/simple_tabler.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative "simple_tabler/version"
|
4
|
-
require_relative "
|
4
|
+
require_relative "simple_tabler/table"
|
5
5
|
|
6
6
|
class Array; include SimpleTabler; end
|
7
7
|
|
@@ -19,8 +19,8 @@ module SimpleTabler
|
|
19
19
|
raise ArgumentError, "All child arrays should have same amount of element with column names you passed as an argument."
|
20
20
|
end
|
21
21
|
|
22
|
-
table_generated_from_array =
|
23
|
-
return table_generated_from_array.
|
22
|
+
table_generated_from_array = Table.new(self, column_names, scale)
|
23
|
+
return table_generated_from_array.content
|
24
24
|
end
|
25
25
|
|
26
26
|
# return true if dimension of array equal two.
|
@@ -60,4 +60,4 @@ module SimpleTabler
|
|
60
60
|
def column_size_correct?(column_names)
|
61
61
|
self[0].size == column_names.size
|
62
62
|
end
|
63
|
-
end
|
63
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_tabler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mew3880
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-07-
|
11
|
+
date: 2022-07-30 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -24,8 +24,10 @@ files:
|
|
24
24
|
- README.md
|
25
25
|
- Rakefile
|
26
26
|
- lib/simple_tabler.rb
|
27
|
+
- lib/simple_tabler/row.rb
|
28
|
+
- lib/simple_tabler/separation.rb
|
29
|
+
- lib/simple_tabler/table.rb
|
27
30
|
- lib/simple_tabler/version.rb
|
28
|
-
- lib/table_from_array.rb
|
29
31
|
- sig/simple_tabler.rbs
|
30
32
|
homepage: https://github.com/Takahashi-Riki/simple_tabler
|
31
33
|
licenses:
|
data/lib/table_from_array.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
class TableFromArray
|
2
|
-
attr_reader :content_of_table
|
3
|
-
|
4
|
-
def initialize(array, column_names, scale)
|
5
|
-
@content_of_table = ""
|
6
|
-
@column_size = array[0].size
|
7
|
-
@scale = scale
|
8
|
-
self.add_header(column_names)
|
9
|
-
self.add_content(array)
|
10
|
-
end
|
11
|
-
|
12
|
-
def add_header(column_names=nil)
|
13
|
-
if column_names
|
14
|
-
add_separation("=")
|
15
|
-
add_row(column_names)
|
16
|
-
add_separation("=")
|
17
|
-
else
|
18
|
-
add_separation("-")
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def add_content(table_materials)
|
23
|
-
table_materials.each do |row_materials|
|
24
|
-
add_row(row_materials)
|
25
|
-
add_separation("-")
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
def max_length_of_array_element(array)
|
31
|
-
array.map{|element| element.to_s.size}.max
|
32
|
-
end
|
33
|
-
|
34
|
-
def add_row(row_materials)
|
35
|
-
content_of_row = ""
|
36
|
-
number_of_lines = (max_length_of_array_element(row_materials).to_f / @scale).ceil
|
37
|
-
(0...number_of_lines).each do |i|
|
38
|
-
line = "|"
|
39
|
-
row_materials.each do |row_material|
|
40
|
-
row_material_sliced_for_this_line = row_material[@scale*i...@scale*(i+1)].to_s
|
41
|
-
space_to_fill_the_blank = " " * (@scale - row_material_sliced_for_this_line.size)
|
42
|
-
line += row_material_sliced_for_this_line + space_to_fill_the_blank + "|"
|
43
|
-
end
|
44
|
-
content_of_row += line + "\n"
|
45
|
-
end
|
46
|
-
@content_of_table += content_of_row
|
47
|
-
end
|
48
|
-
|
49
|
-
def add_separation(mark)
|
50
|
-
@content_of_table += "|" + mark * (@scale * @column_size + @column_size - 1) + "|" + "\n"
|
51
|
-
end
|
52
|
-
end
|