Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: riffraff/parsely
base: 842caa6ab9
...
head fork: riffraff/parsely
compare: fc3e07dbfc
Checking mergeability… Don't worry, you can still create the pull request.
  • 4 commits
  • 8 files changed
  • 0 commit comments
  • 1 contributor
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
60 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,47 @@ 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
+ @running_value = 0
+ @result = proc { @running_value }
+ @result.single = true
+ end
+ def process(value)
+ @running_value += 1
+ @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
@@ -204,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
@@ -247,7 +299,11 @@ def load_rc
def main
if ARGV.empty?
- abort("usage #$0 <expr> <file file file| stdin >")
+ abort("usage #$0 [-l |<expr> <file file file| stdin >]")
+ elsif ARGV[0] == '-l'
+ puts " Available aggregate functions:"
+ puts Ops.keys.map {|k| "\t#{k}"}
+ exit
end
load_rc
expr = ARGV.shift
View
1  test/basic/021-topk/command
@@ -0,0 +1 @@
+parsely 'top(2, _1)' lines.txt
View
6 test/basic/021-topk/lines.txt
@@ -0,0 +1,6 @@
+4 4 4
+1 1 1
+2
+3 3
+5
+3
View
2  test/basic/021-topk/output
@@ -0,0 +1,2 @@
+5
+4
View
1  test/basic/022-topk/command
@@ -0,0 +1 @@
+parsely 'top(2, _1)' lines.txt
View
6 test/basic/022-topk/lines.txt
@@ -0,0 +1,6 @@
+4 4 4
+1 1 1
+2
+3 3
+5
+3
View
2  test/basic/022-topk/output
@@ -0,0 +1,2 @@
+5
+4

No commit comments for this range

Something went wrong with that request. Please try again.