Class: Transformator::Transformation
- Inherits:
-
Object
- Object
- Transformator::Transformation
- Defined in:
- lib/transformator/transformation.rb
Instance Method Summary collapse
- #apply_to(source, options = {}) ⇒ Object
-
#initialize(options = {}, &block) ⇒ Transformation
constructor
A new instance of Transformation.
Constructor Details
#initialize(options = {}, &block) ⇒ Transformation
Returns a new instance of Transformation.
4 5 6 7 8 |
# File 'lib/transformator/transformation.rb', line 4 def initialize( = {}, &block) @context = [:context] @rules = [] self.instance_eval(&block) if block end |
Instance Method Details
#apply_to(source, options = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/transformator/transformation.rb', line 10 def apply_to(source, = {}) source = Ox.parse(source) if source.is_a?(String) result = Ox::Document.new(version: "1.0", encoding: "UTF-8").tap do |target| @rules.each do |rule| apply_rule(rule, source, target, ) end end Ox.dump(result, with_xml: true) end |