Class: Xcop::Document
- Inherits:
-
Object
- Object
- Xcop::Document
- Defined in:
- lib/xcop/document.rb
Overview
One document.
- Author
-
Yegor Bugayenko ([email protected])
- Copyright
-
Copyright © 2017-2025 Yegor Bugayenko
- License
-
MIT
Instance Method Summary collapse
-
#diff(nocolor: false) ⇒ Object
Return the difference, if any (empty string if everything is clean).
-
#fix ⇒ Object
Fixes the document.
-
#initialize(path) ⇒ Document
constructor
Ctor.
Constructor Details
#initialize(path) ⇒ Document
Ctor.
path
-
Path of it
33 34 35 |
# File 'lib/xcop/document.rb', line 33 def initialize(path) @path = path end |
Instance Method Details
#diff(nocolor: false) ⇒ Object
Return the difference, if any (empty string if everything is clean).
38 39 40 41 42 43 |
# File 'lib/xcop/document.rb', line 38 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 |
#fix ⇒ Object
Fixes the document.
46 47 48 49 50 |
# File 'lib/xcop/document.rb', line 46 def fix xml = Nokogiri::XML(File.open(@path), &:noblanks) ideal = xml.to_xml(indent: 2) File.write(@path, ideal) end |