Module: Goat::DOMTools::DiffTools
- Included in:
- DOMDiff
- Defined in:
- lib/goat/dom.rb
Defined Under Namespace
Classes: NoParentDOMID, TextualTranspose
Instance Method Summary
collapse
Instance Method Details
#added(obj, par, pos) ⇒ Object
424
425
426
427
428
|
# File 'lib/goat/dom.rb', line 424
def added(obj, par, pos)
raise NoParentDOMID if par.nil?
raise TextualTranspose if obj.kind_of?(String)
[:add, par, pos, *normalized_tags(obj)]
end
|
#dom_node?(node) ⇒ Boolean
409
410
411
412
|
# File 'lib/goat/dom.rb', line 409
def dom_node?(node)
node.is_a?(Array) && node.first.is_a?(Symbol)
end
|
#lcs_is_addition?(diff) ⇒ Boolean
436
|
# File 'lib/goat/dom.rb', line 436
def lcs_is_addition?(diff); diff.action == '+'; end
|
#lcs_is_removal?(diff) ⇒ Boolean
437
|
# File 'lib/goat/dom.rb', line 437
def lcs_is_removal?(diff); diff.action == '-'; end
|
#lcs_is_replacement?(d1, d2) ⇒ Boolean
414
415
416
417
418
|
# File 'lib/goat/dom.rb', line 414
def lcs_is_replacement?(d1, d2)
d1 && d2 && d1.position == d2.position && (
(d1.action == '+' && d2.action == '-') ||
(d1.action == '-' && d2.action == '+'))
end
|
#lcs_old_and_new(d1, d2) ⇒ Object
420
421
422
|
# File 'lib/goat/dom.rb', line 420
def lcs_old_and_new(d1, d2)
d1.action == '+' ? [d2, d1] : [d1, d2]
end
|
#removed(obj, par, pos) ⇒ Object
430
431
432
433
434
|
# File 'lib/goat/dom.rb', line 430
def removed(obj, par, pos)
raise NoParentDOMID if par.nil?
raise TextualTranspose if obj.kind_of?(String)
[:rem, par, pos, *normalized_tags(obj)]
end
|
#type_of(x) ⇒ Object
399
400
401
402
403
404
405
406
407
|
# File 'lib/goat/dom.rb', line 399
def type_of(x)
if x.is_a?(String)
:string
elsif x.is_a?(Array)
dom_node?(x) ? :node : :array
else
('cls_' + x.class.name.downcase).to_sym
end
end
|