Class: Hashira::Duplication::Fragment
- Inherits:
-
Object
- Object
- Hashira::Duplication::Fragment
- Defined in:
- lib/hashira/duplication/fragment.rb
Constant Summary collapse
- DIGEST_LENGTH =
12- SCHEMA =
%i[ class_node module_node statements_node arguments_node assoc_node array_node hash_node keyword_hash_node constant_read_node constant_path_node symbol_node string_node integer_node float_node true_node false_node nil_node ].freeze
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
- #range ⇒ Object
- #rank ⇒ Object
- #schema? ⇒ Boolean
- #shape ⇒ Object
- #touches?(others) ⇒ Boolean
- #types ⇒ Object
Constructor Details
#initialize(file, roots) ⇒ Fragment
Returns a new instance of Fragment.
15 16 17 18 |
# File 'lib/hashira/duplication/fragment.rb', line 15 def initialize(file, roots) @file = file @roots = roots end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
20 21 22 |
# File 'lib/hashira/duplication/fragment.rb', line 20 def file @file end |
Instance Method Details
#digest ⇒ Object
24 |
# File 'lib/hashira/duplication/fragment.rb', line 24 def digest = Digest::SHA256.hexdigest(shape).slice(0, DIGEST_LENGTH) |
#finish ⇒ Object
34 |
# File 'lib/hashira/duplication/fragment.rb', line 34 def finish = @roots.last.location.end_line |
#line ⇒ Object
32 |
# File 'lib/hashira/duplication/fragment.rb', line 32 def line = @roots.first.location.start_line |
#location ⇒ Object
36 |
# File 'lib/hashira/duplication/fragment.rb', line 36 def location = "#{file}:#{line}" |
#mass ⇒ Object
28 |
# File 'lib/hashira/duplication/fragment.rb', line 28 def mass = types.size |
#nodes ⇒ Object
46 |
# File 'lib/hashira/duplication/fragment.rb', line 46 def nodes = @_nodes ||= @roots.flat_map { Hashira::Analysis::NodeWalk.collect(it) } |
#overlaps?(other) ⇒ Boolean
42 |
# File 'lib/hashira/duplication/fragment.rb', line 42 def overlaps?(other) = file == other.file && line <= other.finish && other.line <= finish |
#range ⇒ Object
38 |
# File 'lib/hashira/duplication/fragment.rb', line 38 def range = "#{file}:#{line}-#{finish}" |
#rank ⇒ Object
40 |
# File 'lib/hashira/duplication/fragment.rb', line 40 def rank = [file, line] |
#schema? ⇒ Boolean
30 |
# File 'lib/hashira/duplication/fragment.rb', line 30 def schema? = nodes.all? { directive?(it) } |
#shape ⇒ Object
26 |
# File 'lib/hashira/duplication/fragment.rb', line 26 def shape = types.join(",") |
#touches?(others) ⇒ Boolean
44 |
# File 'lib/hashira/duplication/fragment.rb', line 44 def touches?(others) = others.any? { overlaps?(it) } |
#types ⇒ Object
22 |
# File 'lib/hashira/duplication/fragment.rb', line 22 def types = @_types ||= nodes.map(&:type) |