File: blob.rb

package info (click to toggle)
ruby-rugged 1.9.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,752 kB
  • sloc: ansic: 8,722; ruby: 7,473; sh: 99; makefile: 5
file content (33 lines) | stat: -rw-r--r-- 786 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Copyright (C) the Rugged contributors.  All rights reserved.
#
# This file is part of Rugged, distributed under the MIT license.
# For full terms see the included LICENSE file.

module Rugged
  class Blob
    class HashSignature
      WHITESPACE_DEFAULT  = 0
      WHITESPACE_IGNORE   = 1
      WHITESPACE_SMART    = 2
    end

    def hashsig(options = 0)
      @hashsig ||= HashSignature.new(self, options)
    end

    def similarity(other)
      other_sig = case other
      when HashSignature
        other
      when String
        HashSignature.new(other)
      when Blob
        other.hashsig
      else
        raise TypeError, "Expected a Rugged::Blob, String or Rugged::Blob::HashSignature"
      end

      HashSignature.compare(self.hashsig, other_sig)
    end
  end
end