Class: Uniword::Diff::Semantic::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/uniword/diff/semantic/result.rb

Overview

Aggregated semantic diff result. Counts by kind and modifier; full change list.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeResult

Returns a new instance of Result.



11
12
13
# File 'lib/uniword/diff/semantic/result.rb', line 11

def initialize
  @changes = []
end

Instance Attribute Details

#changesObject (readonly)

Returns the value of attribute changes.



9
10
11
# File 'lib/uniword/diff/semantic/result.rb', line 9

def changes
  @changes
end

Instance Method Details

#add(change) ⇒ void

This method returns an undefined value.

Parameters:



17
18
19
# File 'lib/uniword/diff/semantic/result.rb', line 17

def add(change)
  @changes << change
end

#by_kindHash{Symbol => Integer}

Count by kind (:added, :removed, :modified, :moved).

Returns:

  • (Hash{Symbol => Integer})


24
25
26
# File 'lib/uniword/diff/semantic/result.rb', line 24

def by_kind
  @changes.group_by(&:kind).transform_values(&:count)
end

#by_modifierHash{Symbol => Integer}

For modified changes, count by modifier (:text, :format, :structure).

Returns:

  • (Hash{Symbol => Integer})


32
33
34
35
# File 'lib/uniword/diff/semantic/result.rb', line 32

def by_modifier
  modified = @changes.select { |c| c.kind == :modified }
  modified.group_by(&:modifier).transform_values(&:count)
end

#countInteger

Total change count.

Returns:

  • (Integer)


40
41
42
# File 'lib/uniword/diff/semantic/result.rb', line 40

def count
  @changes.length
end

#empty?Boolean

True when no changes.

Returns:

  • (Boolean)


47
48
49
# File 'lib/uniword/diff/semantic/result.rb', line 47

def empty?
  @changes.empty?
end