mll 2.5.0 → 2.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/lib/mll.rb +62 -36
  4. data/spec/_spec.rb +7 -5
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7eaa6d43148b9cdf889647a63e9e8661629d776c
4
- data.tar.gz: 53ad8127bbbc75b201bf98c316042281fdb97390
3
+ metadata.gz: 4e828b7ba71a30c704eb325f81a144113ced5243
4
+ data.tar.gz: 3365c0fb3f69975205447c5b962599e825300c78
5
5
  SHA512:
6
- metadata.gz: 622ac74b5373d2ef998ac01d1f834aeba929ae7a368a5f49b5ca1143ec07ce9dfaf8143486539859d7f79e4931c94e930828d6c3eeea518f36d2b26b9c6f77c4
7
- data.tar.gz: c84783d82d35568dc977fe689483c173afaa9d3159053454796f1a9b06cc80cdb3d89259fd875af4677755e9de43961d7ba87ae1cf4b0f4e7ff0b0f5f590c084
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.0"
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?(:map) && r.first.respond_to?(:map) ?
100
- r.first : range[*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
- options[:spacings] ||= [1, 1]
125
- spacings_horizontal, spacings_vertical = [*options[:spacings]]
126
- spacings_vertical ||= 1
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
- frames = {
135
- nil => " ",
136
- true => "┃ ┏┓ ┗┛━ ┃━━┃ ",
137
- :all => "┃┃┏┓╋┗┛━━┣┳┻┫ ",
138
- }[options[:frame]]
139
- raise ArgumentError.new("unknown value of :frame option '#{options[:frame]}'") if options[:frame] && !frames
140
- # TODO smth with this #.all?
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 - 1
143
- strings = table.map{ |row| row.dup.tap{ |a| a[width] = a[width] }.map(&:to_s) }
144
- sizes = strings.transpose.map{ |col| col.map(&:size).max + [spacings_horizontal * 2 - 2, 0].max }
145
- # TODO https://reference.wolfram.com/language/ref/Alignment.html
146
- border_vertical = [frames[9], sizes.map{ |size| frames[8] * size }.join((frames[4] unless spacings_horizontal.zero?)), frames[12]]
147
- spacing_vertical = [frames[0], sizes.map{ |size| frames[13] * size }.join((frames[0] unless spacings_horizontal.zero?)), frames[0]]
148
- gap_vertical = lambda do |i|
149
- j = i - 1
150
- [*-j..j].map{ |k| [border_vertical][k] || spacings_vertical }
151
- end.call spacings_vertical
152
- [
153
- [frames[2], sizes.map{ |size| frames[7] * size }.join((frames[10] unless spacings_horizontal.zero?)), frames[3]].join,
154
- *([spacing_vertical.join] * [spacings_vertical - 1, 0].max),
155
- strings.map{ |row| [frames[0], row.zip(sizes).map{ |str, size|
156
- str.method(alignment).call(size)
157
- }.join((frames[1] unless spacings_horizontal.zero?)), frames[0]].join }.join(
158
- ?\n + gap_vertical.map{ |gap| gap.join + ?\n }.join
159
- ),
160
- *([spacing_vertical.join] * [spacings_vertical - 1, 0].max),
161
- [frames[5], sizes.map{ |size| frames[7] * size }.join((frames[11] unless spacings_horizontal.zero?)), frames[6]].join,
162
- ].join(?\n) + ?\n
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
 
@@ -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, 2..3, [5, 1, -2]]).to be_a Array
281
- expect(table[->(i,j,k){ [i,j,k] }, 3, 2..3, [5, 1, -2]]).to eq \
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.0
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-06-30 00:00:00.000000000 Z
11
+ date: 2016-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler