Class: Licensee::LicenseFile
- Inherits:
-
Object
- Object
- Licensee::LicenseFile
- Defined in:
- lib/licensee/license_file.rb
Instance Attribute Summary collapse
-
#blob ⇒ Object
readonly
Returns the value of attribute blob.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#confidence ⇒ Object
Returns the percent confident with the match.
-
#content ⇒ Object
(also: #to_s, #contents)
Raw file contents.
-
#content_normalized ⇒ Object
File content with all whitespace replaced with a single space.
-
#diff(options = {}) ⇒ Object
Comptutes a diff between known license and project license.
-
#initialize(blob, options = {}) ⇒ LicenseFile
constructor
A new instance of LicenseFile.
-
#match ⇒ Object
Returns an Licensee::License instance of the matches license.
-
#matcher ⇒ Object
Determines which matching strategy to use, returns an instane of that matcher.
- #similarity(other) ⇒ Object
Constructor Details
#initialize(blob, options = {}) ⇒ LicenseFile
5 6 7 8 |
# File 'lib/licensee/license_file.rb', line 5 def initialize(blob, ={}) @blob = blob @path = [:path] end |
Instance Attribute Details
#blob ⇒ Object (readonly)
Returns the value of attribute blob.
3 4 5 |
# File 'lib/licensee/license_file.rb', line 3 def blob @blob end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
3 4 5 |
# File 'lib/licensee/license_file.rb', line 3 def path @path end |
Instance Method Details
#confidence ⇒ Object
Returns the percent confident with the match
48 49 50 |
# File 'lib/licensee/license_file.rb', line 48 def confidence @condience ||= matcher.confidence if matcher end |
#content ⇒ Object Also known as: to_s, contents
Raw file contents
18 19 20 21 22 |
# File 'lib/licensee/license_file.rb', line 18 def content @contents ||= begin blob.content end end |
#content_normalized ⇒ Object
File content with all whitespace replaced with a single space
27 28 29 |
# File 'lib/licensee/license_file.rb', line 27 def content_normalized @content_normalized ||= content.downcase.gsub(/\s+/, " ").strip end |
#diff(options = {}) ⇒ Object
Comptutes a diff between known license and project license
32 33 34 35 |
# File 'lib/licensee/license_file.rb', line 32 def diff(={}) = .merge(:reverse => true) blob.diff(match.body, ).to_s if match end |
#match ⇒ Object
Returns an Licensee::License instance of the matches license
43 44 45 |
# File 'lib/licensee/license_file.rb', line 43 def match @match ||= matcher.match if matcher end |
#matcher ⇒ Object
Determines which matching strategy to use, returns an instane of that matcher
38 39 40 |
# File 'lib/licensee/license_file.rb', line 38 def matcher @matcher ||= Licensee.matchers.map { |m| m.new(self) }.find { |m| m.match } end |
#similarity(other) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/licensee/license_file.rb', line 10 def similarity(other) blob.hashsig(Rugged::Blob::HashSignature::WHITESPACE_SMART) other.hashsig ? blob.similarity(other.hashsig) : 0 rescue Rugged::InvalidError 0 end |