calyx 0.13.0 → 0.14.0

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: b083064b7b93a5747ec7833b4e3ca46394f8f45b
4
- data.tar.gz: d87854cd9b134257987fef4febfae492a7665d3d
3
+ metadata.gz: b7beefadeb8e2f98a6c802a85dec4fb2ee9a81de
4
+ data.tar.gz: aeeb4015155d4ea728f0289fff21488fda88d37d
5
5
  SHA512:
6
- metadata.gz: 267238c9ed8dedc16de8096c53fc362d16f77a25f60ac5f0eb475c304740a44a1530fa236a9cb30f2175da7e39b20729555376b9c18af5118ea83f01711e86ef
7
- data.tar.gz: 1dabb4bc4cd57d42e2887039ced705b9e10c6347e22714414103a737e52c4096ac378db9a6320a6902ab5036691d341a68c13b781bdc8a10062c0ddfd2ef31e4
6
+ metadata.gz: ee1a4994645a80f6ceef3824f348653a9ac44eee32f127db31f457c4ca57c5e5ff26b5228109ba6f407d5ca7c3761d1632b3adcdfb65dd165e8b18d0d1dac24b
7
+ data.tar.gz: 3cd0f9955a377a9e97d4f62b1b2e2b5f256af0dd33089de81fa95d938f29633e0c771ba71d9fd581ed23f310d8edc29c18f4ad3b43b953fbeb905cf2ca100ac0
data/README.md CHANGED
@@ -489,7 +489,9 @@ Rough plan for stabilising the API and features for a `1.0` release.
489
489
  | `0.9` | ~~return grammar tree from `#evaluate`, with flattened string from `#generate` being separate~~ |
490
490
  | `0.10` | ~~inject custom string functions for parameterised rules, transforms and mappings~~ |
491
491
  | `0.11` | ~~support YAML format (and JSON?)~~ |
492
- | `1.0` | ~~API documentation~~ |
492
+ | `0.12` | ~~API documentation~~ |
493
+ | `0.13` | ~~Support for unique rules~~ |
494
+ | `0.14` | Options config and ‘strict mode’ error handling |
493
495
 
494
496
  ## Credits
495
497
 
@@ -503,6 +505,6 @@ Rough plan for stabilising the API and features for a `1.0` release.
503
505
 
504
506
  ## License
505
507
 
506
- Calyx is open source and provided under the terms of the MIT license. Copyright (c) 2015-2016 [Editorial Technology](http://editorial.technology/).
508
+ Calyx is open source and provided under the terms of the MIT license. Copyright (c) 2015-2017 [Editorial Technology](http://editorial.technology/).
507
509
 
508
510
  See the `LICENSE` file [included with the project distribution](https://github.com/maetl/calyx/blob/master/LICENSE) for more information.
data/lib/calyx/grammar.rb CHANGED
@@ -98,16 +98,29 @@ module Calyx
98
98
  # Grammar rules can be constructed on the fly when the passed-in block is
99
99
  # evaluated.
100
100
  #
101
- # @param [Numeric, Random] random
102
- def initialize(random=Random.new, &block)
103
- if random.is_a?(Numeric)
104
- @random = Random.new(random)
101
+ # @param [Numeric, Random, Hash] options
102
+ def initialize(options={}, &block)
103
+ unless options.is_a?(Hash)
104
+ config_opts = {}
105
+ if options.is_a?(Numeric)
106
+ config_opts[:seed] = options
107
+ elsif options.is_a?(Random)
108
+ config_opts[:rng] = options
109
+ end
105
110
  else
106
- @random = random
111
+ config_opts = options.dup
112
+ end
113
+
114
+ @random = if config_opts.key?(:seed)
115
+ Random.new(config_opts[:seed])
116
+ elsif config_opts.key?(:rng)
117
+ config_opts[:rng]
118
+ else
119
+ Random.new
107
120
  end
108
121
 
109
122
  if block_given?
110
- @registry = Registry.new
123
+ @registry = Registry.new(config_opts)
111
124
  @registry.instance_eval(&block)
112
125
  else
113
126
  @registry = self.class.registry
@@ -4,7 +4,8 @@ module Calyx
4
4
  attr_reader :rules, :transforms, :modifiers
5
5
 
6
6
  # Construct an empty registry.
7
- def initialize
7
+ def initialize(options={})
8
+ @options = {}
8
9
  @rules = {}
9
10
  @transforms = {}
10
11
  @modifiers = Modifiers.new
data/lib/calyx/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Calyx
2
- VERSION = '0.13.0'.freeze
2
+ VERSION = '0.14.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: calyx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Rickerby
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-07 00:00:00.000000000 Z
11
+ date: 2017-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler