lib/licensee/license_file.rb in licensee-2.0.0 vs lib/licensee/license_file.rb in licensee-3.0.0

- old
+ new

@@ -5,45 +5,41 @@ def initialize(blob) @blob = blob blob.hashsig(Rugged::Blob::HashSignature::WHITESPACE_SMART) end - def contents - @contents ||= blob.content + # Raw file contents + def content + @contents ||= begin + blob.content + end end - alias_method :to_s, :contents - alias_method :content, :contents + alias_method :to_s, :content + alias_method :contents, :content - def length - @length ||= blob.size + # File content with all whitespace replaced with a single space + def content_normalized + @content_normalized ||= content.downcase.gsub(/\s+/, " ").strip end - def matches - @matches ||= Licensee::Licenses.list.map { |l| [l, calculate_similarity(l)] } + # Comptutes a diff between known license and project license + def diff(options={}) + options = options.merge(:reverse => true) + blob.diff(match.body, options).to_s if match end - def match_info - @match_info ||= matches.max_by { |license, similarity| similarity } + # Determines which matching strategy to use, returns an instane of that matcher + def matcher + @matcher ||= Licensee.matchers.map { |m| m.new(self) }.find { |m| m.match } end + # Returns an Licensee::License instance of the matches license def match - match_info ? match_info[0] : nil + @match ||= matcher.match if matcher end + # Returns the percent confident with the match def confidence - match_info ? match_info[1] : nil - end - alias_method :similarity, :confidence - - def diff(options={}) - options = options.merge(:reverse => true) - blob.diff(match.body, options).to_s if match - end - - private - - # Pulled out for easier testing - def calculate_similarity(other) - blob.similarity(other.hashsig) + @condience ||= matcher.confidence if matcher end end end