Class: K::Replace::Statement

Inherits:
Object
  • Object
show all
Includes:
Changes, Keys
Defined in:
lib/k/replace/statement.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Keys

#chain_properties, #chain_property, #find_all

Constructor Details

#initialize(source) ⇒ Statement

Returns a new instance of Statement.



13
14
15
16
17
18
19
20
# File 'lib/k/replace/statement.rb', line 13

def initialize(source)
  @keys = []
  @source = source

  find_all(@source) do |key|
    @keys << key
  end
end

Instance Attribute Details

#keysObject (readonly)

Returns the value of attribute keys.



10
11
12
# File 'lib/k/replace/statement.rb', line 10

def keys
  @keys
end

#sourceObject (readonly)

Returns the value of attribute source.



10
11
12
# File 'lib/k/replace/statement.rb', line 10

def source
  @source
end

Instance Method Details

#replace(*objects) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/k/replace/statement.rb', line 22

def replace(*objects)
  objs = hash_objects(objects)
  @source.gsub(kreplace.key_pattern) do |key|
    replaced = ''
    find_all(key) do |match|
      chained = chain_property(match)
      chained.each{|k, v| replaced = resolve_property(k, v, objs[k])}
    end
    replaced
  end
end