Sha256: db18af576f32e1046afd15a24181a24758efbdf32afaee5fb5aee0a0ffea6731

Contents?: true

Size: 1.16 KB

Versions: 15

Compression:

Stored size: 1.16 KB

Contents

class Licensee
  class LicenseFile
    attr_reader :blob

    def initialize(blob)
      @blob = blob
      blob.hashsig(Rugged::Blob::HashSignature::WHITESPACE_SMART)
    end

    # Raw file contents
    def content
      @contents ||= begin
        blob.content
      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

15 entries across 15 versions & 1 rubygems

Version Path
licensee-4.3.3 lib/licensee/license_file.rb
licensee-4.3.2 lib/licensee/license_file.rb
licensee-4.3.1 lib/licensee/license_file.rb
licensee-4.3.0 lib/licensee/license_file.rb
licensee-4.2.4 lib/licensee/license_file.rb
licensee-4.2.3 lib/licensee/license_file.rb
licensee-4.2.2 lib/licensee/license_file.rb
licensee-4.2.1 lib/licensee/license_file.rb
licensee-4.2.0 lib/licensee/license_file.rb
licensee-4.1.2 lib/licensee/license_file.rb
licensee-4.1.1 lib/licensee/license_file.rb
licensee-4.1.0 lib/licensee/license_file.rb
licensee-4.0.1 lib/licensee/license_file.rb
licensee-4.0.0 lib/licensee/license_file.rb
licensee-3.0.0 lib/licensee/license_file.rb