Class: Retl::PathBuilder
- Inherits:
-
Object
- Object
- Retl::PathBuilder
- Defined in:
- lib/retl/path_builder.rb
Instance Method Summary collapse
- #calculate(key, action = nil, &block) ⇒ Object (also: #calc)
- #depends_on(name, source = nil, &block) ⇒ Object
- #explode(action = nil, &block) ⇒ Object
- #filter(predicate = nil, &block) ⇒ Object (also: #select)
- #fork(name, &block) ⇒ Object
-
#initialize(path, &block) ⇒ PathBuilder
constructor
A new instance of PathBuilder.
- #inspect(action = nil, &block) ⇒ Object
- #reject(predicate = nil, &block) ⇒ Object
- #step(step = nil, handler: StepHandler, &block) ⇒ Object (also: #replace)
- #transform(action = nil, &block) ⇒ Object
Constructor Details
#initialize(path, &block) ⇒ PathBuilder
Returns a new instance of PathBuilder.
10 11 12 13 |
# File 'lib/retl/path_builder.rb', line 10 def initialize(path, &block) @path = path instance_eval(&block) end |
Instance Method Details
#calculate(key, action = nil, &block) ⇒ Object Also known as: calc
46 47 48 49 |
# File 'lib/retl/path_builder.rb', line 46 def calculate(key, action=nil, &block) action ||= block transform { |data, context| data[key] = context.execute_step(action, data) } end |
#depends_on(name, source = nil, &block) ⇒ Object
52 53 54 55 |
# File 'lib/retl/path_builder.rb', line 52 def depends_on(name, source=nil, &block) source ||= block @path.add_dependency(name, source) end |
#explode(action = nil, &block) ⇒ Object
57 58 59 60 |
# File 'lib/retl/path_builder.rb', line 57 def explode(action=nil, &block) action ||= block step(action, handler: ExplodeHandler) end |
#filter(predicate = nil, &block) ⇒ Object Also known as: select
26 27 28 29 |
# File 'lib/retl/path_builder.rb', line 26 def filter(predicate=nil, &block) predicate ||= block step(predicate, handler: FilterHandler) end |
#fork(name, &block) ⇒ Object
32 33 34 |
# File 'lib/retl/path_builder.rb', line 32 def fork(name, &block) @path.add_fork_builder(name, &block) end |
#inspect(action = nil, &block) ⇒ Object
36 37 38 39 |
# File 'lib/retl/path_builder.rb', line 36 def inspect(action=nil, &block) action ||= block step(action, handler: InspectHandler) end |
#reject(predicate = nil, &block) ⇒ Object
41 42 43 44 |
# File 'lib/retl/path_builder.rb', line 41 def reject(predicate=nil, &block) predicate ||= block filter { |data, context| !context.execute_step(predicate, data) } end |
#step(step = nil, handler: StepHandler, &block) ⇒ Object Also known as: replace
15 16 17 18 |
# File 'lib/retl/path_builder.rb', line 15 def step(step=nil, handler: StepHandler, &block) step ||= block @path.add_step step, handler: handler end |
#transform(action = nil, &block) ⇒ Object
21 22 23 24 |
# File 'lib/retl/path_builder.rb', line 21 def transform(action=nil, &block) action ||= block step(action, handler: TransformHandler) end |