lib/hashformer/generate.rb in hashformer-0.2.1 vs lib/hashformer/generate.rb in hashformer-0.2.2

- old
+ new

@@ -119,15 +119,34 @@ "#{self.class.name}: #{@calls.map{|c| c[:name]}}" end alias inspect to_s end - # TODO: Add a constant generator (that can be chained?) + # Internal representation of a constant output value. Do not instantiate + # directly; call Hashformer::Generate.const (or HF::G.const) instead. + class Constant + attr_reader :value + def initialize(value) + @value = value + end + end + + + # Generates a transformation that always returns a constant value. + # + # Examples: + # HF::G.const(5) + def self.const(value) + Constant.new(value) + end + # Generates a transformation that passes one or more values from the input # Hash (denoted by key names or paths (see Hashformer::Generate.path) to # the block. If the block is not given, then the values are placed in an # array in the order in which their keys were given as parameters. + # + # You can also pass a Hashformer transformation Hash as one or more keys. # # Examples: # HF::G.map(:first, :last) do |f, l| "#{f} #{l}".strip end # HF::G.map(:a1, :a2) # Turns {a1: 1, a2: 2} into [1, 2] # HF::G.map(HF::G.path[:address][:line1], HF::G.path[:address][:line2])