tidtools 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ === 0.0.5 2010/04/28
2
+
3
+ * Windows環境の場合はSJISで入出力するように
4
+
1
5
  === 0.0.4 2010/04/27
2
6
 
3
7
  * 圧縮表示時に、十分に短ければ圧縮しないように
data/Manifest.txt CHANGED
@@ -7,6 +7,7 @@ bin/tidgrep
7
7
  bin/twgrep
8
8
  lib/tidgrep/cli.rb
9
9
  lib/tidtools.rb
10
+ lib/tidtools/platform.rb
10
11
  lib/tidtools/tiddle.rb
11
12
  lib/twgrep/cli.rb
12
13
  script/console
data/lib/tidgrep/cli.rb CHANGED
@@ -1,33 +1,37 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  require File.join(File.dirname(__FILE__), '../tidtools/tiddle')
3
+ require File.join(File.dirname(__FILE__), '../tidtools/platform')
3
4
  require 'optparse'
5
+ require 'kconv'
4
6
 
5
7
  module Tidgrep
6
- # 圧縮表示時のパラメータ
7
- MATCH_LINE_COMP_NUM = 5
8
+ class Tidgrep
9
+ # 圧縮表示時のパラメータ
10
+ MATCH_LINE_COMP_NUM = 5
8
11
 
9
- MATCH_ONLY_TITLE_COMP_NUM = 5
12
+ MATCH_ONLY_TITLE_COMP_NUM = 5
10
13
 
11
- MATCH_TIDDLE_LINE_NUM = 3
12
- MATCH_TIDDLE_COMP_NUM = 5
14
+ MATCH_TIDDLE_LINE_NUM = 3
15
+ MATCH_TIDDLE_COMP_NUM = 5
13
16
 
14
- MATCH_TWEET_LINE_NUM = 3
15
- MATCH_TWEET_COMP_NUM = 5
17
+ MATCH_TWEET_LINE_NUM = 3
18
+ MATCH_TWEET_COMP_NUM = 5
16
19
 
17
- class Tidgrep
18
- def initialize(stdout, file_name, title, regexp_option, report, match_rule, is_comp, keywords)
20
+ def initialize(stdout, file_name, title, regexp_option, report, match_rule, is_comp, keywords, kcode)
21
+ @stdout = stdout
19
22
  @file_name = file_name
20
23
  @title = title
21
24
  @regexp_option = regexp_option
22
25
  @report = report
23
26
  @match_rule = match_rule
24
27
  @is_comp = is_comp
28
+ @kcode = kcode
25
29
 
26
30
  @title_regexp = @title && Regexp.new(@title, @regexp_option)
27
31
 
28
32
  @content_regexps = []
29
33
  keywords.each do |keyword|
30
- @content_regexps << Regexp.new(keyword, @regexp_option)
34
+ @content_regexps << Regexp.new(self.kconv(keyword), @regexp_option)
31
35
  end
32
36
  end
33
37
 
@@ -43,6 +47,22 @@ module Tidgrep
43
47
  return true
44
48
  end
45
49
 
50
+ def kconv(str)
51
+ if (@kcode != Kconv::UTF8)
52
+ str.kconv(@kconv, Kconv::UTF8)
53
+ else
54
+ str
55
+ end
56
+ end
57
+
58
+ def print(msg)
59
+ @stdout.print self.kconv msg
60
+ end
61
+
62
+ def puts(msg)
63
+ @stdout.puts self.kconv msg
64
+ end
65
+
46
66
  def match_line
47
67
  tiddles = Tiddle.parse_sort_modified(@file_name)
48
68
 
@@ -244,6 +264,7 @@ module Tidgrep
244
264
  report = false
245
265
  match_rule = "line"
246
266
  is_comp = false
267
+ kcode = Platform.get_shell_kcode
247
268
 
248
269
  opt = OptionParser.new('tidgrep [option] keyword')
249
270
  opt.on('-f FILE_NAME', '--filename FILE_NAME', 'TiddlyWiki file name') {|v| file_name = v }
@@ -261,7 +282,8 @@ module Tidgrep
261
282
  report,
262
283
  match_rule,
263
284
  is_comp,
264
- arguments)
285
+ arguments,
286
+ kcode)
265
287
 
266
288
  unless obj.validOption?
267
289
  puts opt.help
@@ -0,0 +1,16 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'kconv'
3
+
4
+ class Platform
5
+ def self.windows_os?
6
+ RUBY_PLATFORM =~ /mswin(?!ce)|mingw|cygwin|bccwin/
7
+ end
8
+
9
+ def self.get_shell_kcode
10
+ if windows_os?
11
+ Kconv::SJIS
12
+ else
13
+ Kconv::UTF8
14
+ end
15
+ end
16
+ 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.4'
5
+ VERSION = '0.0.5'
6
6
  end
data/lib/twgrep/cli.rb CHANGED
@@ -11,6 +11,7 @@ module Twgrep
11
11
  report = false
12
12
  match_rule = "tweet"
13
13
  is_comp = false
14
+ kcode = Platform.get_shell_kcode
14
15
 
15
16
  opt = OptionParser.new('twgrep [option] keyword')
16
17
  opt.on('-f FILE_NAME', '--filename FILE_NAME', 'TiddlyWiki file name') {|v| file_name = v }
@@ -26,7 +27,8 @@ module Twgrep
26
27
  report,
27
28
  match_rule,
28
29
  is_comp,
29
- arguments)
30
+ arguments,
31
+ kcode)
30
32
 
31
33
  unless obj.validOption? && arguments.size > 0
32
34
  puts opt.help
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 4
9
- version: 0.0.4
8
+ - 5
9
+ version: 0.0.5
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-27 00:00:00 +09:00
17
+ date: 2010-04-28 00:00:00 +09:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -81,6 +81,7 @@ files:
81
81
  - bin/twgrep
82
82
  - lib/tidgrep/cli.rb
83
83
  - lib/tidtools.rb
84
+ - lib/tidtools/platform.rb
84
85
  - lib/tidtools/tiddle.rb
85
86
  - lib/twgrep/cli.rb
86
87
  - script/console