tidtools 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,4 +1,10 @@
1
- === 0.0.3 xxxx-xx-xx
1
+ === 0.0.4 2010/04/27
2
+
3
+ * 圧縮表示時に、十分に短ければ圧縮しないように
4
+
5
+ * つぶやき専用検索、twgrepを追加
6
+
7
+ === 0.0.3 2010-04-25
2
8
 
3
9
  * -cオプションを追加(結果を圧縮して表示する)
4
10
 
data/Manifest.txt CHANGED
@@ -4,12 +4,15 @@ PostInstall.txt
4
4
  README.rdoc
5
5
  Rakefile
6
6
  bin/tidgrep
7
+ bin/twgrep
7
8
  lib/tidgrep/cli.rb
8
9
  lib/tidtools.rb
9
10
  lib/tidtools/tiddle.rb
11
+ lib/twgrep/cli.rb
10
12
  script/console
11
13
  script/destroy
12
14
  script/generate
13
15
  test/test_helper.rb
14
16
  test/test_tidgrep_cli.rb
15
17
  test/test_tidtools.rb
18
+ test/test_twgrep_cli.rb
data/bin/twgrep ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+ #
4
+ # Created on 2010-4-27.
5
+ # Copyright (c) 2010. All rights reserved.
6
+
7
+ require 'rubygems'
8
+ require File.expand_path(File.dirname(__FILE__) + "/../lib/tidtools")
9
+ require "twgrep/cli"
10
+
11
+ # バージョン番号
12
+ Version = "0.0.1"
13
+
14
+ # コマンドの実行
15
+ Twgrep::CLI.execute(STDOUT, ARGV)
data/lib/tidgrep/cli.rb CHANGED
@@ -15,36 +15,20 @@ module Tidgrep
15
15
  MATCH_TWEET_COMP_NUM = 5
16
16
 
17
17
  class Tidgrep
18
- def initialize
19
- @file_name = ENV['TIDGREP_PATH']
20
- @title = nil
21
- @regexp_option = 0
22
- @report = false
23
- @match_rule = "line"
24
- @is_comp = false
25
- end
18
+ def initialize(stdout, file_name, title, regexp_option, report, match_rule, is_comp, keywords)
19
+ @file_name = file_name
20
+ @title = title
21
+ @regexp_option = regexp_option
22
+ @report = report
23
+ @match_rule = match_rule
24
+ @is_comp = is_comp
26
25
 
27
- def setupParam(stdout, arguments)
28
- opt = OptionParser.new('tidgrep [option] keyword')
29
- opt.on('-f FILE_NAME', '--filename FILE_NAME', 'TiddlyWiki file name') {|v| @file_name = v }
30
- opt.on('-t TITLE', '--title TITLE', 'match title') {|v| @title = v }
31
- opt.on('-i', '--ignore', 'ignore case') {|v| @regexp_option |= Regexp::IGNORECASE }
32
- opt.on('-r', '--report', 'disp report') {|v| @report = true }
33
- opt.on('-m MATCH_RULE', '--match MATCH_RULE', 'match rule [line, tiddle, tweet]') {|v| @match_rule = v }
34
- opt.on('-c', '--comp', 'compression disp') {|v| @is_comp = true; @report = true }
35
- opt.parse!(arguments)
36
-
37
26
  @title_regexp = @title && Regexp.new(@title, @regexp_option)
38
27
 
39
28
  @content_regexps = []
40
- arguments.each do |keyword|
29
+ keywords.each do |keyword|
41
30
  @content_regexps << Regexp.new(keyword, @regexp_option)
42
31
  end
43
-
44
- unless validOption?
45
- puts opt.help
46
- exit
47
- end
48
32
  end
49
33
 
50
34
  def validOption?
@@ -156,7 +140,13 @@ module Tidgrep
156
140
  unless @is_comp
157
141
  puts tiddle.content
158
142
  else
159
- print tiddle.content.split(/\n/)[0..(MATCH_TIDDLE_LINE_NUM - 1)].join("\n") + "\n.\n"
143
+ tiddle_a = tiddle.content.split(/\n/)
144
+
145
+ if (tiddle_a.size <= MATCH_TIDDLE_LINE_NUM)
146
+ print tiddle.content
147
+ else
148
+ print tiddle_a[0..(MATCH_TIDDLE_LINE_NUM - 1)].join("\n") + "\n.\n"
149
+ end
160
150
  end
161
151
 
162
152
  if (@is_comp && match_tiddles >= MATCH_TIDDLE_COMP_NUM)
@@ -204,7 +194,13 @@ module Tidgrep
204
194
  unless @is_comp
205
195
  print tweet
206
196
  else
207
- print tweet.split(/\n/)[0..(MATCH_TWEET_LINE_NUM - 1)].join("\n") + "\n.\n"
197
+ tweet_a = tweet.split(/\n/)
198
+
199
+ if (tweet_a.size <= MATCH_TWEET_LINE_NUM)
200
+ print tweet
201
+ else
202
+ print tweet_a[0..(MATCH_TWEET_LINE_NUM - 1)].join("\n") + "\n.\n"
203
+ end
208
204
  end
209
205
 
210
206
  if (@is_comp && match_tweets >= MATCH_TWEET_COMP_NUM)
@@ -223,11 +219,7 @@ module Tidgrep
223
219
  end
224
220
  end
225
221
 
226
- def execute(stdout, arguments=[])
227
- # パラメータの設定
228
- setupParam(stdout, arguments)
229
-
230
- # マッチルールごとに処理を変える
222
+ def execute
231
223
  if (@content_regexps.size > 0)
