Class: Creamerscript::Sweeteners::Base
- Inherits:
-
Object
- Object
- Creamerscript::Sweeteners::Base
show all
- Defined in:
- lib/creamerscript/sweeteners/base.rb
Constant Summary
collapse
- SYMBOL =
/[A-Za-z0-9$_@]+/
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
8
9
10
|
# File 'lib/creamerscript/sweeteners/base.rb', line 8
def initialize
@substitutions = {}
end
|
Instance Attribute Details
Returns the value of attribute source.
6
7
8
|
# File 'lib/creamerscript/sweeteners/base.rb', line 6
def source
@source
end
|
#substitutions ⇒ Object
Returns the value of attribute substitutions.
6
7
8
|
# File 'lib/creamerscript/sweeteners/base.rb', line 6
def substitutions
@substitutions
end
|
Instance Method Details
12
13
14
|
# File 'lib/creamerscript/sweeteners/base.rb', line 12
def call(id)
@source = substitutions[id]
end
|
#substitute(source) ⇒ Object
20
21
22
|
# File 'lib/creamerscript/sweeteners/base.rb', line 20
def substitute(source)
source.gsub!(pattern) { |match| tokenize(match) }
end
|
#to_coffee ⇒ Object
16
17
18
|
# File 'lib/creamerscript/sweeteners/base.rb', line 16
def to_coffee
source
end
|
28
29
30
|
# File 'lib/creamerscript/sweeteners/base.rb', line 28
def token
"_____CREAMER_#{type.upcase}_#{substitutions.size}_____"
end
|
#tokenize(substitution) ⇒ Object
24
25
26
|
# File 'lib/creamerscript/sweeteners/base.rb', line 24
def tokenize(substitution)
token.tap { substitutions[substitutions.size] = substitution }
end
|
32
33
34
|
# File 'lib/creamerscript/sweeteners/base.rb', line 32
def type
self.class.name.split("::").last.underscore.to_sym
end
|