synt 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 61e52388871ff043151ec66372c3ffc60f67be0a
4
- data.tar.gz: 9af48d4f1a541461e4ca6739ee44395be4f92669
3
+ metadata.gz: 07d8eb90258e1d9b95e1f14d9d93a0f742426c98
4
+ data.tar.gz: 48febfb847f4d9031c8b0335c8ffe408728bf8ca
5
5
  SHA512:
6
- metadata.gz: daec8bbc9b5c2007734e9b459dce71a6b5fb1a221d601d37fbbc1e25a599bd5858799a2494fc6dcf92a60952e1ade148cebff043f570fe15cb21505f8250739c
7
- data.tar.gz: 7a099290fe8ba60b402996c686a90f867c6901f41c7b873fb01dc58fca7c3ad439fc82e88263a7338858f3080b90c101a01bc3247da7f2c4bfbd84b06af78083
6
+ metadata.gz: d46ef30ae4c429863047b957d1eea15ff1e4c19cde044b93ad785a85d3818904d5df97531c48ac0e56675784fb98237d22a9db9c03c38fbe77badcd6c1714050
7
+ data.tar.gz: 3f1e5c9381a6d790d6f9da8f52929a1160a77f29f931e348a987cf8614dd27c4f3b12e29bb803466624e4a010b7a47dbf568bfdc500110f9d28584b321595ca4
@@ -8,12 +8,20 @@ define 'Synt'
8
8
  module Synt::Similar
9
9
  extend self
10
10
 
11
+ def determine string_or_file
12
+ if File.exists? string_or_file
13
+ IO.read string_or_file
14
+ else
15
+ string_or_file || ''
16
+ end
17
+ end
18
+
11
19
  def compare opts
12
20
  error 'no compare propery provided' unless opts[:compare]
13
21
  error 'no to propery provided' unless opts[:to]
14
22
 
15
- src = opts[:compare] || ''
16
- cmp = opts[:to] || ''
23
+ src = determine opts[:compare]
24
+ cmp = determine opts[:to]
17
25
  algorithm = algorithms[(opts[:algorithm] || 'jaccard').to_sym]
18
26
  n_start, n_end = ngram_range opts[:ngram]
19
27
  src_t = normalize_ripper_tokens Synt::Parser.parse(src)
@@ -1,3 +1,3 @@
1
1
  module Synt
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -13,6 +13,32 @@ describe Synt::Similar do
13
13
  let(:dissimilar_a_path) { 'spec/fixtures/compare-rb-dissimilar-a.rb' }
14
14
  let(:dissimilar_b_path) { 'spec/fixtures/compare-rb-dissimilar-b.rb' }
15
15
 
16
+ context 'cli' do
17
+ context 'comparing things' do
18
+ context 'that are Files' do
19
+ before do
20
+ allow(File).to receive(:exists?).and_return(true)
21
+ expect(IO).to receive(:read).and_return("42").twice
22
+ end
23
+
24
+ it 'read both files from the file system' do
25
+ subject.compare compare: "file/path.rb", to: "file/path2"
26
+ end
27
+ end
28
+
29
+ context 'that are Strings' do
30
+ before do
31
+ allow(File).to receive(:exists?).and_return(false)
32
+ expect(IO).to_not receive(:read)
33
+ end
34
+
35
+ it 'should not read any files' do
36
+ subject.compare compare: "file/path.rb", to: "file/path2"
37
+ end
38
+ end
39
+ end
40
+ end
41
+
16
42
  context 'duplicate code comparison' do
17
43
  let(:dupe) { file_to_s duplicate_path }
18
44
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: synt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brent Lintner