Class: JsonDeepCompare::DocumentComparison::SubstitutionsBuilder::Node
- Inherits:
-
Object
- Object
- JsonDeepCompare::DocumentComparison::SubstitutionsBuilder::Node
- Defined in:
- lib/json-deep-compare/document_comparison.rb
Instance Method Summary collapse
-
#initialize(selector) ⇒ Node
constructor
A new instance of Node.
- #method_missing(meth, *args, &block) ⇒ Object
- #rules ⇒ Object
- #value=(v) ⇒ Object
Constructor Details
#initialize(selector) ⇒ Node
Returns a new instance of Node.
54 55 56 57 |
# File 'lib/json-deep-compare/document_comparison.rb', line 54 def initialize(selector) @selector = selector @sub_nodes = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/json-deep-compare/document_comparison.rb', line 59 def method_missing(meth, *args, &block) if block_given? if args.size == 1 sub_node = Node.new( @selector + " > .#{meth} :nth-child(#{args.first})" ) else sub_node = Node.new(@selector + " > .#{meth}") end yield sub_node elsif args.size == 2 sub_node = Node.new( @selector + " > .#{meth} :nth-child(#{args.first})" ) sub_node.value = args.last else sub_node = Node.new(@selector + " > .#{meth}") sub_node.value = args.first end @sub_nodes << sub_node end |
Instance Method Details
#rules ⇒ Object
81 82 83 |
# File 'lib/json-deep-compare/document_comparison.rb', line 81 def rules @sub_nodes.map { |sn| sn.rules }.flatten.concat([@rule]).compact end |