algebrick 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/lib/algebrick.rb +34 -2
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3afd890330088870db253424a7296f619666dbe5
4
- data.tar.gz: 6660ee990c34420c9599f5cb2f43a80c1d33ae4e
3
+ metadata.gz: 9166938f13bced97656434796a7d426cf19a7396
4
+ data.tar.gz: eea50d70bef296d2d9f7ad18554ddae07d771eb8
5
5
  SHA512:
6
- metadata.gz: d737796cb0b2ece44f606cf2d5cc9c6273893b23de0c355ebb290f09e6e35e997d33af220298bded254281ffe71cfed4abd5680c3646a004f385c7240b306980
7
- data.tar.gz: baeb8506f6f66ee19891b1f2921b8fe45e4aa5efeecb22b2e2b3b6c23ad4e421ebad7f7c2c035d88b6563028adadcd7b9805d67c2a9b8ae72715b0e6afb70f96
6
+ metadata.gz: 7a6f6620de67a7c6dc50d28874996e2a1596fdf590bcfa71158e42fc648a2f0c70ae7e39c81b84281b0a2abe7262e33fcb88997ed78ca04321d3f66201d8f71a
7
+ data.tar.gz: 466e978ff88c63b24378c42b633def34e90cd60cc6ac79938b46e705f2d4ed5ddb2b9edd6fcdd2dc3c3dabe62afdc8270fa9c78e10f15a63b00c2d69c7d5040a
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.3.2
data/lib/algebrick.rb CHANGED
@@ -58,6 +58,7 @@ module Algebrick
58
58
  end
59
59
 
60
60
  module TypeCheck
61
+ # FIND: type checking of collections?
61
62
  def Type?(value, *types)
62
63
  types.any? { |t| value.is_a? t }
63
64
  end
@@ -321,10 +322,41 @@ module Algebrick
321
322
  if type.field_names?
322
323
  type.field_names.map { |name| "#{name}: #{self[name].to_s}" }.join(', ')
323
324
  else
324
- fields.map(&:to_s).join(',')
325
+ fields.map(&:to_s).join(', ')
325
326
  end + ']'
326
327
  end
327
328
 
329
+ def pretty_print(q)
330
+ q.group(1, "#{self.class.type.name}[", ']') do
331
+ if type.field_names?
332
+ type.field_names.each_with_index do |name, i|
333
+ if i == 0
334
+ q.breakable ''
335
+ else
336
+ q.text ','
337
+ q.breakable ' '
338
+ end
339
+ q.text name.to_s
340
+ q.text ':'
341
+ q.group(1) do
342
+ q.breakable ' '
343
+ q.pp self[name]
344
+ end
345
+ end
346
+ else
347
+ fields.each_with_index do |value, i|
348
+ if i == 0
349
+ q.breakable ''
350
+ else
351
+ q.text ','
352
+ q.breakable ' '
353
+ end
354
+ q.pp value
355
+ end
356
+ end
357
+ end
358
+ end
359
+
328
360
  def to_ary
329
361
  @fields
330
362
  end
@@ -1107,7 +1139,7 @@ module Algebrick
1107
1139
  raise ArgumentError, "no #{dif} fields in #{algebraic_type}"
1108
1140
  end
1109
1141
  algebraic_type.field_names.map do |field|
1110
- field_matchers[field] || Algebrick.any
1142
+ field_matchers.key?(field) ? field_matchers[field] : Algebrick.any
1111
1143
  end
1112
1144
 
1113
1145
  # AProduct.(:field_name)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: algebrick
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Petr Chalupa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-17 00:00:00.000000000 Z
11
+ date: 2013-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -157,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
157
  version: '0'
158
158
  requirements: []
159
159
  rubyforge_project:
160
- rubygems_version: 2.0.0
160
+ rubygems_version: 2.0.3
161
161
  signing_key:
162
162
  specification_version: 4
163
163
  summary: Algebraic types and pattern matching for Ruby