Class: Build::Text::Substitutions::SymbolicSubstitution
- Inherits:
-
Object
- Object
- Build::Text::Substitutions::SymbolicSubstitution
- Defined in:
- lib/build/text/substitutions.rb
Instance Attribute Summary collapse
-
#keyword ⇒ Object
readonly
Returns the value of attribute keyword.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #apply(text) ⇒ Object
- #freeze ⇒ Object
-
#initialize(keyword, value) ⇒ SymbolicSubstitution
constructor
A new instance of SymbolicSubstitution.
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
#keyword ⇒ Object (readonly)
Returns the value of attribute keyword.
85 86 87 |
# File 'lib/build/text/substitutions.rb', line 85 def keyword @keyword end |
#value ⇒ Object (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 |
#freeze ⇒ Object
88 89 90 91 92 93 |
# File 'lib/build/text/substitutions.rb', line 88 def freeze @keyword.freeze @value.freeze super end |