Class: Herb::DiffResult

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/herb/diff_result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(identical, operations) ⇒ DiffResult

: (bool, Array) -> void



11
12
13
14
15
# File 'lib/herb/diff_result.rb', line 11

def initialize(identical, operations)
  @identical = identical
  @operations = operations.freeze
  freeze
end

Instance Attribute Details

#operationsObject (readonly)

: Array



8
9
10
# File 'lib/herb/diff_result.rb', line 8

def operations
  @operations
end

Instance Method Details

#changed?Boolean

: () -> bool

Returns:

  • (Boolean)


36
37
38
# File 'lib/herb/diff_result.rb', line 36

def changed?
  !identical?
end

#each(&block) ⇒ Object

: () { (Herb::DiffOperation) -> void } -> void : () -> Enumerator[Herb::DiffOperation, void]



19
20
21
22
23
# File 'lib/herb/diff_result.rb', line 19

def each(&block)
  return operations.each unless block

  operations.each(&block)
end

#identical?Boolean

: () -> bool

Returns:

  • (Boolean)


26
27
28
# File 'lib/herb/diff_result.rb', line 26

def identical?
  @identical
end

#inspectObject

: () -> String



51
52
53
54
55
56
57
# File 'lib/herb/diff_result.rb', line 51

def inspect
  if identical?
    "#<#{self.class.name} identical>"
  else
    "#<#{self.class.name} #{operation_count} operation#{"s" unless operation_count == 1}>"
  end
end

#operation_countObject

: () -> Integer



31
32
33
# File 'lib/herb/diff_result.rb', line 31

def operation_count
  operations.size
end

#to_hashObject Also known as: to_h

: () -> Hash[Symbol, untyped]



41
42
43
44
45
46
# File 'lib/herb/diff_result.rb', line 41

def to_hash
  {
    identical: identical?,
    operations: operations.map(&:to_hash),
  }
end