Class: Hashira::Duplication::Fragment
- Inherits:
-
Object
- Object
- Hashira::Duplication::Fragment
- Defined in:
- lib/hashira/duplication/fragment.rb
Constant Summary collapse
- DIGEST_LENGTH =
12
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
Instance Method Summary collapse
- #digest ⇒ Object
- #finish ⇒ Object
-
#initialize(file, roots) ⇒ Fragment
constructor
A new instance of Fragment.
- #line ⇒ Object
- #location ⇒ Object
- #mass ⇒ Object
- #nodes ⇒ Object
- #overlaps?(other) ⇒ Boolean
- #overlaps_any?(others) ⇒ Boolean
- #range ⇒ Object
- #shape ⇒ Object
- #sort_key ⇒ Object
- #types ⇒ Object
Constructor Details
#initialize(file, roots) ⇒ Fragment
Returns a new instance of Fragment.
10 11 12 13 |
# File 'lib/hashira/duplication/fragment.rb', line 10 def initialize(file, roots) @file = file @roots = roots end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
15 16 17 |
# File 'lib/hashira/duplication/fragment.rb', line 15 def file @file end |
Instance Method Details
#digest ⇒ Object
19 |
# File 'lib/hashira/duplication/fragment.rb', line 19 def digest = Digest::SHA256.hexdigest(shape).slice(0, DIGEST_LENGTH) |
#finish ⇒ Object
27 |
# File 'lib/hashira/duplication/fragment.rb', line 27 def finish = @roots.last.location.end_line |
#line ⇒ Object
25 |
# File 'lib/hashira/duplication/fragment.rb', line 25 def line = @roots.first.location.start_line |
#location ⇒ Object
29 |
# File 'lib/hashira/duplication/fragment.rb', line 29 def location = "#{file}:#{line}" |
#mass ⇒ Object
23 |
# File 'lib/hashira/duplication/fragment.rb', line 23 def mass = types.size |
#nodes ⇒ Object
39 |
# File 'lib/hashira/duplication/fragment.rb', line 39 def nodes = @nodes ||= @roots.flat_map { Analysis::NodeWalk.collect(it) } |
#overlaps?(other) ⇒ Boolean
35 |
# File 'lib/hashira/duplication/fragment.rb', line 35 def overlaps?(other) = file == other.file && line <= other.finish && other.line <= finish |
#overlaps_any?(others) ⇒ Boolean
37 |
# File 'lib/hashira/duplication/fragment.rb', line 37 def overlaps_any?(others) = others.any? { overlaps?(it) } |
#range ⇒ Object
31 |
# File 'lib/hashira/duplication/fragment.rb', line 31 def range = "#{file}:#{line}-#{finish}" |
#shape ⇒ Object
21 |
# File 'lib/hashira/duplication/fragment.rb', line 21 def shape = types.join(",") |
#sort_key ⇒ Object
33 |
# File 'lib/hashira/duplication/fragment.rb', line 33 def sort_key = [file, line] |
#types ⇒ Object
17 |
# File 'lib/hashira/duplication/fragment.rb', line 17 def types = @types ||= nodes.map(&:type) |