Class: Ruote::DollarSubstitution

Inherits:
Object
  • Object
show all
Defined in:
lib/ruote/svc/dollar_sub.rb

Overview

This service is in charge of extrapolating strings like “$f:nada == $f:y”.

It relies on the rufus-dollar gem.

It's OK to override this service with your own.

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ DollarSubstitution

Returns a new instance of DollarSubstitution


42
43
44
45
# File 'lib/ruote/svc/dollar_sub.rb', line 42

def initialize(context)

  @context = context
end

Instance Method Details

#dict_classObject

This method is public, for easy overriding. This implementation returns Ruote::Dollar::Dict whose instances are used to extrapolate dollar strings like “$f:customer” or “$Ruote::DollarSubstitution.r:Timer:Time.nowr:Time.now.to_s/$f:year_target”


81
82
83
84
# File 'lib/ruote/svc/dollar_sub.rb', line 81

def dict_class

  ::Ruote::Dollar::Dict
end

#s(text, flow_expression, workitem) ⇒ Object

Performs 'dollar substitution' on a piece of text with as input a flow expression and a workitem (fields and variables).

With help from Nick Petrella (2008/03/20)


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/ruote/svc/dollar_sub.rb', line 52

def s(text, flow_expression, workitem)

  if text.is_a?(String)

    literal_sub(
      Rufus.dsub(text, dict_class.new(flow_expression, workitem)),
      flow_expression,
      workitem)

  elsif text.is_a?(Array)

    text.collect { |e| s(e, flow_expression, workitem) }

  elsif text.is_a?(Hash)

    text.remap { |(k, v), h|
      h[s(k, flow_expression, workitem)] = s(v, flow_expression, workitem)
    }

  else

    text
  end
end