Class: Licensee::LicenseFile

Inherits:
Object
  • Object
show all
Defined in:
lib/licensee/license_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(blob, options = {}) ⇒ LicenseFile



5
6
7
8
# File 'lib/licensee/license_file.rb', line 5

def initialize(blob, options={})
  @blob = blob
  @path = options[:path]
end

Instance Attribute Details

#blobObject (readonly)

Returns the value of attribute blob.



3
4
5
# File 'lib/licensee/license_file.rb', line 3

def blob
  @blob
end

#pathObject (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

#confidenceObject

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

#contentObject 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_normalizedObject

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(options={})
  options = options.merge(:reverse => true)
  blob.diff(match.body, options).to_s if match
end

#matchObject

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

#matcherObject

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