Sha256: fb78f99360e8a08ee288d2b5983c8cbe186e9a05dcedb426a9fb51e3a4c0cc9f

Contents?: true

Size: 1.36 KB

Versions: 4

Compression:

Stored size: 1.36 KB

Contents

class Licensee
  class LicenseFile
    attr_reader :blob, :path

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

    def similarity(other)
      blob.hashsig(Rugged::Blob::HashSignature::WHITESPACE_SMART)
      other.hashsig ? blob.similarity(other.hashsig) : 0
    rescue Rugged::InvalidError
      0
    end

    # Raw file contents
    def content
      @contents ||= begin
        blob.content.force_encoding("UTF-8")
      end
    end
    alias_method :to_s, :content
    alias_method :contents, :content

    # File content with all whitespace replaced with a single space
    def content_normalized
      @content_normalized ||= content.downcase.gsub(/\s+/, " ").strip
    end

    # 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

    # 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 ||= matcher.match if matcher
    end

    # Returns the percent confident with the match
    def confidence
      @condience ||= matcher.confidence if matcher
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
licensee-4.9.0 lib/licensee/license_file.rb
licensee-4.8.0 lib/licensee/license_file.rb
licensee-4.7.4 lib/licensee/license_file.rb
licensee-4.7.3 lib/licensee/license_file.rb