Module: Ruby::Merge::ScaffoldChunkSupport
- Defined in:
- lib/ruby/merge/scaffold_chunk_support.rb
Defined Under Namespace
Classes: ChunkSpec
Constant Summary collapse
- BUNDLER_GEM_TASKS_SPEC =
ChunkSpec.new( anchor_type: :require_call, anchor_value: 'bundler/gem_tasks', satellite_patterns: [], jaccard_threshold: 0.35, max_lookahead: 0, max_lookbehind: 0 )
- RSPEC_SPEC =
ChunkSpec.new( anchor_type: :require_call, anchor_value: 'rspec/core/rake_task', satellite_patterns: ['RSpec::Core::RakeTask.new'], jaccard_threshold: 0.35, max_lookahead: 5, max_lookbehind: 2 )
- RUBOCOP_SPEC =
ChunkSpec.new( anchor_type: :require_call, anchor_value: 'rubocop/rake_task', satellite_patterns: ['RuboCop::RakeTask.new'], jaccard_threshold: 0.35, max_lookahead: 5, max_lookbehind: 2 )
- DEFAULT_TASK_SPEC =
ChunkSpec.new( anchor_type: :task_call, anchor_value: 'default', satellite_patterns: [], jaccard_threshold: 0.35, max_lookahead: 0, max_lookbehind: 0 )
- ALL_SPECS =
[BUNDLER_GEM_TASKS_SPEC, RSPEC_SPEC, RUBOCOP_SPEC, DEFAULT_TASK_SPEC].freeze
Class Method Summary collapse
- .jaccard(a_set, b_set) ⇒ Object
- .jaccard_tokens(text) ⇒ Object
- .task_anchor_match?(source, anchor_value, threshold) ⇒ Boolean
Class Method Details
.jaccard(a_set, b_set) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/ruby/merge/scaffold_chunk_support.rb', line 60 def jaccard(a_set, b_set) union = a_set | b_set return 0.0 if union.empty? (a_set & b_set).size.to_f / union.size end |
.jaccard_tokens(text) ⇒ Object
56 57 58 |
# File 'lib/ruby/merge/scaffold_chunk_support.rb', line 56 def jaccard_tokens(text) text.scan(/[A-Za-z0-9_]+/).to_set end |
.task_anchor_match?(source, anchor_value, threshold) ⇒ Boolean
67 68 69 70 71 |
# File 'lib/ruby/merge/scaffold_chunk_support.rb', line 67 def task_anchor_match?(source, anchor_value, threshold) node_tokens = jaccard_tokens(source.to_s) pattern_tokens = jaccard_tokens("task #{anchor_value}") jaccard(pattern_tokens, node_tokens) >= threshold end |