parsely 0.1.2 → 0.1.3

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.
data/TODO CHANGED
@@ -2,7 +2,7 @@
2
2
  - _2 in dump by _1 in other
3
3
  - _2 in dump by _1 in other
4
4
  + _1 if /www/
5
- - _1 if _2 =~ x
5
+ + _1 if _2 =~ x
6
6
  - .parselyrc
7
7
  - split by: if a X or not, or if _1 in other_file (subsides comm)
8
8
  + in "foo 1\nbar 2" "sum(_2) if _2 < 3" to see how much I can delete
@@ -48,7 +48,7 @@ class Proc
48
48
  end
49
49
  end
50
50
  class Parsely
51
- VERSION = "0.1.2"
51
+ VERSION = "0.1.3"
52
52
  def self.cmd(&block)
53
53
  klass = Struct.new :value, &block
54
54
  klass.class_eval do
@@ -106,17 +106,17 @@ class Parsely
106
106
  @result
107
107
  end
108
108
  end,
109
- :sum => cmd do
110
- def initialize index
111
- super
112
- @running_value = 0
113
- @result = proc { @running_value }
114
- @result.single = true
115
- end
116
- def _process(value)
117
- @running_value += value.to_i
118
- @result
119
- end
109
+ :sum => cmd do
110
+ def initialize index
111
+ super
112
+ @running_value = 0
113
+ @result = proc { @running_value }
114
+ @result.single = true
115
+ end
116
+ def _process(value)
117
+ @running_value += value.to_i
118
+ @result
119
+ end
120
120
  end,
121
121
  :avg => cmd do
122
122
  def initialize index
@@ -194,8 +194,18 @@ class Parsely
194
194
  r=elems.map do |e|
195
195
  case e
196
196
  when /(\w+)\(\_(\d+)\)/
197
- klass=Ops[$1.to_sym]
197
+ opname = $1.to_sym
198
+ klass=Ops[opname]
198
199
  if klass.nil?
200
+ =begin
201
+ if respond_to? opname
202
+ klass = cmd do
203
+ def _process(value)
204
+ send opname, value
205
+ end
206
+ end
207
+ else
208
+ =end
199
209
  abort "unknown op '#$1'"
200
210
  end
201
211
  klass.new(Value.new($2.to_i))
@@ -217,10 +227,24 @@ class Parsely
217
227
  end
218
228
  end
219
229
 
230
+ def load_rc
231
+ rcfile = if ENV["PARSELYRC"]
232
+ ENV["PARSELYRC"]
233
+ else
234
+ home = ENV["HOME"] || Dir.pwd
235
+ home+"/.parselyrc"
236
+ #_parsely, $parsely etc
237
+ end
238
+ if File.exists?(rcfile)
239
+ load rcfile
240
+ end
241
+ end
242
+
220
243
  def main
221
244
  if ARGV.empty?
222
245
  abort("usage #$0 <expr> <file file file| stdin >")
223
246
  end
247
+ load_rc
224
248
  expr = ARGV.shift
225
249
  main_loop(expr,ARGF)
226
250
  end
@@ -0,0 +1,2 @@
1
+
2
+ PARSELYRC=parselyrc parsely '_1' counts.txt
@@ -0,0 +1,7 @@
1
+ keep 10
2
+ no 5
3
+ foo 1
4
+ bar 1
5
+ baz 2
6
+ quux 3
7
+
@@ -0,0 +1,8 @@
1
+ from rcfile
2
+ keep
3
+ no
4
+ foo
5
+ bar
6
+ baz
7
+ quux
8
+
@@ -0,0 +1 @@
1
+ puts "from rcfile"
@@ -0,0 +1 @@
1
+ HOME=myhome parsely '_1' counts.txt
@@ -0,0 +1,7 @@
1
+ keep 10
2
+ no 5
3
+ foo 1
4
+ bar 1
5
+ baz 2
6
+ quux 3
7
+
@@ -0,0 +1 @@
1
+ puts 'from home rc'
@@ -0,0 +1,8 @@
1
+ from home rc
2
+ keep
3
+ no
4
+ foo
5
+ bar
6
+ baz
7
+ quux
8
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parsely
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-07-14 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &2152909340 !ruby/object:Gem::Requirement
16
+ requirement: &2168739940 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2152909340
24
+ version_requirements: *2168739940
25
25
  description: ! "parsely is a simple tool for managing text files.\n Mostly
26
26
  to replace a lot of awk/sed/ruby/perl one-off scripts.\n This
27
27
  is an internal release, guaranteed to break and ruin your life."
@@ -81,6 +81,14 @@ files:
81
81
  - test/basic/014-line-index/command
82
82
  - test/basic/014-line-index/counts.txt
83
83
  - test/basic/014-line-index/output
84
+ - test/basic/015-rcfile-env/command
85
+ - test/basic/015-rcfile-env/counts.txt
86
+ - test/basic/015-rcfile-env/output
87
+ - test/basic/015-rcfile-env/parselyrc
88
+ - test/basic/016-rcfile-home/command
89
+ - test/basic/016-rcfile-home/counts.txt
90
+ - test/basic/016-rcfile-home/myhome/.parselyrc
91
+ - test/basic/016-rcfile-home/output
84
92
  - test/cli-runner.rb
85
93
  homepage: http://github.com/riffraff/parsely
86
94
  licenses: []
@@ -149,4 +157,12 @@ test_files:
149
157
  - test/basic/014-line-index/command
150
158
  - test/basic/014-line-index/counts.txt
151
159
  - test/basic/014-line-index/output
160
+ - test/basic/015-rcfile-env/command
161
+ - test/basic/015-rcfile-env/counts.txt
162
+ - test/basic/015-rcfile-env/output
163
+ - test/basic/015-rcfile-env/parselyrc
164
+ - test/basic/016-rcfile-home/command
165
+ - test/basic/016-rcfile-home/counts.txt
166
+ - test/basic/016-rcfile-home/myhome/.parselyrc
167
+ - test/basic/016-rcfile-home/output
152
168
  - test/cli-runner.rb