mll 2.2.0 → 2.2.1
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 +4 -4
- data/.travis.yml +1 -0
- data/README.md +1 -2
- data/lib/mll.rb +19 -5
- data/mll.gemspec +1 -1
- data/spec/_spec.rb +75 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d58bb50822e2731bcbf03713335a1445f697a8a9
|
4
|
+
data.tar.gz: 8c42d69f1444b610b797b2263854b67909e66e9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6aa2a6b3fa89f8a0dd28327c280458db1e4570716f1bc63d2efaed23df23ae4d305359374988e148ada03a9c3b5f6072900fae0ce5f4a1677946b81733ac2f4
|
7
|
+
data.tar.gz: 632e9c4422e12b7e6b5b860b2d56400fc5137cf02cfb325a61dd60c3ecbbf229322d91ad913f304700f9e4c5344cb316a0f264fc3222ca2b56724e41dcd560c2
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -118,6 +118,7 @@ module MLL
|
|
118
118
|
# TODO try to make #table lazy (Enumerator instead of Array)
|
119
119
|
def grid
|
120
120
|
lambda do |table, **options|
|
121
|
+
# TODO negative spacings?
|
121
122
|
# TODO smth with this #.all?
|
122
123
|
# TODO https://reference.wolfram.com/language/ref/Alignment.html
|
123
124
|
# TODO not sure if we need any other kind of Listability except of #range[[Array]]
|
@@ -210,8 +211,6 @@ describe MLL do
|
|
210
211
|
# TODO Alternating pink and yellow at successive horizontal positions
|
211
212
|
# TODO Alternating pink and yellow at successive vertical positions
|
212
213
|
# TODO Make the grid contents red
|
213
|
-
# TODO "set the horizontal spacing between items" do
|
214
|
-
# TODO "set the horizontal and vertical spacings" do
|
215
214
|
# TODO "grids can be nested" do
|
216
215
|
describe "Options:" do
|
217
216
|
# TODO "align elements around the center of the grid" do
|
data/lib/mll.rb
CHANGED
@@ -118,6 +118,10 @@ module MLL
|
|
118
118
|
# https://en.wikipedia.org/wiki/Box_Drawing
|
119
119
|
def grid
|
120
120
|
lambda do |table, **options|
|
121
|
+
# TODO negative spacings?
|
122
|
+
options[:spacings] ||= [1, 1]
|
123
|
+
spacings_horizontal, spacings_vertical = [*options[:spacings]]
|
124
|
+
spacings_vertical ||= 1
|
121
125
|
raise ArgumentError.new("unknown value of :alignment option '#{options[:alignment]}'") unless \
|
122
126
|
alignment = {
|
123
127
|
nil => :center,
|
@@ -135,14 +139,24 @@ module MLL
|
|
135
139
|
table = [table] unless table.all?{ |e| e.respond_to? :each }
|
136
140
|
width = table.map(&:size).max - 1
|
137
141
|
strings = table.map{ |row| row.dup.tap{ |a| a[width] = a[width] }.map(&:to_s) }
|
138
|
-
sizes = strings.transpose.map{ |col| col.map(&:size).max }
|
142
|
+
sizes = strings.transpose.map{ |col| col.map(&:size).max + [spacings_horizontal * 2 - 2, 0].max }
|
139
143
|
# TODO https://reference.wolfram.com/language/ref/Alignment.html
|
144
|
+
border_vertical = [frames[9], sizes.map{ |size| frames[8] * size }.join((frames[4] unless spacings_horizontal.zero?)), frames[12]]
|
145
|
+
spacing_vertical = [frames[0], sizes.map{ |size| frames[13] * size }.join((frames[0] unless spacings_horizontal.zero?)), frames[0]]
|
146
|
+
gap_vertical = lambda do |i|
|
147
|
+
j = i - 1
|
148
|
+
[*-j..j].map{ |k| [border_vertical][k] || spacings_vertical }
|
149
|
+
end.call spacings_vertical
|
140
150
|
[
|
141
|
-
[frames[2], sizes.map{ |size| frames[7] * size }.join(frames[10]), frames[3]].join,
|
142
|
-
|
143
|
-
|
151
|
+
[frames[2], sizes.map{ |size| frames[7] * size }.join((frames[10] unless spacings_horizontal.zero?)), frames[3]].join,
|
152
|
+
*([spacing_vertical.join] * [spacings_vertical - 1, 0].max),
|
153
|
+
strings.map{ |row| [frames[0], row.zip(sizes).map{ |str, size|
|
154
|
+
str.method(alignment).call(size)
|
155
|
+
}.join((frames[1] unless spacings_horizontal.zero?)), frames[0]].join }.join(
|
156
|
+
?\n + gap_vertical.map{ |gap| gap.join + ?\n }.join
|
144
157
|
),
|
145
|
-
[
|
158
|
+
*([spacing_vertical.join] * [spacings_vertical - 1, 0].max),
|
159
|
+
[frames[5], sizes.map{ |size| frames[7] * size }.join((frames[11] unless spacings_horizontal.zero?)), frames[6]].join,
|
146
160
|
].join(?\n) + ?\n
|
147
161
|
end
|
148
162
|
end
|
data/mll.gemspec
CHANGED
data/spec/_spec.rb
CHANGED
@@ -955,7 +955,12 @@ describe MLL do
|
|
955
955
|
skip "#normal is yet to be implemented"
|
956
956
|
end
|
957
957
|
example "the lists do not all need to be the same length" do
|
958
|
-
expect(grid[[[1],[2,3]]].to_s).to eq
|
958
|
+
expect(grid[[[1],[2,3]]].to_s).to eq \
|
959
|
+
" \n" \
|
960
|
+
" 1 \n" \
|
961
|
+
" \n" \
|
962
|
+
" 2 3 \n" \
|
963
|
+
" \n"
|
959
964
|
end
|
960
965
|
# TODO SpanFromLeft SpanFromAbove SpanFromBoth
|
961
966
|
# TODO The following options can be given
|
@@ -1053,10 +1058,77 @@ describe MLL do
|
|
1053
1058
|
"┃ccc┃ d┃\n" \
|
1054
1059
|
"┗━━━┻━━━━┛\n"
|
1055
1060
|
end
|
1056
|
-
|
1057
|
-
# TODO "set the horizontal and vertical spacings" do
|
1061
|
+
|
1058
1062
|
# TODO "grids can be nested" do
|
1059
1063
|
|
1064
|
+
# https://reference.wolfram.com/language/ref/Spacings.html
|
1065
|
+
describe "option :spacing" do
|
1066
|
+
|
1067
|
+
example "set the horizontal spacing between items" do
|
1068
|
+
expect(grid[table[?x, [3], [3]], spacings: 2, frame: :all]).to eq \
|
1069
|
+
"┏━━━┳━━━┳━━━┓\n" \
|
1070
|
+
"┃ x ┃ x ┃ x ┃\n" \
|
1071
|
+
"┣━━━╋━━━╋━━━┫\n" \
|
1072
|
+
"┃ x ┃ x ┃ x ┃\n" \
|
1073
|
+
"┣━━━╋━━━╋━━━┫\n" \
|
1074
|
+
"┃ x ┃ x ┃ x ┃\n" \
|
1075
|
+
"┗━━━┻━━━┻━━━┛\n"
|
1076
|
+
end
|
1077
|
+
example "set the horizontal and vertical spacings" do
|
1078
|
+
expect(grid[table[?x, [3], [3]], spacings: [2, 0], frame: :all]).to eq \
|
1079
|
+
"┏━━━┳━━━┳━━━┓\n" \
|
1080
|
+
"┃ x ┃ x ┃ x ┃\n" \
|
1081
|
+
"┃ x ┃ x ┃ x ┃\n" \
|
1082
|
+
"┃ x ┃ x ┃ x ┃\n" \
|
1083
|
+
"┗━━━┻━━━┻━━━┛\n"
|
1084
|
+
end
|
1085
|
+
example "insert no additional space between columns" do
|
1086
|
+
expect(grid[table[?x, [4], [7]], spacings: 0]).to eq \
|
1087
|
+
" \n" \
|
1088
|
+
" xxxxxxx \n" \
|
1089
|
+
" \n" \
|
1090
|
+
" xxxxxxx \n" \
|
1091
|
+
" \n" \
|
1092
|
+
" xxxxxxx \n" \
|
1093
|
+
" \n" \
|
1094
|
+
" xxxxxxx \n" \
|
1095
|
+
" \n"
|
1096
|
+
expect(grid[table[?x, [4], [7]], spacings: 0, frame: :all]).to eq \
|
1097
|
+
"┏━━━━━━━┓\n" \
|
1098
|
+
"┃xxxxxxx┃\n" \
|
1099
|
+
"┣━━━━━━━┫\n" \
|
1100
|
+
"┃xxxxxxx┃\n" \
|
1101
|
+
"┣━━━━━━━┫\n" \
|
1102
|
+
"┃xxxxxxx┃\n" \
|
1103
|
+
"┣━━━━━━━┫\n" \
|
1104
|
+
"┃xxxxxxx┃\n" \
|
1105
|
+
"┗━━━━━━━┛\n"
|
1106
|
+
end
|
1107
|
+
example "insert additional space at the second horizontal divider" do
|
1108
|
+
skip "automatic"
|
1109
|
+
expect(grid[table[?x, [4], [7]], spacings: {2 => 3}, frame: :all]).to eq \
|
1110
|
+
" - \n" \
|
1111
|
+
" xxxxxxx \n" \
|
1112
|
+
" xxxxxxx \n" \
|
1113
|
+
" xxxxxxx \n" \
|
1114
|
+
" xxxxxxx \n" \
|
1115
|
+
" \n"
|
1116
|
+
end
|
1117
|
+
example "set the size of the grid's margins" do
|
1118
|
+
skip "cycling"
|
1119
|
+
expect(grid[table[?x, [3], [7]], spacings: [[5, [], 5], [5, [], 5]], frame: :all]).to eq \
|
1120
|
+
" - \n" \
|
1121
|
+
" - \n" \
|
1122
|
+
" xxxxxxx \n" \
|
1123
|
+
" xxxxxxx \n" \
|
1124
|
+
" xxxxxxx \n" \
|
1125
|
+
" xxxxxxx \n" \
|
1126
|
+
" \n" \
|
1127
|
+
" \n"
|
1128
|
+
end
|
1129
|
+
|
1130
|
+
end
|
1131
|
+
|
1060
1132
|
end
|
1061
1133
|
|
1062
1134
|
describe "Options:" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mll
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Maslov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|