class Build::Text::Substitutions

Attributes

ordered[R]

Public Class Methods

new(ordered = []) click to toggle source
# File lib/build/text/substitutions.rb, line 26
def initialize(ordered = [])
        @ordered = ordered
end

Public Instance Methods

+(other) click to toggle source
# File lib/build/text/substitutions.rb, line 49
def + other
        Substitutions.new(@ordered + other.ordered)
end
<<(substitution) click to toggle source
# File lib/build/text/substitutions.rb, line 45
def << substitution
        @ordered << substition
end
[]=(keyword, value) click to toggle source
# File lib/build/text/substitutions.rb, line 36
def []= keyword, value
        if Array === value
                open, close = *value.each_slice(value.length / 2)
                @ordered << NestedSubstitution.new(keyword, open, close)
        else
                @ordered << SymbolicSubstitution.new('$' + keyword, value.to_s)
        end
end
apply(text) click to toggle source
# File lib/build/text/substitutions.rb, line 59
def apply(text)
        return text unless @ordered.count > 0
        
        grouped = [[@ordered.first]]
        
        @ordered.drop(1).each do |substitution|
                if grouped.last[0].class == substitution.class
                        grouped.last << substitution
                else
                        grouped << [substitution]
                end
        end
        
        grouped.each do |group|
                text = group.first.class.apply(text, group)
        end
        
        return text
end
call(text) click to toggle source
# File lib/build/text/substitutions.rb, line 55
def call(text)
        apply(text)
end
freeze() click to toggle source
Calls superclass method
# File lib/build/text/substitutions.rb, line 30
def freeze
        @ordered.freeze
        
        super
end