Class: Flowcation::Substitution
- Inherits:
-
Object
- Object
- Flowcation::Substitution
- Defined in:
- lib/flowcation/substitution.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
-
#xpath ⇒ Object
readonly
Returns the value of attribute xpath.
Instance Method Summary collapse
- #apply(doc) ⇒ Object
-
#initialize(name, xpath, type, value, key) ⇒ Substitution
constructor
A new instance of Substitution.
Constructor Details
#initialize(name, xpath, type, value, key) ⇒ Substitution
Returns a new instance of Substitution.
4 5 6 |
# File 'lib/flowcation/substitution.rb', line 4 def initialize(name, xpath, type, value, key) @name, @xpath, @type, @value, @key = name, xpath, type, value, key end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/flowcation/substitution.rb', line 3 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
3 4 5 |
# File 'lib/flowcation/substitution.rb', line 3 def type @type end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
3 4 5 |
# File 'lib/flowcation/substitution.rb', line 3 def value @value end |
#xpath ⇒ Object (readonly)
Returns the value of attribute xpath.
3 4 5 |
# File 'lib/flowcation/substitution.rb', line 3 def xpath @xpath end |
Instance Method Details
#apply(doc) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/flowcation/substitution.rb', line 7 def apply(doc) element = doc.at_xpath(@xpath) raise SubstitutionNotFoundException.build(xpath: @xpath, name: @name) unless element case @type when 'content' doc.at_xpath(@xpath).content = @value when 'attribute' doc.at_xpath(@xpath).attributes[@key].value = @value when 'replace' doc.at_xpath(@xpath).replace Nokogiri::XML::Text.new(@value, doc.document) when 'append' puts "APPEND #{doc.at_xpath(@xpath).class}" doc.at_xpath(@xpath).after Nokogiri::XML::Text.new(@value, doc.document) when 'replace_collection' doc.xpath(@xpath).first.replace Nokogiri::XML::Text.new(@value, doc.document) doc.xpath(@xpath).each do |node| node.remove if node.is_a? Nokogiri::XML::Element end end doc end |