Class: Hashira::Duplication::Delta
- Inherits:
-
Object
- Object
- Hashira::Duplication::Delta
- Defined in:
- lib/hashira/duplication/delta.rb
Constant Summary collapse
- ADVICE =
{ identical: "byte-for-byte identical — extract a shared method and call it from each site.", literal: "differs only in literal values — extract a method, pass them as arguments.", message: "differs only in the receiver or message — extract a method taking the receiver.", constant: "differs only in a constant — extract a method and parameterize it.", structure: "the control flow differs — extract the common core, but verify by hand (lower confidence).", mixed: "extract the shared shape and pass what differs as parameters." }.freeze
Instance Method Summary collapse
-
#initialize(cluster) ⇒ Delta
constructor
A new instance of Delta.
- #kind ⇒ Object
- #summary ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(cluster) ⇒ Delta
Returns a new instance of Delta.
15 16 17 |
# File 'lib/hashira/duplication/delta.rb', line 15 def initialize(cluster) @cluster = cluster end |
Instance Method Details
#kind ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/hashira/duplication/delta.rb', line 21 def kind = kinds return :identical if .empty? return :structure if .include?(:structure) .size == 1 ? .first : :mixed end |
#summary ⇒ Object
19 |
# File 'lib/hashira/duplication/delta.rb', line 19 def summary = ADVICE.fetch(kind) |
#to_h ⇒ Object
29 30 31 32 |
# File 'lib/hashira/duplication/delta.rb', line 29 def to_h { mass: @cluster.mass, sites: @cluster.size, kind:, locations: @cluster.sites.sort_by(&:sort_key).map(&:range) } end |