Class: K::Replace::Statement
- Inherits:
-
Object
- Object
- K::Replace::Statement
- 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(*objects) ⇒ Object
Methods included from Keys
#chain_properties, #chain_property, #find_all
Constructor Details
#initialize(source) ⇒ Statement
Returns a new instance of Statement.
12 13 14 15 16 17 18 19 |
# File 'lib/k/replace/statement.rb', line 12 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(*objects) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/k/replace/statement.rb', line 21 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 = objs[k].send(v)} end replaced end end |