Skip to content

Commit

Permalink
support geo lookup and timediff, untested
Browse files Browse the repository at this point in the history
  • Loading branch information
riffraff committed Mar 13, 2012
1 parent 95d2cd3 commit 21373f1
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
1 change: 1 addition & 0 deletions TODO
Expand Up @@ -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
42 changes: 41 additions & 1 deletion lib/parsely.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 21373f1

Please sign in to comment.