Module: K::Replace::Keys
- Included in:
- Statement
- Defined in:
- lib/k/replace/keys.rb
Instance Method Summary collapse
Instance Method Details
#chain_properties(text) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/k/replace/keys.rb', line 15 def chain_properties(text) keys, obj = find_all(text), Hash.new obj.tap do |it| keys.each do |i| it.merge!(chain_property(i)) do |k, ov, nv| if ov.kind_of?(Array) && nv.kind_of?(Array) ov.concat(nv).uniq elsif ov.kind_of?(Array) && !nv.kind_of?(Array) ov.<<(nv).uniq else [ ov, nv ] end end end end end |
#chain_property(property) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/k/replace/keys.rb', line 32 def chain_property(property) Hash.new.tap do |hash| hash.merge!(array_chain(property.split('.'))) do |k, ov, nv| if ov.kind_of?(Array) && nv.kind_of?(Array) ov.concat(nv).uniq else ov << nv if ov.kind_of?(Array) end end end end |
#find_all(text) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/k/replace/keys.rb', line 6 def find_all(text) [].tap do |arr| text.scan(kreplace.key_pattern) do |match| yield match[0] if block_given? arr << match[0] end end.flatten.compact end |