Class: CoconductorCLI
- Inherits:
-
Thor
- Object
- Thor
- CoconductorCLI
- Defined in:
- lib/coconductor/commands/diff.rb,
lib/coconductor/commands/detect.rb,
lib/coconductor/commands/version.rb
Instance Method Summary collapse
Instance Method Details
#detect(_path = nil) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/coconductor/commands/detect.rb', line 9 def detect(_path = nil) Coconductor.confidence_threshold = [:confidence] rows = [] rows << if code_of_conduct ['Code of conduct:', code_of_conduct.name] else ['Code of conduct:', set_color('None', :red)] end unless code_of_conduct.nil? %i[key family version language].each do |method| value = code_of_conduct.public_send(method) rows << [humanize(method, :method), humanize(value, method)] if value end end unless code_of_conduct_file.nil? %i[relative_path confidence matcher content_hash].each do |method| value = code_of_conduct_file.public_send(method) rows << [humanize(method, :method), humanize(value, method)] if value end end print_table rows return unless code_of_conduct_file && ([:code_of_conduct] || [:diff]) expected_code_of_conduct = [:code_of_conduct] || closest_code_of_conduct return unless expected_code_of_conduct invoke(:diff, nil, code_of_conduct: expected_code_of_conduct, code_of_conduct_to_diff: code_of_conduct_file) end |
#diff(_path = nil) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/coconductor/commands/diff.rb', line 9 def diff(_path = nil) say "Comparing to #{expected_code_of_conduct.name}:" rows = [] left = expected_code_of_conduct.content_normalized(wrap: 80) right = code_of_conduct_to_diff.content_normalized(wrap: 80) similarity = expected_code_of_conduct.similarity(code_of_conduct_to_diff) similarity = Licensee::ContentHelper.format_percent(similarity) rows << ['Input Length:', code_of_conduct_to_diff.length] rows << ['License length:', expected_code_of_conduct.length] rows << ['Similarity:', similarity] print_table rows if left == right say 'Exact match!', :green exit end Dir.mktmpdir do |dir| path = File. 'CODE_OF_CONDUCT', dir Dir.chdir(dir) do `git init` File.write(path, left) `git add CODE_OF_CONDUCT` `git commit -m 'left'` File.write(path, right) say `git diff --word-diff` end end end |
#version ⇒ Object
5 6 7 |
# File 'lib/coconductor/commands/version.rb', line 5 def version say Coconductor::VERSION end |