Class: K::Replace::Statement
- Inherits:
-
Object
- Object
- K::Replace::Statement
- Includes:
- DynamicAccessors, Keys
- Defined in:
- lib/k/replace/statement.rb
Instance Attribute Summary collapse
-
#keys ⇒ Object
readonly
Returns the value of attribute keys.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
-
#initialize(source) ⇒ Statement
constructor
A new instance of Statement.
- #replace(hash) ⇒ Object
Methods included from DynamicAccessors
Methods included from Keys
#chain_properties, #chain_property, #find_all
Constructor Details
#initialize(source) ⇒ Statement
Returns a new instance of Statement.
11 12 13 14 15 16 17 18 |
# File 'lib/k/replace/statement.rb', line 11 def initialize(source) @keys = [] @source = source find_all(@source) do |key| @keys << key end end |
Instance Attribute Details
#keys ⇒ Object (readonly)
Returns the value of attribute keys.
9 10 11 |
# File 'lib/k/replace/statement.rb', line 9 def keys @keys end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
9 10 11 |
# File 'lib/k/replace/statement.rb', line 9 def source @source end |
Instance Method Details
#replace(hash) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/k/replace/statement.rb', line 20 def replace(hash) @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, hash[k])} end replaced end end |