ruby_codex 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/ruby_codex.rb +14 -5
  2. metadata +6 -5
  3. checksums.yaml +0 -15
data/lib/ruby_codex.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  load 'data_node.rb'
2
+ require 'pp'
2
3
 
3
4
  class Codex
4
5
 
@@ -107,11 +108,18 @@ class Codex
107
108
  query = db.where(keys).first
108
109
  query_count = query.nil? ? 0 : query.count
109
110
  func = db.where(:type => keys[:type], :func => keys[:func]).sort(:count => -1).limit(1).first
110
- alt_count = func.nil? ? 0 : func.count
111
+ alt_text =
112
+ if func
113
+ alt_count = func.count
114
+ "and the most common alternative #{func.norm_code} has appeared #{alt_count.to_s} times."
115
+ else
116
+ alt_count = 0
117
+ "and we've seen no known alternative."
118
+ end
111
119
  { :keys => keys,
112
120
  :message =>
113
- "Function call #{keys[:norm_code]} has appeared #{query_count.to_s} times, and the most " +
114
- "common alternative #{func.norm_code} has appeared #{alt_count.to_s} times.",
121
+ "Function call #{keys[:norm_code]} has appeared #{query_count.to_s} times, " +
122
+ alt_text,
115
123
  :unlikely => Proc.new { |t=10| alt_count > t * (query_count + 1)}
116
124
  }
117
125
  }
@@ -178,11 +186,12 @@ class Codex
178
186
  types = query.ident_types.select { |k,v| ["str","int","float","array","hash"].include? k }
179
187
  types.default = 0
180
188
  best = types.select { |k,v| k != data[:ident_type] }.sort_by{ |k,v| v*-1 }.first
189
+ best_str = best ? "#{best[1].to_s} times as #{best[0].to_s}" : "never as anything else."
181
190
  { :keys => keys,
182
191
  :message =>
183
192
  "The identifier #{keys[:ident]} has appeared #{types[data[:ident_type]].to_s} " +
184
- "times as #{data[:ident_type].to_s} and #{best[1].to_s} times as #{best[0].to_s}",
185
- :unlikely => Proc.new { |t=5| best[1] > t * (types[keys[:ident_type]] + 1) }
193
+ "times as #{data[:ident_type].to_s} and #{best_str}",
194
+ :unlikely => Proc.new { |t=5| best ? best[1] > t * (types[keys[:ident_type]] + 1) : false }
186
195
  }
187
196
  else
188
197
  { :message => "Never Seen", :unlikely => Proc.new { false } }
metadata CHANGED
@@ -1,7 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_codex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Ethan Fast
@@ -22,26 +23,26 @@ files:
22
23
  homepage: http://rubygems.org/gems/ruby-codex
23
24
  licenses:
24
25
  - MIT
25
- metadata: {}
26
26
  post_install_message:
27
27
  rdoc_options: []
28
28
  require_paths:
29
29
  - lib
30
30
  required_ruby_version: !ruby/object:Gem::Requirement
31
+ none: false
31
32
  requirements:
32
33
  - - ! '>='
33
34
  - !ruby/object:Gem::Version
34
35
  version: '0'
35
36
  required_rubygems_version: !ruby/object:Gem::Requirement
37
+ none: false
36
38
  requirements:
37
39
  - - ! '>='
38
40
  - !ruby/object:Gem::Version
39
41
  version: '0'
40
42
  requirements: []
41
43
  rubyforge_project:
42
- rubygems_version: 2.0.5
44
+ rubygems_version: 1.8.25
43
45
  signing_key:
44
- specification_version: 4
46
+ specification_version: 3
45
47
  summary: Analyze ruby ASTs with Codex
46
48
  test_files: []
47
- has_rdoc:
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- YmVlZWZiZWU3MWNlNDMxMWIwYzFhMzVhZDczMWUxNzAzMGQxN2M2OA==
5
- data.tar.gz: !binary |-
6
- N2NhNGQzYmYwNzAzNTk1M2I3ZDkyZjM2YTU5OGJlNzZkMjcwYmYyYg==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- NGQ5NmI1ZTkwMjNiZDZlZjExZjUzMzBhYWJhNDJkZTYwZTE3MDIzODcxOTNh
10
- ZGMxNDhlNGZjOWZlNmU4NTdkNjIyZGVhM2I4MzFkNTk0MTU5ZTA5YjRhZjcy
11
- NTFmMmI2ZDNhZTU5MmE1YzlkNWU1NzE3YTMwMzMzODQ0YjlhY2Q=
12
- data.tar.gz: !binary |-
13
- MWU4Zjg1M2FlZDc2NzRhNmNkMjNjYTVhZjE3OTE3ODAxY2Y4ZWIwYjdiMDBi
14
- ODUzZjE5MmE4MzQ1OTVjYjRkMDViYzA2MjFhZTFiMDkxOWY1NmUxNzZjNjY0
15
- YTlhMTM3ZjdkZGQyYjNkZjNlYjhkNzgwODVmOTczNGZkYjFlZGU=