Class: Build::Text::Substitutions::SymbolicSubstitution

Inherits:
Object
  • Object
show all
Defined in:
lib/build/text/substitutions.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(keyword, value) ⇒ SymbolicSubstitution

Returns a new instance of SymbolicSubstitution.



80
81
82
83
# File 'lib/build/text/substitutions.rb', line 80

def initialize(keyword, value)
	@keyword = keyword
	@value = value
end

Instance Attribute Details

#keywordObject (readonly)

Returns the value of attribute keyword.



85
86
87
# File 'lib/build/text/substitutions.rb', line 85

def keyword
  @keyword
end

#valueObject (readonly)

Returns the value of attribute value.



86
87
88
# File 'lib/build/text/substitutions.rb', line 86

def value
  @value
end

Class Method Details

.apply(text, group) ⇒ Object



99
100
101
102
103
104
105
# File 'lib/build/text/substitutions.rb', line 99

def self.apply(text, group)
	substitutions = Hash[group.collect{|substitution| [substitution.keyword, substitution.value]}]

	pattern = Regexp.new(substitutions.keys.map{|key| Regexp.escape(key)}.join('|'))

	text.gsub(pattern) {|key| substitutions[key]}
end

Instance Method Details

#apply(text) ⇒ Object



95
96
97
# File 'lib/build/text/substitutions.rb', line 95

def apply(text)
	text.gsub(@keyword, @value)
end

#freezeObject



88
89
90
91
92
93
# File 'lib/build/text/substitutions.rb', line 88

def freeze
	@keyword.freeze
	@value.freeze
	
	super
end