Class: Reivt::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/reivt/document.rb

Overview

Blueprint for Document objects

Author:

  • brwnrclse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(blob, content_type, doc_name, has_diff = false) ⇒ Document

Returns a new instance of Document.



25
26
27
28
29
30
# File 'lib/reivt/document.rb', line 25

def initialize(blob, content_type, doc_name, has_diff = false)
  @blob = blob
  @content_type = content_type
  @has_diff = has_diff
  @doc_name = doc_name
end

Instance Attribute Details

#blobString

Returns The contents of the file.

Returns:

  • (String)

    The contents of the file



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/reivt/document.rb', line 22

class Document
  attr_accessor(:blob, :content_type, :doc_name, :name, :has_diff)

  def initialize(blob, content_type, doc_name, has_diff = false)
    @blob = blob
    @content_type = content_type
    @has_diff = has_diff
    @doc_name = doc_name
  end

  # Allows Documents objects to be compared using .eql? using their contents
  #       and file name.
  #
  # @param other [Rev::Document] The Document to compare to
  #
  # @return [Boolean] True if equal
  #                False if not equa
  #
  def eql?(other)
    self == other
  end

  # Allows Documents objects to be compared using hashes created from a
  #       logical and (&) between the files contents and name.
  #
  # @param other [Rev::Document] The Document to compare to
  #
  # @return [Fixnum] The & between file content and name
  #
  def hash
    @blob.hash & @doc_name.hash
  end

  # Allows Documents objects to be compared using == using their contents
  #       and file name.
  #
  # @param other [Rev::Document] The Document to compare to
  #
  # @return [Boolean] True if equal
  #                   False if not equa
  #
  def ==(other)
    @blob == other.blob && @doc_name == other.doc_name
  end
end

#content_typeString

Returns The type of content within the file.

Returns:

  • (String)

    The type of content within the file



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/reivt/document.rb', line 22

class Document
  attr_accessor(:blob, :content_type, :doc_name, :name, :has_diff)

  def initialize(blob, content_type, doc_name, has_diff = false)
    @blob = blob
    @content_type = content_type
    @has_diff = has_diff
    @doc_name = doc_name
  end

  # Allows Documents objects to be compared using .eql? using their contents
  #       and file name.
  #
  # @param other [Rev::Document] The Document to compare to
  #
  # @return [Boolean] True if equal
  #                False if not equa
  #
  def eql?(other)
    self == other
  end

  # Allows Documents objects to be compared using hashes created from a
  #       logical and (&) between the files contents and name.
  #
  # @param other [Rev::Document] The Document to compare to
  #
  # @return [Fixnum] The & between file content and name
  #
  def hash
    @blob.hash & @doc_name.hash
  end

  # Allows Documents objects to be compared using == using their contents
  #       and file name.
  #
  # @param other [Rev::Document] The Document to compare to
  #
  # @return [Boolean] True if equal
  #                   False if not equa
  #
  def ==(other)
    @blob == other.blob && @doc_name == other.doc_name
  end
end

#doc_nameArray<DocumentClass>

Returns The name of the file.

Returns:

  • (Array<DocumentClass>)

    The name of the file



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/reivt/document.rb', line 22

class Document
  attr_accessor(:blob, :content_type, :doc_name, :name, :has_diff)

  def initialize(blob, content_type, doc_name, has_diff = false)
    @blob = blob
    @content_type = content_type
    @has_diff = has_diff
    @doc_name = doc_name
  end

  # Allows Documents objects to be compared using .eql? using their contents
  #       and file name.
  #
  # @param other [Rev::Document] The Document to compare to
  #
  # @return [Boolean] True if equal
  #                False if not equa
  #
  def eql?(other)
    self == other
  end

  # Allows Documents objects to be compared using hashes created from a
  #       logical and (&) between the files contents and name.
  #
  # @param other [Rev::Document] The Document to compare to
  #
  # @return [Fixnum] The & between file content and name
  #
  def hash
    @blob.hash & @doc_name.hash
  end

  # Allows Documents objects to be compared using == using their contents
  #       and file name.
  #
  # @param other [Rev::Document] The Document to compare to
  #
  # @return [Boolean] True if equal
  #                   False if not equa
  #
  def ==(other)
    @blob == other.blob && @doc_name == other.doc_name
  end
end

#has_diffBoolean

Returns Whether or not the file will have a diff.

Returns:

  • (Boolean)

    Whether or not the file will have a diff



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/reivt/document.rb', line 22

class Document
  attr_accessor(:blob, :content_type, :doc_name, :name, :has_diff)

  def initialize(blob, content_type, doc_name, has_diff = false)
    @blob = blob
    @content_type = content_type
    @has_diff = has_diff
    @doc_name = doc_name
  end

  # Allows Documents objects to be compared using .eql? using their contents
  #       and file name.
  #
  # @param other [Rev::Document] The Document to compare to
  #
  # @return [Boolean] True if equal
  #                False if not equa
  #
  def eql?(other)
    self == other
  end

  # Allows Documents objects to be compared using hashes created from a
  #       logical and (&) between the files contents and name.
  #
  # @param other [Rev::Document] The Document to compare to
  #
  # @return [Fixnum] The & between file content and name
  #
  def hash
    @blob.hash & @doc_name.hash
  end

  # Allows Documents objects to be compared using == using their contents
  #       and file name.
  #
  # @param other [Rev::Document] The Document to compare to
  #
  # @return [Boolean] True if equal
  #                   False if not equa
  #
  def ==(other)
    @blob == other.blob && @doc_name == other.doc_name
  end
end

#nameObject

Returns the value of attribute name.



23
24
25
# File 'lib/reivt/document.rb', line 23

def name
  @name
end

Instance Method Details

#==(other) ⇒ Boolean

Allows Documents objects to be compared using == using their contents

and file name.

Parameters:

  • other (Rev::Document)

    The Document to compare to

Returns:

  • (Boolean)

    True if equal False if not equa



63
64
65
# File 'lib/reivt/document.rb', line 63

def ==(other)
  @blob == other.blob && @doc_name == other.doc_name
end

#eql?(other) ⇒ Boolean

Allows Documents objects to be compared using .eql? using their contents

and file name.

Parameters:

  • other (Rev::Document)

    The Document to compare to

Returns:

  • (Boolean)

    True if equal False if not equa



40
41
42
# File 'lib/reivt/document.rb', line 40

def eql?(other)
  self == other
end

#hashFixnum

Allows Documents objects to be compared using hashes created from a

logical and (&) between the files contents and name.

Parameters:

  • other (Rev::Document)

    The Document to compare to

Returns:

  • (Fixnum)

    The & between file content and name



51
52
53
# File 'lib/reivt/document.rb', line 51

def hash
  @blob.hash & @doc_name.hash
end