Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

support geo lookup and timediff, untested

  • Loading branch information...
commit 21373f12f5f3275b36f2cf7007d916e1a51aec8c 1 parent 95d2cd3
@riffraff authored
Showing with 42 additions and 1 deletion.
  1. +1 −0  TODO
  2. +41 −1 lib/parsely.rb
View
1  TODO
@@ -22,3 +22,4 @@ summaryse is a cool extension from which to steal stuff. Maybe provide basic fun
- top k
selext top/max N or N% ditto for minus
select outliers
+parsely '_1.each_cons(3).to_a if rand(400)==1' /usr/share/dict/words |pbcopy #make PerlVar enumerable
View
42 lib/parsely.rb
@@ -39,7 +39,18 @@ def + other
PerlVar.new((to_s + other).to_s)
end
end
+ if ENV['GEOIP_CITY_DATA'] and File.exists?(ENV['GEOIP_CITY_DATA'])
+ require 'geoip'
+ geoip = GeoIP.new(ENV['GEOIP_CITY_DATA'])
+ GeoIP::City.members.each do |m|
+ define_method m do
+ geoip.city(self)[m]
+ end
+ end
+ end
end
+
+
PerlNil = PerlVar.new ''
attr :line
attr :vals
@@ -90,6 +101,22 @@ def to_s
end
end
Ops = {
+ :timediff => cmd do
+ def initialize value
+ require 'date'
+ @running_value = nil
+ end
+ def process(value)
+ new_value = DateTime.parse(value).to_time
+ if @running_value.nil?
+ @result = new_value.to_s
+ else
+ @result = ">\t+" + (new_value - @running_value).to_s
+ end
+ @running_value = new_value
+ @result
+ end
+ end,
:count => cmd do
def initialize value
super
@@ -102,6 +129,19 @@ def process(value)
@result
end
end,
+ :top => cmd do
+ def initialize value
+ super
+ @running_values = []
+ @result = proc { @running_value.sort.last(@k) }
+ @result.single = true
+ end
+ def process(k, value)
+ @k ||= k
+ @running_values << value
+ @result
+ end
+ end,
:min => cmd do
def initialize value
super
@@ -216,7 +256,7 @@ def process(value)
obj = nil
define_method k do |values|
obj ||= v.new(nil)
- obj.process(values)
+ obj.process(*values)
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.