Class: Xcop::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/xcop/document.rb

Overview

One document.

Author

Yegor Bugayenko (yegor256@gmail.com)

Copyright

Copyright © 2017-2026 Yegor Bugayenko

License

MIT

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Document

Ctor.

path

Path of it



16
17
18
# File 'lib/xcop/document.rb', line 16

def initialize(path)
  @path = path
end

Instance Method Details

#diff(nocolor: false) ⇒ Object

Return the difference, if any (empty string if everything is clean).



21
22
23
24
25
26
# File 'lib/xcop/document.rb', line 21

def diff(nocolor: false)
  xml = Nokogiri::XML(File.open(@path), &:noblanks)
  ideal = xml.to_xml(indent: 2)
  now = File.read(@path)
  differ(ideal, now, nocolor: nocolor)
end

#fixObject

Fixes the document.



29
30
31
32
33
# File 'lib/xcop/document.rb', line 29

def fix
  xml = Nokogiri::XML(File.open(@path), &:noblanks)
  ideal = xml.to_xml(indent: 2)
  File.write(@path, ideal)
end