mll 2.5.0 → 2.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/mll.rb +62 -36
- data/spec/_spec.rb +7 -5
- 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: 4e828b7ba71a30c704eb325f81a144113ced5243
|
4
|
+
data.tar.gz: 3365c0fb3f69975205447c5b962599e825300c78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a2c95ffc31aac88097f2d383a5113cbfff4a4a5be337981f4c52f41a3f43d75854892044488b4ce6edd26a61b02a695dc7b228c9d1f6ff4ac61d4e616236e5a
|
7
|
+
data.tar.gz: 7abc5d63a3438924c5fe7423e9a86a3aa74618d8739383b72560a2063c27b4dd9f8d51306fa0798399a8b48a6cdd524ab26e53c0d55f6a281e0cce0952502cd1
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
[![Join the chat at https://gitter.im/Nakilon/mll](https://badges.gitter.im/Nakilon/mll.svg)](https://gitter.im/Nakilon/mll?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
4
4
|
[![Gem Version](https://badge.fury.io/rb/mll.svg)](http://badge.fury.io/rb/mll)
|
5
|
-
[![Build Status](https://travis-ci.org/Nakilon/mll.svg)](https://travis-ci.org/Nakilon/mll)
|
5
|
+
[![Build Status](https://travis-ci.org/Nakilon/mll.svg)](https://travis-ci.org/Nakilon/mll?branch=master)
|
6
6
|
|
7
7
|
### What
|
8
8
|
|
data/lib/mll.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module MLL
|
2
2
|
|
3
|
-
VERSION = "2.5.
|
3
|
+
VERSION = "2.5.1"
|
4
4
|
|
5
5
|
class << self
|
6
6
|
|
@@ -96,8 +96,11 @@ module MLL
|
|
96
96
|
lambda do |f, *args|
|
97
97
|
[].tap do |result|
|
98
98
|
[[result, args.map{ |r| # add lazy?
|
99
|
-
r.respond_to?
|
100
|
-
r
|
99
|
+
if r.respond_to? :map
|
100
|
+
next r if r.is_a? Range
|
101
|
+
next r.first if r.first.respond_to? :map # TODO check r.size?
|
102
|
+
end
|
103
|
+
range[*r]
|
101
104
|
}]].tap do |stack|
|
102
105
|
stack.each do |ai, ri|
|
103
106
|
# TODO try to make #table lazy (Enumerator instead of Array)
|
@@ -119,47 +122,70 @@ module MLL
|
|
119
122
|
# http://www.unicode.org/charts/PDF/U2500.pdf
|
120
123
|
# https://en.wikipedia.org/wiki/Box_Drawing
|
121
124
|
def grid
|
122
|
-
lambda do |table, **options|
|
125
|
+
lambda do |table, spacings: [1, 1], **options|
|
123
126
|
# TODO negative spacings?
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
raise ArgumentError.new("unknown value of :alignment option '#{options[:alignment]}'") unless \
|
127
|
+
spacing_horizontal, spacing_vertical = spacings
|
128
|
+
spacing_vertical ||= 1
|
129
|
+
raise ArgumentError.new("unsupported value of :alignment option '#{options[:alignment]}'") unless \
|
128
130
|
alignment = {
|
129
131
|
nil => :center,
|
130
132
|
:center => :center,
|
131
133
|
:left => :ljust,
|
132
134
|
:right => :rjust,
|
133
135
|
}[options[:alignment]]
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
# TODO smth with this
|
136
|
+
raise ArgumentError.new("unsupported value of :frame option '#{options[:frame]}'") unless \
|
137
|
+
frames = {
|
138
|
+
nil => " ",
|
139
|
+
true => "┃ ┏┓ ┗┛━ ┃━━┃ ",
|
140
|
+
:all => "┃┃┏┓╋┗┛━━┣┳┻┫ ",
|
141
|
+
}[options[:frame]]
|
142
|
+
# TODO smth with this; maybe check out how Mathematica handles `Table[{1,{2,3},4}]`
|
143
|
+
|
141
144
|
table = [table] unless table.all?{ |e| e.respond_to? :each }
|
142
|
-
width = table.map(&:size).max
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
145
|
+
width = table.map(&:size).max
|
146
|
+
table = table.map do |row|
|
147
|
+
row.dup.tap do |row|
|
148
|
+
row[width - 1] = row[width - 1]
|
149
|
+
end.map &:to_s
|
150
|
+
end
|
151
|
+
rows = table.map{ |row| row.map{ |s| s.count ?\n }.max + 1 }
|
152
|
+
cols = table.transpose.map{ |col| col.flat_map{ |s| s.scan(/.+/).map(&:size) }.max }
|
153
|
+
|
154
|
+
chars = table.flat_map.with_index do |row, i|
|
155
|
+
row.map.with_index do |s, j|
|
156
|
+
lines = s.scan(/.+/)
|
157
|
+
max = lines.map(&:size).max || 0
|
158
|
+
lines.map!{ |line| line.ljust(max).method(alignment).call(cols[j]) }
|
159
|
+
self.table[ lambda do |k, l|
|
160
|
+
m = k - spacing_vertical
|
161
|
+
n = l - spacing_horizontal
|
162
|
+
0<=m && m<lines.size && 0<=n && n<cols[j] ? lines[m][n] : frames[(
|
163
|
+
h = spacing_horizontal.zero?
|
164
|
+
v = spacing_vertical.zero?
|
165
|
+
k == 0 ? l == 0 ?
|
166
|
+
h ? v ? ?O : 7 : v ? 0 :
|
167
|
+
i.zero? ? j.zero? ? 2 : 10 : j.zero? ? 9 : 4 :
|
168
|
+
v ? 13 : i.zero? ? 7 : 8 : l == 0 ? j.zero? ? 0 : 1 : 13
|
169
|
+
)]
|
170
|
+
end, 0...[rows[i] + spacing_vertical * 2 - 1, 1].max,
|
171
|
+
0...[cols[j] + spacing_horizontal * 2 - 1, 1].max ]
|
172
|
+
end.transpose.map{ |row| row.inject :+ }
|
173
|
+
end
|
174
|
+
|
175
|
+
borders_horizontal = fold_list[0, rows, ->i,j{ i + j + spacing_vertical * 2 - 1 }].to_a
|
176
|
+
chars.each_with_index do |line, i|
|
177
|
+
line.push frames[borders_horizontal.include?(i) && !spacing_vertical.zero? ? 12 : 0]
|
178
|
+
line.unshift frames[i.zero? ? 2 : borders_horizontal.include?(i) && !spacing_vertical.zero? ? 9 : 0] if spacing_horizontal.zero?
|
179
|
+
end
|
180
|
+
borders_vertical = fold_list[0, cols, ->i,j{ i + j + spacing_horizontal * 2 - 1 }].to_a
|
181
|
+
chars = chars.transpose.each_with_index do |line, i|
|
182
|
+
line.push frames[i.zero? ? 5 : borders_vertical.include?(i) && !spacing_horizontal.zero? ? 11 : 7]
|
183
|
+
line.unshift frames[i.zero? ? 2 : borders_vertical.include?(i) && !spacing_horizontal.zero? ? 10 : 7] if spacing_vertical.zero?
|
184
|
+
end.transpose
|
185
|
+
chars[-1][-1] = frames[6]
|
186
|
+
chars[0][-1] = frames[3]
|
187
|
+
|
188
|
+
chars.map{ |row| row.push ?\n }.join
|
163
189
|
end
|
164
190
|
end
|
165
191
|
|
data/spec/_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require "pp"
|
2
|
+
|
1
3
|
require_relative "../lib/mll"
|
2
4
|
|
3
5
|
# PERMATODO test all implemented exceptions
|
@@ -277,12 +279,12 @@ describe MLL do
|
|
277
279
|
end
|
278
280
|
|
279
281
|
example "table[lambda, n1, min..max, [max, min, -step]]" do
|
280
|
-
expect(table[->(i,j,k){ [i,j,k] }, 3,
|
281
|
-
expect(table[->(i,j,k){ [i,j,k] }, 3,
|
282
|
+
expect(table[->(i,j,k){ [i,j,k] }, 3, 1..3, [5, 1, -2]]).to be_a Array
|
283
|
+
expect(table[->(i,j,k){ [i,j,k] }, 3, 1..3, [5, 1, -2]]).to eq \
|
282
284
|
[
|
283
|
-
[[[1, 2, 5], [1, 2, 3], [1, 2, 1]], [[1, 3, 5], [1, 3, 3], [1, 3, 1]]],
|
284
|
-
[[[2, 2, 5], [2, 2, 3], [2, 2, 1]], [[2, 3, 5], [2, 3, 3], [2, 3, 1]]],
|
285
|
-
[[[3, 2, 5], [3, 2, 3], [3, 2, 1]], [[3, 3, 5], [3, 3, 3], [3, 3, 1]]]
|
285
|
+
[[[1, 1, 5], [1, 1, 3], [1, 1, 1]], [[1, 2, 5], [1, 2, 3], [1, 2, 1]], [[1, 3, 5], [1, 3, 3], [1, 3, 1]]],
|
286
|
+
[[[2, 1, 5], [2, 1, 3], [2, 1, 1]], [[2, 2, 5], [2, 2, 3], [2, 2, 1]], [[2, 3, 5], [2, 3, 3], [2, 3, 1]]],
|
287
|
+
[[[3, 1, 5], [3, 1, 3], [3, 1, 1]], [[3, 2, 5], [3, 2, 3], [3, 2, 1]], [[3, 3, 5], [3, 3, 3], [3, 3, 1]]]
|
286
288
|
]
|
287
289
|
end
|
288
290
|
|
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.5.
|
4
|
+
version: 2.5.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: 2016-
|
11
|
+
date: 2016-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|