Class: Xcop::Document
- Inherits:
-
Object
- Object
- Xcop::Document
- Defined in:
- lib/xcop.rb
Overview
One document.
Instance Method Summary collapse
-
#diff ⇒ Object
Return the difference, if any (empty string if everything is clean).
-
#fix(license = '') ⇒ Object
Fixes the document.
-
#initialize(path) ⇒ Document
constructor
Ctor.
-
#ldiff(license) ⇒ Object
Return the difference for the license.
Constructor Details
#initialize(path) ⇒ Document
Ctor.
path-
Path of it
73 74 75 |
# File 'lib/xcop.rb', line 73 def initialize(path) @path = path end |
Instance Method Details
#diff ⇒ Object
Return the difference, if any (empty string if everything is clean).
78 79 80 81 82 83 84 85 |
# File 'lib/xcop.rb', line 78 def diff xml = Nokogiri::XML(File.open(@path), &:noblanks) ideal = xml.to_xml(indent: 2) now = File.read(@path) Differ.format = :color return Differ.diff_by_line(ideal, now).to_s unless now == ideal '' end |
#fix(license = '') ⇒ Object
Fixes the document.
98 99 100 101 102 103 104 105 106 107 |
# File 'lib/xcop.rb', line 98 def fix(license = '') xml = Nokogiri::XML(File.open(@path), &:noblanks) unless license.empty? xml.children.before( Nokogiri::XML::Comment.new(xml, license.strip) ) end ideal = xml.to_xml(indent: 2) File.write(@path, ideal) end |
#ldiff(license) ⇒ Object
Return the difference for the license.
88 89 90 91 92 93 94 95 |
# File 'lib/xcop.rb', line 88 def ldiff(license) xml = Nokogiri::XML(File.open(@path), &:noblanks) now = xml.xpath('/comment()')[0].text.to_s.strip ideal = license.strip Differ.format = :color return Differ.diff_by_line(ideal, now).to_s unless now == ideal '' end |