parsely 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/README.mkd +3 -0
- data/TODO +5 -0
- data/lib/parsely.rb +61 -5
- data/test/basic/021-topk/command +1 -0
- data/test/basic/021-topk/lines.txt +6 -0
- data/test/basic/021-topk/output +2 -0
- data/test/basic/022-topk/command +1 -0
- data/test/basic/022-topk/lines.txt +6 -0
- data/test/basic/022-topk/output +2 -0
- metadata +23 -11
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZWE3YTNkZDNkZDJkYmYxYjljOTdhZjk4N2E4OTI3MDU1NjAzYjYxMw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZjQxODlhODg4YzdjMmU5ZWEzNmUzYjU0YzBlZWUwOGU2Y2M1Mjg1YQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YTE0ZTU3ZDNjYjc1ZGI1Y2VkNjhhNDkzMDNmMjJhOGVkMjRkNzVmOTI3ODRi
|
10
|
+
ZDM5NjRlYTBlZWFmM2NjZTJmODBiMTlmYTU4MjJkODhlNmI5ZDFiZTY4M2I0
|
11
|
+
OWNlYjZiMjExNGViYjQzYzZmM2Y3NjA5NDZiNTZmNzQyZWIwNmM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MjBmZmQzM2Y1MmNkNTg1NTBiYzAyYTZkMTIxZjZiNTVkYTBmOTQ3N2Y5NDJj
|
14
|
+
MDliMWE4NDQwYTAyNDY3ZGI1ZGE5NzJhNzBlMWNjZTQ4MzdmOGE2Y2YwMzBh
|
15
|
+
NjJmNWUxMjUzMGMxNmE5NTJmMDc2ZTlmNzkxZTkzMjliMjMzOWQ=
|
data/README.mkd
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
|
1
2
|
# DISCLAIMER
|
2
3
|
|
3
4
|
Do Not Use This.
|
@@ -20,6 +21,7 @@ It does nothing you can't do with a few pipes, sed, awk, grep, ack, perl,
|
|
20
21
|
ruby, sort, uniq, bc, ministats and comm.
|
21
22
|
|
22
23
|
It is useful for me because
|
24
|
+
|
23
25
|
* I am very bad at remembering options for command line tools, and get
|
24
26
|
confused when BSD and GNU tools don't match
|
25
27
|
* I always get confused escaping stuff in the shell
|
@@ -43,3 +45,4 @@ something in parsely, but I don't think you should use this tool, at
|
|
43
45
|
least for the next couple of years.
|
44
46
|
Or you can write me an email at rff.rff+parsely@gmail.com if you want.
|
45
47
|
|
48
|
+
[](http://travis-ci.org/riffraff/parsely)
|
data/TODO
CHANGED
@@ -22,3 +22,8 @@ summaryse is a cool extension from which to steal stuff. Maybe provide basic fun
|
|
22
22
|
- top k
|
23
23
|
selext top/max N or N% ditto for minus
|
24
24
|
select outliers
|
25
|
+
parsely '_1.each_cons(3).to_a if rand(400)==1' /usr/share/dict/words |pbcopy #make PerlVar enumerable
|
26
|
+
document GEOIP, and everything else
|
27
|
+
list fields, eg pr -l => _1 _2(_1 _2) _3 _4
|
28
|
+
on -k also perform file guessing (e.g. headers for csv, common log format)
|
29
|
+
diffcount
|
data/lib/parsely.rb
CHANGED
@@ -39,7 +39,18 @@ class PseudoBinding
|
|
39
39
|
PerlVar.new((to_s + other).to_s)
|
40
40
|
end
|
41
41
|
end
|
42
|
+
if ENV['GEOIP_CITY_DATA'] and File.exists?(ENV['GEOIP_CITY_DATA'])
|
43
|
+
require 'geoip'
|
44
|
+
geoip = GeoIP.new(ENV['GEOIP_CITY_DATA'])
|
45
|
+
GeoIP::City.members.each do |m|
|
46
|
+
define_method m do
|
47
|
+
geoip.city(self)[m]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
42
51
|
end
|
52
|
+
|
53
|
+
|
43
54
|
PerlNil = PerlVar.new ''
|
44
55
|
attr :line
|
45
56
|
attr :vals
|
@@ -75,7 +86,7 @@ class Proc
|
|
75
86
|
end
|
76
87
|
end
|
77
88
|
class Parsely
|
78
|
-
VERSION = "0.1.
|
89
|
+
VERSION = "0.1.5"
|
79
90
|
def self.cmd(&block)
|
80
91
|
Struct.new :value, &block
|
81
92
|
end
|
@@ -83,13 +94,54 @@ class Parsely
|
|
83
94
|
|
84
95
|
Expression = Struct.new :code, :items do
|
85
96
|
def process(pb)
|
86
|
-
result = pb.instance_eval(code)
|
97
|
+
result = pb.instance_eval(code, __FILE__, __LINE__+1)
|
87
98
|
end
|
88
99
|
def to_s
|
89
100
|
code.to_s
|
90
101
|
end
|
91
102
|
end
|
92
103
|
Ops = {
|
104
|
+
:timediff => cmd do
|
105
|
+
def initialize value
|
106
|
+
require 'date'
|
107
|
+
@running_value = nil
|
108
|
+
end
|
109
|
+
def process(value)
|
110
|
+
new_value = DateTime.parse(value).to_time
|
111
|
+
if @running_value.nil?
|
112
|
+
@result = new_value.to_s
|
113
|
+
else
|
114
|
+
@result = ">\t+" + (new_value - @running_value).to_s
|
115
|
+
end
|
116
|
+
@running_value = new_value
|
117
|
+
@result
|
118
|
+
end
|
119
|
+
end,
|
120
|
+
:count => cmd do
|
121
|
+
def initialize value
|
122
|
+
super
|
123
|
+
@running_value = 0
|
124
|
+
@result = proc { @running_value }
|
125
|
+
@result.single = true
|
126
|
+
end
|
127
|
+
def process(value)
|
128
|
+
@running_value += 1
|
129
|
+
@result
|
130
|
+
end
|
131
|
+
end,
|
132
|
+
:top => cmd do
|
133
|
+
def initialize values
|
134
|
+
super
|
135
|
+
@running_values = []
|
136
|
+
@result = proc { @running_values.sort {|a,b| b <=> a}.first(@k).join("\n") }
|
137
|
+
@result.single = true
|
138
|
+
end
|
139
|
+
def process(k, value)
|
140
|
+
@k ||= k
|
141
|
+
@running_values << value
|
142
|
+
@result
|
143
|
+
end
|
144
|
+
end,
|
93
145
|
:min => cmd do
|
94
146
|
def initialize value
|
95
147
|
super
|
@@ -202,9 +254,9 @@ class Parsely
|
|
202
254
|
Ops.each do |k,v|
|
203
255
|
#instantiating the object is expensive and we are not using 99% of them
|
204
256
|
obj = nil
|
205
|
-
define_method k do
|
257
|
+
define_method k do |*values|
|
206
258
|
obj ||= v.new(nil)
|
207
|
-
obj.process(values)
|
259
|
+
obj.process(*values)
|
208
260
|
end
|
209
261
|
end
|
210
262
|
end
|
@@ -247,7 +299,11 @@ class Parsely
|
|
247
299
|
|
248
300
|
def main
|
249
301
|
if ARGV.empty?
|
250
|
-
abort("usage #$0
|
302
|
+
abort("usage #$0 [-l |<expr> <file file file| stdin >]")
|
303
|
+
elsif ARGV[0] == '-l'
|
304
|
+
puts " Available aggregate functions:"
|
305
|
+
puts Ops.keys.map {|k| "\t#{k}"}
|
306
|
+
exit
|
251
307
|
end
|
252
308
|
load_rc
|
253
309
|
expr = ARGV.shift
|
@@ -0,0 +1 @@
|
|
1
|
+
parsely 'top(2, _1)' lines.txt
|
@@ -0,0 +1 @@
|
|
1
|
+
parsely 'top(2, _1)' lines.txt
|
metadata
CHANGED
@@ -1,27 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parsely
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.5
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Gabriele Renzi
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2013-12-17 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rake
|
16
|
-
requirement:
|
17
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
17
|
- - ! '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
25
27
|
description: ! "parsely is a simple tool for managing text files.\n DO
|
26
28
|
NOT USE IT.\n Mostly to replace a lot of awk/sed/ruby/perl one-off
|
27
29
|
scripts.\n This is an internal release, guaranteed to break
|
@@ -102,30 +104,35 @@ files:
|
|
102
104
|
- test/basic/019-increment-lineno-and-values/command
|
103
105
|
- test/basic/019-increment-lineno-and-values/lines.txt
|
104
106
|
- test/basic/019-increment-lineno-and-values/output
|
107
|
+
- test/basic/021-topk/command
|
108
|
+
- test/basic/021-topk/lines.txt
|
109
|
+
- test/basic/021-topk/output
|
110
|
+
- test/basic/022-topk/command
|
111
|
+
- test/basic/022-topk/lines.txt
|
112
|
+
- test/basic/022-topk/output
|
105
113
|
- test/cli-runner.rb
|
106
114
|
homepage: http://github.com/riffraff/parsely
|
107
115
|
licenses: []
|
116
|
+
metadata: {}
|
108
117
|
post_install_message:
|
109
118
|
rdoc_options: []
|
110
119
|
require_paths:
|
111
120
|
- lib
|
112
121
|
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
-
none: false
|
114
122
|
requirements:
|
115
123
|
- - ! '>='
|
116
124
|
- !ruby/object:Gem::Version
|
117
125
|
version: 1.9.2
|
118
126
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
-
none: false
|
120
127
|
requirements:
|
121
128
|
- - ! '>='
|
122
129
|
- !ruby/object:Gem::Version
|
123
130
|
version: '0'
|
124
131
|
requirements: []
|
125
132
|
rubyforge_project:
|
126
|
-
rubygems_version: 1.
|
133
|
+
rubygems_version: 2.1.11
|
127
134
|
signing_key:
|
128
|
-
specification_version:
|
135
|
+
specification_version: 4
|
129
136
|
summary: a simple tool for text file wrangling
|
130
137
|
test_files:
|
131
138
|
- test/basic/001/command
|
@@ -187,5 +194,10 @@ test_files:
|
|
187
194
|
- test/basic/019-increment-lineno-and-values/command
|
188
195
|
- test/basic/019-increment-lineno-and-values/lines.txt
|
189
196
|
- test/basic/019-increment-lineno-and-values/output
|
197
|
+
- test/basic/021-topk/command
|
198
|
+
- test/basic/021-topk/lines.txt
|
199
|
+
- test/basic/021-topk/output
|
200
|
+
- test/basic/022-topk/command
|
201
|
+
- test/basic/022-topk/lines.txt
|
202
|
+
- test/basic/022-topk/output
|
190
203
|
- test/cli-runner.rb
|
191
|
-
has_rdoc:
|