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).
-
#initialize(path) ⇒ Document
constructor
Ctor.
-
#ldiff(license) ⇒ Object
Return the difference for the license.
Constructor Details
#initialize(path) ⇒ Document
Ctor.
path-
Path of it
36 37 38 |
# File 'lib/xcop.rb', line 36 def initialize(path) @path = path end |
Instance Method Details
#diff ⇒ Object
Return the difference, if any (empty string if everything is clean).
41 42 43 44 45 46 47 |
# File 'lib/xcop.rb', line 41 def diff xml = Nokogiri::XML(File.open(@path), &:noblanks) ideal = xml.to_xml(indent: 2) now = File.read(@path) return Differ.diff_by_line(ideal, now).to_s unless now == ideal '' end |
#ldiff(license) ⇒ Object
Return the difference for the license.
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/xcop.rb', line 50 def ldiff(license) xml = Nokogiri::XML(File.open(@path), &:noblanks) now = xml.xpath('/comment()')[0].to_s ideal = [ '<!--', *license.strip.split(/\n/).map(&:strip), '-->' ].join("\n") return Differ.diff_by_line(ideal, now).to_s unless now == ideal '' end |