lib/parslet/transform.rb in parslet-1.3.0 vs lib/parslet/transform.rb in parslet-1.4.0

- old
+ new

@@ -129,16 +129,16 @@ @__transform_rules << [Parslet::Pattern.new(expression), block] end # Allows accessing the class' rules # - def rules # :nodoc: + def rules @__transform_rules || [] end end - def initialize(&block) # :nodoc: + def initialize(&block) @rules = [] if block instance_eval(&block) end @@ -181,11 +181,10 @@ # # If you would like the current environment preserved, please use the # arity 1 variant of the block. Alternatively, you can inject a context object # and call methods on it (think :ctx => self). # - # Example: # # the local variable a is simulated # t.call_on_match(:a => :b) { a } # # no change of environment here # t.call_on_match(:a => :b) { |d| d[:a] } # @@ -201,30 +200,37 @@ end # Allow easy access to all rules, the ones defined in the instance and the # ones predefined in a subclass definition. # - def rules # :nodoc: + def rules self.class.rules + @rules end - def transform_elt(elt, context) # :nodoc: + # @api private + # + def transform_elt(elt, context) rules.each do |pattern, block| if bindings=pattern.match(elt, context) # Produces transformed value return call_on_match(bindings, block) end end # No rule matched - element is not transformed return elt end - def recurse_hash(hsh, ctx) # :nodoc: + + # @api private + # + def recurse_hash(hsh, ctx) hsh.inject({}) do |new_hsh, (k,v)| new_hsh[k] = apply(v, ctx) new_hsh end end - def recurse_array(ary, ctx) # :nodoc: + # @api private + # + def recurse_array(ary, ctx) ary.map { |elt| apply(elt, ctx) } end end \ No newline at end of file