mll 2.2.0 → 2.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 66cecae3ebfe3b1589979a8146bb036f5f8a7203
4
- data.tar.gz: dd4fd79c9a5684e9cdefa25845a0530c1c897b5a
3
+ metadata.gz: d58bb50822e2731bcbf03713335a1445f697a8a9
4
+ data.tar.gz: 8c42d69f1444b610b797b2263854b67909e66e9b
5
5
  SHA512:
6
- metadata.gz: 1b0b5f12be754586a9e65a437924d5ac6153596c9fc5225da5820948b8f1fb10b49b42db02ac89a089f3872b26aba8d8896b5ae5d6bc4479d41398f3dc4ec18c
7
- data.tar.gz: 5fe76c75a56556b8e77e7855e28d006828fb963e1f943b14a7ec7ab4051c691280f365d25a9bbdb3640b82859bf1816b3f6ef44b033c149fcf89504a5af9ec75
6
+ metadata.gz: d6aa2a6b3fa89f8a0dd28327c280458db1e4570716f1bc63d2efaed23df23ae4d305359374988e148ada03a9c3b5f6072900fae0ce5f4a1677946b81733ac2f4
7
+ data.tar.gz: 632e9c4422e12b7e6b5b860b2d56400fc5137cf02cfb325a61dd60c3ecbbf229322d91ad913f304700f9e4c5344cb316a0f264fc3222ca2b56724e41dcd560c2
@@ -40,4 +40,5 @@ env:
40
40
  - rvm_max_time_flag=60
41
41
  before_install:
42
42
  - gem install bundler
43
+ - rm Gemfile.lock
43
44
  script: rake spec
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
- strings.map{ |row| [frames[0], row.zip(sizes).map{ |str, size| str.method(alignment).call size }.join(frames[1]), frames[0]].join }.join(
143
- [?\n, frames[9], sizes.map{ |size| frames[8] * size }.join(frames[4]), frames[12], ?\n].join
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
- [frames[5], sizes.map{ |size| frames[7] * size }.join(frames[11]), frames[6]].join,
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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "mll"
3
- spec.version = "2.2.0"
3
+ spec.version = "2.2.1"
4
4
  spec.authors = ["Victor Maslov"]
5
5
  spec.email = ["nakilon@gmail.com"]
6
6
  spec.summary = "Mathematica Language Library in Ruby"
@@ -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 " \n 1 \n \n 2 3 \n \n"
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
- # TODO "set the horizontal spacing between items" do
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.0
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-12 00:00:00.000000000 Z
11
+ date: 2015-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler