ruby_codex 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/ruby_codex.rb +18 -4
  2. metadata +1 -1
@@ -95,6 +95,11 @@ class Codex
95
95
  key.merge({
96
96
  :func => Proc.new { |x| func_name.call(x) },
97
97
  :sig => Proc.new { |x| x.children.drop(2).map { |y| type.call(y) } },
98
+ :norm_code => Proc.new do |x|
99
+ name = func_name.call(x)
100
+ sig = x.children.drop(2).map { |y| type.call(y) }.join(",")
101
+ "#{name}(#{sig})"
102
+ end
98
103
  }),
99
104
  data_core.merge({
100
105
  :info => Proc.new { |x| info.call(without_caller(x)) },
@@ -102,6 +107,8 @@ class Codex
102
107
  }),
103
108
  combine,
104
109
  Proc.new do |db,keys,values|
110
+ primatives = ["str","int","float","array","hash"]
111
+ all_prim = keys[:sig].all? { |x| primatives.include?(x) }
105
112
  query = db.where( :type => keys[:type], :func => keys[:func], :sig => keys[:sig]).first
106
113
  query_count = query.nil? ? 0 : query.count
107
114
  func = db.where(:type => keys[:type], :func => keys[:func], :sig => {:$ne => keys[:sig]}).sort(:count => -1).limit(1).first
@@ -118,7 +125,7 @@ class Codex
118
125
  "Function call #{keys[:func]}:#{keys[:sig].join(",")} has appeared #{query_count.to_s} times, " +
119
126
  alt_text,
120
127
  :unlikely => Proc.new do |ac=5,t=1024|
121
- query_count == 0 && alt_count >= ac || alt_count >= t * (query_count + 1)
128
+ all_prim && query_count == 0 && alt_count >= ac || alt_count >= t * (query_count + 1)
122
129
  end
123
130
  }
124
131
  end
@@ -131,13 +138,18 @@ class Codex
131
138
  :type => Proc.new { "func_chain" },
132
139
  :f1 => Proc.new { |x| func_name.call(x) },
133
140
  :f2 => Proc.new { |x| func_name.call(x.children.first) },
141
+ :norm_code => Proc.new do |x|
142
+ f1 = func_name.call(x)
143
+ f2 = func_name.call(x.children.first)
144
+ "#{f1}.#{f2}"
145
+ end
134
146
  }),
135
147
  data_core,
136
148
  combine,
137
149
  Proc.new do |db,keys,data|
138
150
  query = db.where(keys).first
139
151
  query_count = query.nil? ? 0 : query.count
140
- fs = [:f1,:f2].map { |f| db.where(:type => "send", :func => keys[f]).size }
152
+ fs = [:f1,:f2].map { |f| db.where(:type => "send", :func => keys[f]).sum(:count) }
141
153
  { :keys => keys,
142
154
  :message =>
143
155
  "Function #{keys[:f1]} has appeared #{fs[0].to_s} times " +
@@ -169,6 +181,7 @@ class Codex
169
181
  key.merge({
170
182
  :type => Proc.new { "ident" },
171
183
  :ident => Proc.new { |x| x.children.first.to_s },
184
+ :norm_code => Proc.new { |x| x.children.first.to_s + " ="}
172
185
  }),
173
186
  data_core.merge({
174
187
  :ident_type => Proc.new { |x| type.call(x.children[1]) rescue nil }
@@ -177,9 +190,10 @@ class Codex
177
190
  :ident_types => Proc.new { |v| v.group_by { |y| y[:ident_type] }.map_hash { |x| x.size } }
178
191
  }),
179
192
  Proc.new { |db, keys, data|
193
+ #pp keys
180
194
  primatives = ["str","int","float","array","hash"]
181
195
  query = db.where(keys).first
182
- if query && primatives.include?(keys[:ident_type])
196
+ if query && primatives.include?(data[:ident_type])
183
197
  types = query.ident_types.select { |k,v| primatives.include? k }
184
198
  types.default = 0
185
199
  best = types.select { |k,v| k != data[:ident_type] }.sort_by{ |k,v| v*-1 }.first
@@ -190,7 +204,7 @@ class Codex
190
204
  "times as #{data[:ident_type].to_s} and #{best_str}",
191
205
  :unlikely => Proc.new do |ac=5,t=8|
192
206
  if best
193
- types[keys[:ident_type]] == 0 && best[1] >= ac || best[1] >= t * (types[keys[:ident_type]] + 1)
207
+ (types[keys[:ident_type]] == 0 && best[1] >= ac) || (best[1] >= t * (types[keys[:ident_type]] + 1))
194
208
  else
195
209
  false
196
210
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_codex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: