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.



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

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”



84
85
86
87
# File 'lib/ruote/svc/dollar_sub.rb', line 84

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)



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

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.inject({}) { |h, (k, v)|

      h[s(k, flow_expression, workitem)] = s(v, flow_expression, workitem)
      h
    }

  else

    text
  end
end