class Creamerscript::Sweeteners::Base

Constants

SYMBOL

Attributes

source[RW]
substitutions[RW]

Public Class Methods

new() click to toggle source
# File lib/creamerscript/sweeteners/base.rb, line 8
def initialize
  @substitutions = {}
end

Public Instance Methods

call(id) click to toggle source
# File lib/creamerscript/sweeteners/base.rb, line 12
def call(id)
  @source = substitutions[id]
end
substitute(source) click to toggle source
# File lib/creamerscript/sweeteners/base.rb, line 20
def substitute(source)
  source.gsub!(pattern) { |match| tokenize(match) }
end
to_coffee() click to toggle source
# File lib/creamerscript/sweeteners/base.rb, line 16
def to_coffee
  source
end
token() click to toggle source
# File lib/creamerscript/sweeteners/base.rb, line 28
def token
  "_____CREAMER_#{type.upcase}_#{substitutions.size}_____"
end
tokenize(substitution) click to toggle source
# File lib/creamerscript/sweeteners/base.rb, line 24
def tokenize(substitution)
  token.tap { substitutions[substitutions.size] = substitution }
end
type() click to toggle source
# File lib/creamerscript/sweeteners/base.rb, line 32
def type
  self.class.name.split("::").last.underscore.to_sym
end