Class: ItemProcessor
- Inherits:
-
Object
- Object
- ItemProcessor
- Defined in:
- lib/textplacer/item_processor.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
-
#initialize(source, context) ⇒ ItemProcessor
constructor
A new instance of ItemProcessor.
- #perform ⇒ Object
Constructor Details
#initialize(source, context) ⇒ ItemProcessor
Returns a new instance of ItemProcessor.
4 5 6 7 |
# File 'lib/textplacer/item_processor.rb', line 4 def initialize(source, context) @source = source.dup @context = context end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
2 3 4 |
# File 'lib/textplacer/item_processor.rb', line 2 def context @context end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
2 3 4 |
# File 'lib/textplacer/item_processor.rb', line 2 def source @source end |
Instance Method Details
#perform ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/textplacer/item_processor.rb', line 9 def perform items = source.scan /({{(.+?)}})/m items.each do |replace, key| source.gsub! replace, context.indifferent_fetch(key).to_s end source end |