calyx 0.4.0 → 0.4.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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/calyx.rb +11 -2
  3. data/lib/calyx/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5ce625a176cd41a95aac8b5c2dcadc0ef95e3bf3
4
- data.tar.gz: b0c911bdc364efe49b1c8d882823426eda62c23a
3
+ metadata.gz: 719581f0b1a1255f386ed91d64b2d956b1e7820c
4
+ data.tar.gz: 173aaada6063be3dad4c1eaa707390608a5b952e
5
5
  SHA512:
6
- metadata.gz: d323c2e78271a53a8de7c8fe1b1925a35e0f0f20b85bc8fca503ac099f9517f3c2279a66e4cae765519acc58a9544d103e4bacfd34030b982eba05f363390e36
7
- data.tar.gz: 348d17e64e1783360e947f9cca81d3770a1dc22c7cacc94f7977a6b2dc2fae472ecc677cf7e3c433968863704b6f7e097f50e09330d7f0024ea7783c4386a1d4
6
+ metadata.gz: c1510e5ba1db72a661965766c78cb5e6a79e04be682997c2e1f4ddf5c85623c9eb5785bc273a492feed090704e84cc78dc791a4ccdbadec9ac2e436b1849009a
7
+ data.tar.gz: b835c0ddee655a64bdad32f8487aa1563812a355c916713e8e9476a0a021f0cf689639a0a986591e3777a8b81a40ca55173140f3bc3e800f04516cc7b4ad6c0b
@@ -88,7 +88,15 @@ module Calyx
88
88
 
89
89
  raise 'Weights must sum to 1' if weights_sum != 1.0
90
90
 
91
- self.new(productions)
91
+ choices = productions.map do |choice, weight|
92
+ if choice.is_a?(String)
93
+ [Concat.parse(choice), weight]
94
+ elsif choice.is_a?(Symbol)
95
+ [NonTerminal.new(choice), weight]
96
+ end
97
+ end
98
+
99
+ self.new(choices)
92
100
  end
93
101
 
94
102
  def initialize(collection)
@@ -96,7 +104,8 @@ module Calyx
96
104
  end
97
105
 
98
106
  def evaluate(registry)
99
- @collection.max_by { |_, weight| rand ** (1.0 / weight) }.first
107
+ choice = @collection.max_by { |_, weight| rand ** (1.0 / weight) }.first
108
+ choice.evaluate(registry)
100
109
  end
101
110
  end
102
111
 
@@ -1,3 +1,3 @@
1
1
  module Calyx
2
- VERSION = '0.4.0'.freeze
2
+ VERSION = '0.4.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: calyx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Rickerby