232
224
  case @match_rule
233
225
  when "line"
@@ -246,7 +238,37 @@ module Tidgrep
246
238
 
247
239
  class CLI
248
240
  def self.execute(stdout, arguments=[])
249
- Tidgrep.new.execute(stdout, arguments)
241
+ file_name = ENV['TIDGREP_PATH']
242
+ title = nil
243
+ regexp_option = 0
244
+ report = false
245
+ match_rule = "line"
246
+ is_comp = false
247
+
248
+ opt = OptionParser.new('tidgrep [option] keyword')
249
+ opt.on('-f FILE_NAME', '--filename FILE_NAME', 'TiddlyWiki file name') {|v| file_name = v }
250
+ opt.on('-t TITLE', '--title TITLE', 'match title') {|v| title = v }
251
+ opt.on('-i', '--ignore', 'ignore case') {|v| regexp_option |= Regexp::IGNORECASE }
252
+ opt.on('-r', '--report', 'disp report') {|v| report = true }
253
+ opt.on('-m MATCH_RULE', '--match MATCH_RULE', 'match rule [line, tiddle, tweet]') {|v| match_rule = v }
254
+ opt.on('-c', '--comp', 'compression disp') {|v| is_comp = true; report = true }
255
+ opt.parse!(arguments)
256
+
257
+ obj = Tidgrep.new(stdout,
258
+ file_name,
259
+ title,
260
+ regexp_option,
261
+ report,
262
+ match_rule,
263
+ is_comp,
264
+ arguments)
265
+
266
+ unless obj.validOption?
267
+ puts opt.help
268
+ exit
269
+ end
270
+
271
+ obj.execute
250
272
  end
251
273
  end
252
274
  end
data/lib/tidtools.rb CHANGED
@@ -2,5 +2,5 @@ $:.unshift(File.dirname(__FILE__)) unless
2
2
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
4
  module Tidtools
5
- VERSION = '0.0.3'
5
+ VERSION = '0.0.4'
6
6
  end
data/lib/twgrep/cli.rb ADDED
@@ -0,0 +1,39 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.join(File.dirname(__FILE__), '../tidgrep/cli')
3
+ require 'optparse'
4
+
5
+ module Twgrep
6
+ class CLI
7
+ def self.execute(stdout, arguments=[])
8
+ file_name = ENV['TIDGREP_PATH']
9
+ title = "Tweet"
10
+ regexp_option = 0
11
+ report = false
12
+ match_rule = "tweet"
13
+ is_comp = false
14
+
15
+ opt = OptionParser.new('twgrep [option] keyword')
16
+ opt.on('-f FILE_NAME', '--filename FILE_NAME', 'TiddlyWiki file name') {|v| file_name = v }
17
+ opt.on('-i', '--ignore', 'ignore case') {|v| regexp_option |= Regexp::IGNORECASE }
18
+ opt.on('-r', '--report', 'disp report') {|v| report = true }
19
+ opt.on('-c', '--comp', 'compression disp') {|v| is_comp = true; report = true }
20
+ opt.parse!(arguments)
21
+
22
+ obj = Tidgrep::Tidgrep.new(stdout,
23
+ file_name,
24
+ title,
25
+ regexp_option,
26
+ report,
27
+ match_rule,
28
+ is_comp,
29
+ arguments)
30
+
31
+ unless obj.validOption? && arguments.size > 0
32
+ puts opt.help
33
+ exit
34
+ end
35
+
36
+ obj.execute
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,14 @@
1
+ require File.join(File.dirname(__FILE__), "test_helper.rb")
2
+ require 'twgrep/cli'
3
+
4
+ class TestTwgrepCli < Test::Unit::TestCase
5
+ def setup
6
+ Twgrep::CLI.execute(@stdout_io = StringIO.new, [])
7
+ @stdout_io.rewind
8
+ @stdout = @stdout_io.read
9
+ end
10
+
11
+ def test_print_default_output
12
+ assert_match(/To update this executable/, @stdout)
13
+ end
14
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 3
9
- version: 0.0.3
8
+ - 4
9
+ version: 0.0.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - ongaeshi
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-25 00:00:00 +09:00
17
+ date: 2010-04-27 00:00:00 +09:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -64,6 +64,7 @@ email:
64
64
  - ongaeshi@example.com
65
65
  executables:
66
66
  - tidgrep
67
+ - twgrep
67
68
  extensions: []
68
69
 
69
70
  extra_rdoc_files:
@@ -77,15 +78,18 @@ files:
77
78
  - README.rdoc
78
79
  - Rakefile
79
80
  - bin/tidgrep
81
+ - bin/twgrep
80
82
  - lib/tidgrep/cli.rb
81
83
  - lib/tidtools.rb
82
84
  - lib/tidtools/tiddle.rb
85
+ - lib/twgrep/cli.rb
83
86
  - script/console
84
87
  - script/destroy
85
88
  - script/generate
86
89
  - test/test_helper.rb
87
90
  - test/test_tidgrep_cli.rb
88
91
  - test/test_tidtools.rb
92
+ - test/test_twgrep_cli.rb
89
93
  has_rdoc: true
90
94
  homepage: http://github.com/ongaeshi/tidtools
91
95
  licenses: []
@@ -121,3 +125,4 @@ test_files:
121
125
  - test/test_helper.rb
122
126
  - test/test_tidgrep_cli.rb
123
127
  - test/test_tidtools.rb
128
+ - test/test_twgrep_cli.rb