Class: ItemProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/textplacer/item_processor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#contextObject (readonly)

Returns the value of attribute context.



2
3
4
# File 'lib/textplacer/item_processor.rb', line 2

def context
  @context
end

#sourceObject (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

#performObject



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