ruby-bsdconv 11.1.0 → 11.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0066bb97b35708c2537ce5e757ba9bbcdb507a44
4
- data.tar.gz: 7e09436a715d04d719d71a9f52c4a29a35f5cc00
3
+ metadata.gz: ac83b010e742d45610e126dbf4e0fec6fcd3b717
4
+ data.tar.gz: ec794f163b76f01e5bdd6a9fd481affeeab81215
5
5
  SHA512:
6
- metadata.gz: 3da4b1f5d9743358fda293bca924e022dfaa394104c6465873063ccdf3e326a4aa4c795911e002549981e1df9ab41257a66ed6178bb20c7f5581bf9434763748
7
- data.tar.gz: f0cb64891797a31c7b225dd1b148cc17616f2604e28b3802c43f0115f837ee6f2e19ea19e34275ed88385fb014f37f2d0d47c65b709363a6ed04715fbe2c00e8
6
+ metadata.gz: efa3bf01b8e64282a142dad8315df7a9db9254335dce0b6cced96e285b7317200dbba88bc1d84153f89cf5c1f12e7812097664f4289e049f46e02aef00507a9d
7
+ data.tar.gz: 9e83c49f520b3c95dd5700ae0383776f6269cca868e36025149ad1863a98193d1cd296abfa0aebeeb7d0183d7fb31ea5b4e9c56583f6bab2800f8d1bb346cecf
@@ -0,0 +1,10 @@
1
+ #Gems
2
+ https://rubygems.org/gems/ruby-bsdconv
3
+
4
+ #Documentation
5
+ http://buganini.github.io/bsdconv/ruby-bsdconv/doc/api.html
6
+
7
+ see example/* for example
8
+
9
+ #Support
10
+ IRC: irc://irc.freenode.net#bsdconv
data/Rakefile CHANGED
@@ -2,24 +2,16 @@
2
2
 
3
3
  require "#{dir = File.dirname(__FILE__)}/task/gemgem"
4
4
 
5
- Gemgem.dir = dir
6
- ($LOAD_PATH << File.expand_path("#{Gemgem.dir}/lib")).uniq!
7
-
8
- desc 'Generate gemspec'
9
- task 'gem:spec' do
10
- Gemgem.spec = Gemgem.create do |s|
11
- s.name = 'ruby-bsdconv'
12
- s.version = '11.1.0'
13
- s.extensions = 'ext/ruby-bsdconv/extconf.rb'
14
- s.authors = ['Buganini Q']
15
- s.email = 'buganini@gmail.com'
16
- s.homepage = 'https://github.com/buganini/ruby-bsdconv'
17
- s.license = 'BSD'
18
- s.summary = 'ruby wrapper for bsdconv'
19
- s.description =
20
- "#{s.summary}. bsdconv is a BSD licensed charset/encoding converter" \
21
- " library with more functionalities than libiconv"
22
- end
23
-
24
- Gemgem.write
5
+ Gemgem.init(dir) do |s|
6
+ s.name = 'ruby-bsdconv'
7
+ s.version = '11.3.1'
8
+ s.extensions = 'ext/ruby-bsdconv/extconf.rb'
9
+ s.authors = ['Buganini Q']
10
+ s.email = 'buganini@gmail.com'
11
+ s.homepage = 'https://github.com/buganini/ruby-bsdconv'
12
+ s.license = 'BSD'
13
+ s.summary = 'ruby wrapper for bsdconv'
14
+ s.description =
15
+ "#{s.summary}. bsdconv is a BSD licensed charset/encoding converter" \
16
+ " library with more functionalities than libiconv"
25
17
  end
@@ -0,0 +1,99 @@
1
+ Ruby binding API
2
+ ================
3
+
4
+ .. rb:module:: bsdconv
5
+
6
+ .. rb:class:: Bsdconv
7
+
8
+ .. rb:const:: FILTER
9
+ .. rb:const:: FROM
10
+ .. rb:const:: INTER
11
+ .. rb:const:: TO
12
+
13
+ Phase type
14
+
15
+ .. rb:const:: CTL_ATTACH_SCORE
16
+ .. rb:const:: CTL_ATTACH_OUTPUT_FILE
17
+ .. rb:const:: CTL_AMBIGUOUS_PAD
18
+
19
+ Request for :rb:meth:`ctl`
20
+
21
+ .. rb:classmethod:: new(conversion)
22
+
23
+ Create converter instance with given conversion string
24
+
25
+ .. rb:classmethod:: insert_phase(conversion, codec, phase_type, phasen)
26
+
27
+ Insert conversion phase into bsdconv conversion string
28
+
29
+ .. rb:classmethod:: insert_codec(conversion, codec, phasen, codecn)
30
+
31
+ Insert conversion codec into bsdconv conversion string
32
+
33
+ .. rb:classmethod:: replace_phase(conversion, codec, phase_type, phasen)
34
+
35
+ Replace conversion phase in the bsdconv conversion string
36
+
37
+ .. rb:classmethod:: replace_codec(conversion, codec, phasen, codecn)
38
+
39
+ Replace conversion codec in the bsdconv conversion string
40
+
41
+ .. rb:classmethod:: error()
42
+
43
+ Get error message
44
+
45
+ .. rb:classmethod:: codecs_list(type)
46
+
47
+ DEPRECATED: Use :rb:meth:`modules_list` instead
48
+
49
+ .. rb:classmethod:: modules_list(type)
50
+
51
+ Get modules list of specified type
52
+
53
+ .. rb:classmethod:: codec_check(type, module)
54
+
55
+ DEPRECATED: Use :rb:meth:`module_check` instead
56
+
57
+ .. rb:classmethod:: module_check(type, module)
58
+
59
+ Check availability with given type and module name
60
+
61
+ .. rb:classmethod:: mktemp(template)
62
+
63
+ mkstemp()
64
+
65
+ .. rb:classmethod:: fopen(path, mode)
66
+
67
+ fopen()
68
+
69
+ .. rb:method:: conv(s)
70
+
71
+ Perform conversion
72
+
73
+ .. rb:method:: init()
74
+
75
+ Initialize/Reset bsdconv converter
76
+
77
+ .. rb:method:: ctl(arg_ptr_obj, arg_int)
78
+
79
+ Manipulate the underlying codec parameters
80
+
81
+ .. rb:method:: conv_chunk(s)
82
+
83
+ Perform conversion without initializing and flushing
84
+
85
+ .. rb:method:: conv_chunk_last(s)
86
+
87
+ Perform conversion without initializing
88
+
89
+ .. rb:method:: conv_file(from_file, to_file)
90
+
91
+ Perform conversion with given filename
92
+
93
+ .. rb:method:: counter([name])
94
+
95
+ Return conversion info
96
+
97
+ .. rb:method:: counter_reset([name])
98
+
99
+ Reset counter, if no name supplied, all counters will be reset
File without changes
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bsdconv'
4
+
5
+ c = Bsdconv.new(ARGV[0])
6
+
7
+ if c.nil?
8
+ abort(Bsdconv.error())
9
+ end
10
+
11
+ s = ""
12
+ c.init
13
+ while $stdin.gets
14
+ s += $_
15
+ end
16
+ puts c.conv(s)
17
+
18
+ p c.counter
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bsdconv'
4
+
5
+ c = Bsdconv.new(ARGV[0])
6
+
7
+ if c.nil?
8
+ abort(Bsdconv.error())
9
+ end
10
+
11
+ c.conv_file(ARGV[1], ARGV[2])
12
+
13
+ p c
14
+ p c.counter
@@ -5,7 +5,7 @@ require 'bsdconv'
5
5
  score,path=Bsdconv::mktemp("score.XXXXXX")
6
6
  list=open("characters_list.txt","w+")
7
7
 
8
- c=Bsdconv.new('utf-8:score_train:null')
8
+ c=Bsdconv.new('utf-8:score-train:null')
9
9
  c.init
10
10
 
11
11
  c.ctl(Bsdconv::CTL_ATTACH_SCORE, score, 0);
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bsdconv'
4
+
5
+ sin="utf-8:utf-8,ascii"
6
+ sout=Bsdconv.insert_phase(sin, "upper", Bsdconv::INTER, 1)
7
+ puts sout
8
+
9
+ sin=sout
10
+ sout=Bsdconv.replace_phase(sin, "full", Bsdconv::INTER, 1)
11
+ puts sout
12
+
13
+ sin=sout
14
+ sout=Bsdconv.replace_codec(sin, "big5", 2, 1)
15
+ puts sout
16
+
17
+ sin=sout
18
+ sout=Bsdconv.insert_codec(sin, "ascii", 0, 1)
19
+ puts sout
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bsdconv'
4
+
5
+ p Bsdconv.module_check(Bsdconv::FROM, "_utf-8")
6
+ p Bsdconv.module_check(Bsdconv::INTER, "_utf-8")
7
+ puts 'Filter:'
8
+ p Bsdconv.modules_list(Bsdconv::FILTER)
9
+ puts 'From:'
10
+ p Bsdconv.modules_list(Bsdconv::FROM)
11
+ puts 'Inter:'
12
+ p Bsdconv.modules_list(Bsdconv::INTER)
13
+ puts 'To:'
14
+ p Bsdconv.modules_list(Bsdconv::TO)
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2011-2013 Kuan-Chung Chiu <buganini@gmail.com>
2
+ * Copyright (c) 2011-2014 Kuan-Chung Chiu <buganini@gmail.com>
3
3
  *
4
4
  * Permission to use, copy, modify, and distribute this software for any
5
5
  * purpose with or without fee is hereby granted, provided that the above
@@ -40,7 +40,6 @@ static VALUE m_conv_chunk_last(VALUE, VALUE);
40
40
  static VALUE m_conv_file(VALUE, VALUE, VALUE);
41
41
  static VALUE m_counter(int, VALUE *, VALUE);
42
42
  static VALUE m_counter_reset(int, VALUE *, VALUE);
43
- static VALUE m_nil(VALUE);
44
43
  static VALUE m_inspect(VALUE);
45
44
 
46
45
  static VALUE f_insert_phase(VALUE, VALUE, VALUE, VALUE, VALUE);
@@ -48,8 +47,8 @@ static VALUE f_insert_codec(VALUE, VALUE, VALUE, VALUE, VALUE);
48
47
  static VALUE f_replace_phase(VALUE, VALUE, VALUE, VALUE, VALUE);
49
48
  static VALUE f_replace_codec(VALUE, VALUE, VALUE, VALUE, VALUE);
50
49
  static VALUE f_error(VALUE);
51
- static VALUE f_codecs_list(VALUE, VALUE);
52
- static VALUE f_codec_check(VALUE, VALUE, VALUE);
50
+ static VALUE f_modules_list(VALUE, VALUE);
51
+ static VALUE f_module_check(VALUE, VALUE, VALUE);
53
52
  static VALUE f_mktemp(VALUE, VALUE);
54
53
  static VALUE f_fopen(VALUE, VALUE, VALUE);
55
54
 
@@ -68,22 +67,24 @@ void Init_bsdconv(){
68
67
  rb_define_method(Bsdconv, "counter_reset", m_counter_reset, -1);
69
68
  rb_define_method(Bsdconv, "inspect", m_inspect, 0);
70
69
 
70
+ rb_define_const(Bsdconv, "FILTER", INT2NUM(FILTER));
71
71
  rb_define_const(Bsdconv, "FROM", INT2NUM(FROM));
72
72
  rb_define_const(Bsdconv, "INTER", INT2NUM(INTER));
73
73
  rb_define_const(Bsdconv, "TO", INT2NUM(TO));
74
74
 
75
- rb_define_const(Bsdconv, "CTL_ATTACH_SCORE", INT2NUM(BSDCONV_ATTACH_SCORE));
76
- rb_define_const(Bsdconv, "CTL_SET_WIDE_AMBI", INT2NUM(BSDCONV_SET_WIDE_AMBI));
77
- rb_define_const(Bsdconv, "CTL_SET_TRIM_WIDTH", INT2NUM(BSDCONV_SET_TRIM_WIDTH));
78
- rb_define_const(Bsdconv, "CTL_ATTACH_OUTPUT_FILE", INT2NUM(BSDCONV_ATTACH_OUTPUT_FILE));
75
+ rb_define_const(Bsdconv, "CTL_ATTACH_SCORE", INT2NUM(BSDCONV_CTL_ATTACH_SCORE));
76
+ rb_define_const(Bsdconv, "CTL_ATTACH_OUTPUT_FILE", INT2NUM(BSDCONV_CTL_ATTACH_OUTPUT_FILE));
77
+ rb_define_const(Bsdconv, "CTL_AMBIGUOUS_PAD", INT2NUM(BSDCONV_CTL_AMBIGUOUS_PAD));
79
78
 
80
79
  rb_define_singleton_method(Bsdconv, "insert_phase", f_insert_phase, 4);
81
80
  rb_define_singleton_method(Bsdconv, "insert_codec", f_insert_codec, 4);
82
81
  rb_define_singleton_method(Bsdconv, "replace_phase", f_replace_phase, 4);
83
82
  rb_define_singleton_method(Bsdconv, "replace_codec", f_replace_codec, 4);
84
83
  rb_define_singleton_method(Bsdconv, "error", f_error, 0);
85
- rb_define_singleton_method(Bsdconv, "codecs_list", f_codecs_list, 1);
86
- rb_define_singleton_method(Bsdconv, "codec_check", f_codec_check, 2);
84
+ rb_define_singleton_method(Bsdconv, "modules_list", f_modules_list, 1);
85
+ rb_define_singleton_method(Bsdconv, "module_check", f_module_check, 2);
86
+ rb_define_singleton_method(Bsdconv, "codecs_list", f_modules_list, 1);
87
+ rb_define_singleton_method(Bsdconv, "codec_check", f_module_check, 2);
87
88
  rb_define_singleton_method(Bsdconv, "mktemp", f_mktemp, 1);
88
89
  rb_define_singleton_method(Bsdconv, "fopen", f_fopen, 2);
89
90
 
@@ -246,7 +247,6 @@ static VALUE m_counter(int argc, VALUE *argv, VALUE self){
246
247
  }
247
248
 
248
249
  static VALUE m_counter_reset(int argc, VALUE *argv, VALUE self){
249
- VALUE ret;
250
250
  struct bsdconv_instance *ins;
251
251
  Data_Get_Struct(self, struct bsdconv_instance, ins);
252
252
  if(argc!=0){
@@ -277,28 +277,28 @@ static VALUE m_inspect(VALUE self){
277
277
 
278
278
  static VALUE f_insert_phase(VALUE self, VALUE conversion, VALUE codec, VALUE phase_type, VALUE phasen){
279
279
  char *s=bsdconv_insert_phase(RSTRING_PTR(conversion), RSTRING_PTR(codec), NUM2INT(phase_type), NUM2INT(phasen));
280
- char *ret=rb_str_new2(s);
280
+ VALUE ret=rb_str_new2(s);
281
281
  bsdconv_free(s);
282
282
  return ret;
283
283
  }
284
284
 
285
285
  static VALUE f_insert_codec(VALUE self, VALUE conversion, VALUE codec, VALUE phasen, VALUE codecn){
286
286
  char *s=bsdconv_insert_codec(RSTRING_PTR(conversion), RSTRING_PTR(codec), NUM2INT(phasen), NUM2INT(codecn));
287
- char *ret=rb_str_new2(s);
287
+ VALUE ret=rb_str_new2(s);
288
288
  bsdconv_free(s);
289
289
  return ret;
290
290
  }
291
291
 
292
292
  static VALUE f_replace_phase(VALUE self, VALUE conversion, VALUE codec, VALUE phase_type, VALUE phasen){
293
293
  char *s=bsdconv_replace_phase(RSTRING_PTR(conversion), RSTRING_PTR(codec), NUM2INT(phase_type), NUM2INT(phasen));
294
- char *ret=rb_str_new2(s);
294
+ VALUE ret=rb_str_new2(s);
295
295
  bsdconv_free(s);
296
296
  return ret;
297
297
  }
298
298
 
299
299
  static VALUE f_replace_codec(VALUE self, VALUE conversion, VALUE codec, VALUE phasen, VALUE codecn){
300
300
  char *s=bsdconv_replace_codec(RSTRING_PTR(conversion), RSTRING_PTR(codec), NUM2INT(phasen), NUM2INT(codecn));
301
- char *ret=rb_str_new2(s);
301
+ VALUE ret=rb_str_new2(s);
302
302
  bsdconv_free(s);
303
303
  return ret;
304
304
  }
@@ -311,11 +311,11 @@ static VALUE f_error(VALUE self){
311
311
  return ret;
312
312
  }
313
313
 
314
- static VALUE f_codecs_list(VALUE self, VALUE phase_type){
314
+ static VALUE f_modules_list(VALUE self, VALUE phase_type){
315
315
  char **list, **p;
316
316
  VALUE ret;
317
317
  ret=rb_ary_new();
318
- list=bsdconv_codecs_list(NUM2INT(phase_type));
318
+ list=bsdconv_modules_list(NUM2INT(phase_type));
319
319
  p=list;
320
320
  while(*p!=NULL){
321
321
  rb_ary_push(ret, rb_str_new2(*p));
@@ -326,8 +326,8 @@ static VALUE f_codecs_list(VALUE self, VALUE phase_type){
326
326
  return ret;
327
327
  }
328
328
 
329
- static VALUE f_codec_check(VALUE self, VALUE phase_type, VALUE codec){
330
- if(bsdconv_codec_check(NUM2INT(phase_type), RSTRING_PTR(codec))){
329
+ static VALUE f_module_check(VALUE self, VALUE phase_type, VALUE codec){
330
+ if(bsdconv_module_check(NUM2INT(phase_type), RSTRING_PTR(codec))){
331
331
  return Qtrue;
332
332
  }
333
333
  return Qfalse;
@@ -1,23 +1,29 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: ruby-bsdconv 11.1.0 ruby lib
2
+ # stub: ruby-bsdconv 11.3.1 ruby lib
3
+ # stub: ext/ruby-bsdconv/extconf.rb
3
4
 
4
5
  Gem::Specification.new do |s|
5
6
  s.name = "ruby-bsdconv"
6
- s.version = "11.1.0"
7
+ s.version = "11.3.1"
7
8
 
8
9
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
10
+ s.require_paths = ["lib"]
9
11
  s.authors = ["Buganini Q"]
10
- s.date = "2013-09-16"
12
+ s.date = "2014-05-13"
11
13
  s.description = "ruby wrapper for bsdconv. bsdconv is a BSD licensed charset/encoding converter library with more functionalities than libiconv"
12
14
  s.email = "buganini@gmail.com"
13
15
  s.extensions = ["ext/ruby-bsdconv/extconf.rb"]
14
16
  s.files = [
15
17
  ".gitignore",
16
- "README",
18
+ "README.md",
17
19
  "Rakefile",
18
- "example/example.rb",
19
- "example/example2.rb",
20
- "example/example3.rb",
20
+ "doc/api.rst",
21
+ "example/example_chunk.rb",
22
+ "example/example_conv.rb",
23
+ "example/example_conv_file.rb",
24
+ "example/example_ctl.rb",
25
+ "example/example_insert_replace.rb",
26
+ "example/example_modules.rb",
21
27
  "ext/ruby-bsdconv/bsdconv.c",
22
28
  "ext/ruby-bsdconv/extconf.rb",
23
29
  "ruby-bsdconv.gemspec",
@@ -25,8 +31,7 @@ Gem::Specification.new do |s|
25
31
  "test/test_basic.rb"]
26
32
  s.homepage = "https://github.com/buganini/ruby-bsdconv"
27
33
  s.licenses = ["BSD"]
28
- s.require_paths = ["lib"]
29
- s.rubygems_version = "2.1.3"
34
+ s.rubygems_version = "2.2.2"
30
35
  s.summary = "ruby wrapper for bsdconv"
31
36
  s.test_files = ["test/test_basic.rb"]
32
37
  end
@@ -1,106 +1,144 @@
1
1
 
2
- require 'pathname'
3
-
4
2
  module Gemgem
5
3
  class << self
6
- attr_accessor :dir, :spec
4
+ attr_accessor :dir, :spec, :spec_create
7
5
  end
8
6
 
9
7
  module_function
10
- def create
11
- yield(spec = Gem::Specification.new{ |s|
12
- s.rubygems_version = Gem::VERSION
13
- s.date = Time.now.strftime('%Y-%m-%d')
14
- s.files = gem_files
15
- s.test_files = gem_files.grep(%r{^test/(.+?/)*test_.+?\.rb$})
16
- s.executables = Dir['bin/*'].map{ |f| File.basename(f) }
17
- s.require_paths = %w[lib]
18
- })
19
- spec
20
- end
21
-
22
- def gem_tag
23
- spec.version.to_s
8
+ def gem_tag ; spec.version.to_s ; end
9
+ def gem_path ; "#{pkg_dir}/#{spec.name}-#{gem_tag}.gem"; end
10
+ def spec_path ; "#{dir}/#{spec.name}.gemspec" ; end
11
+ def pkg_dir ; "#{dir}/pkg" ; end
12
+ def escaped_dir; @escaped_dir ||= Regexp.escape(dir); end
13
+
14
+ def init dir, &block
15
+ self.dir = dir
16
+ $LOAD_PATH.unshift("#{dir}/lib")
17
+ ENV['RUBYLIB'] = "#{dir}/lib:#{ENV['RUBYLIB']}"
18
+ ENV['PATH'] = "#{dir}/bin:#{ENV['PATH']}"
19
+ self.spec_create = block
24
20
  end
25
21
 
26
- def gem_filename
27
- "#{spec.name}-#{spec.version}.gem"
22
+ def create
23
+ spec = Gem::Specification.new do |s|
24
+ s.date = Time.now.strftime('%Y-%m-%d')
25
+ s.files = gem_files
26
+ s.test_files = test_files
27
+ s.executables = bin_files
28
+ end
29
+ spec_create.call(spec)
30
+ self.spec = spec
28
31
  end
29
32
 
30
33
  def write
31
- File.open("#{dir}/#{spec.name}.gemspec", 'w'){ |f|
32
- f << split_lines(spec.to_ruby) }
34
+ File.open(spec_path, 'w'){ |f| f << split_lines(spec.to_ruby) }
33
35
  end
34
36
 
35
37
  def split_lines ruby
36
- ruby.gsub(/(.+?)\[(.+?)\]/){ |s|
38
+ ruby.gsub(/(.+?)\s*=\s*\[(.+?)\]/){ |s|
37
39
  if $2.index(',')
38
- "#{$1}[\n #{$2.split(',').map(&:strip).join(",\n ")}]"
40
+ "#{$1} = [\n #{$2.split(',').map(&:strip).join(",\n ")}]"
39
41
  else
40
42
  s
41
43
  end
42
44
  }
43
45
  end
44
46
 
47
+ def strip_path path
48
+ strip_home_path(strip_cwd_path(path))
49
+ end
50
+
51
+ def strip_home_path path
52
+ path.sub(ENV['HOME'], '~')
53
+ end
54
+
55
+ def strip_cwd_path path
56
+ path.sub(Dir.pwd, '.')
57
+ end
58
+
59
+ def git *args
60
+ `git --git-dir=#{dir}/.git #{args.join(' ')}`
61
+ end
62
+
63
+ def sh_git *args
64
+ Rake.sh('git', "--git-dir=#{dir}/.git", *args)
65
+ end
66
+
67
+ def sh_gem *args
68
+ Rake.sh(Gem.ruby, '-S', 'gem', *args)
69
+ end
70
+
71
+ def glob path=dir
72
+ Dir.glob("#{path}/**/*", File::FNM_DOTMATCH)
73
+ end
74
+
45
75
  def all_files
46
- @all_files ||= find_files(Pathname.new(dir)).map{ |file|
47
- if file.to_s =~ %r{\.git/|\.git$}
48
- nil
76
+ @all_files ||= fold_files(glob).sort
77
+ end
78
+
79
+ def fold_files files
80
+ files.inject([]){ |r, path|
81
+ if File.file?(path) && path !~ %r{/\.git(/|$)} &&
82
+ (rpath = path[%r{^#{escaped_dir}/(.*$)}, 1])
83
+ r << rpath
84
+ elsif File.symlink?(path) # walk into symlinks...
85
+ r.concat(fold_files(glob(File.expand_path(path,
86
+ File.readlink(path)))))
49
87
  else
50
- file.to_s
88
+ r
51
89
  end
52
- }.compact.sort
90
+ }
53
91
  end
54
92
 
55
93
  def gem_files
56
- @gem_files ||= all_files - ignored_files
94
+ @gem_files ||= all_files.reject{ |f|
95
+ f =~ ignored_pattern && !git_files.include?(f)
96
+ }
57
97
  end
58
98
 
59
- def ignored_files
60
- @ignored_file ||= all_files.select{ |path| ignore_patterns.find{ |ignore|
61
- path =~ ignore && !git_files.include?(path)}}
99
+ def test_files
100
+ @test_files ||= gem_files.grep(%r{^test/(.+?/)*test_.+?\.rb$})
101
+ end
102
+
103
+ def bin_files
104
+ @bin_files ||= gem_files.grep(%r{^bin/}).map{ |f| File.basename(f) }
62
105
  end
63
106
 
64
107
  def git_files
65
108
  @git_files ||= if File.exist?("#{dir}/.git")
66
- `git ls-files`.split("\n")
109
+ git('ls-files').split("\n")
67
110
  else
68
111
  []
69
112
  end
70
113
  end
71
114
 
72
- # protected
73
- def find_files path
74
- path.children.select(&:file?).map{|file| file.to_s[(dir.size+1)..-1]} +
75
- path.children.select(&:directory?).map{|dir| find_files(dir)}.flatten
115
+ def ignored_files
116
+ @ignored_files ||= all_files.grep(ignored_pattern)
76
117
  end
77
118
 
78
- def ignore_patterns
79
- @ignore_files ||= expand_patterns(
80
- gitignore.split("\n").reject{ |pattern|
81
- pattern.strip == ''
82
- }).map{ |pattern| %r{^([^/]+/)*?#{Regexp.escape(pattern)}(/[^/]+)*?$} }
119
+ def ignored_pattern
120
+ @ignored_pattern ||= if gitignore.empty?
121
+ /^$/
122
+ else
123
+ Regexp.new(expand_patterns(gitignore).join('|'))
124
+ end
83
125
  end
84
126
 
85
127
  def expand_patterns pathes
86
- pathes.map{ |path|
87
- if path !~ /\*/
88
- path
89
- else
90
- expand_patterns(
91
- Dir[path] +
92
- Pathname.new(File.dirname(path)).children.select(&:directory?).
93
- map{ |prefix| "#{prefix}/#{File.basename(path)}" })
94
- end
95
- }.flatten
128
+ # http://git-scm.com/docs/gitignore
129
+ pathes.flat_map{ |path|
130
+ # we didn't implement negative pattern for now
131
+ Regexp.escape(path).sub(%r{^/}, '^').gsub(/\\\*/, '[^/]*')
132
+ }
96
133
  end
97
134
 
98
135
  def gitignore
99
- if File.exist?(path = "#{dir}/.gitignore")
100
- File.read(path)
101
- else
102
- ''
103
- end
136
+ @gitignore ||= if File.exist?(path = "#{dir}/.gitignore")
137
+ File.read(path).lines.
138
+ reject{ |l| l == /^\s*(#|\s+$)/ }.map(&:strip)
139
+ else
140
+ []
141
+ end
104
142
  end
105
143
  end
106
144
 
@@ -108,22 +146,37 @@ namespace :gem do
108
146
 
109
147
  desc 'Install gem'
110
148
  task :install => [:build] do
111
- sh("#{Gem.ruby} -S gem install pkg/#{Gemgem.gem_filename}")
149
+ Gemgem.sh_gem('install', Gemgem.gem_path)
112
150
  end
113
151
 
114
152
  desc 'Build gem'
115
153
  task :build => [:spec] do
116
- sh("#{Gem.ruby} -S gem build #{Gemgem.spec.name}.gemspec")
117
- sh("mkdir -p pkg")
118
- sh("mv #{Gemgem.gem_filename} pkg/")
154
+ require 'fileutils'
155
+ require 'rubygems/package'
156
+ gem = nil
157
+ Dir.chdir(Gemgem.dir) do
158
+ gem = Gem::Package.build(Gem::Specification.load(Gemgem.spec_path))
159
+ FileUtils.mkdir_p(Gemgem.pkg_dir)
160
+ FileUtils.mv(gem, Gemgem.pkg_dir) # gem is relative path, but might be ok
161
+ end
162
+ puts "\e[35mGem built: \e[33m" \
163
+ "#{Gemgem.strip_path("#{Gemgem.pkg_dir}/#{gem}")}\e[0m"
164
+ end
165
+
166
+ desc 'Generate gemspec'
167
+ task :spec do
168
+ Gemgem.create
169
+ Gemgem.write
119
170
  end
120
171
 
121
172
  desc 'Release gem'
122
173
  task :release => [:spec, :check, :build] do
123
- sh("git tag #{Gemgem.gem_tag}")
124
- sh("git push")
125
- sh("git push --tags")
126
- sh("#{Gem.ruby} -S gem push pkg/#{Gemgem.gem_filename}")
174
+ Gemgem.module_eval do
175
+ sh_git('tag', Gemgem.gem_tag)
176
+ sh_git('push')
177
+ sh_git('push', '--tags')
178
+ sh_gem('push', Gemgem.gem_path)
179
+ end
127
180
  end
128
181
 
129
182
  task :check do
@@ -146,11 +199,35 @@ end # of gem namespace
146
199
 
147
200
  desc 'Run tests in memory'
148
201
  task :test do
149
- $LOAD_PATH.unshift('lib')
150
- Dir['./test/**/test_*.rb'].each{ |file| require file[0..-4] }
202
+ next if Gemgem.test_files.empty?
203
+
204
+ Gemgem.test_files.each{ |file| require "#{Gemgem.dir}/#{file[0..-4]}" }
151
205
  Test::Unit::Runner.autorun
152
206
  end
153
207
 
208
+ desc 'Trash ignored files'
209
+ task :clean => ['gem:spec'] do
210
+ next if Gemgem.ignored_files.empty?
211
+
212
+ require 'fileutils'
213
+ trash = File.expand_path("~/.Trash/#{Gemgem.spec.name}")
214
+ puts "Move the following files into:" \
215
+ " \e[35m#{Gemgem.strip_path(trash)}\e[33m"
216
+
217
+ Gemgem.ignored_files.each do |file|
218
+ from = "#{Gemgem.dir}/#{file}"
219
+ to = "#{trash}/#{File.dirname(file)}"
220
+ puts Gemgem.strip_path(from)
221
+
222
+ FileUtils.mkdir_p(to)
223
+ FileUtils.mv(from, to)
224
+ end
225
+
226
+ print "\e[0m"
227
+ end
228
+
154
229
  task :default do
155
- puts `#{Gem.ruby} -S #{$PROGRAM_NAME} -T`
230
+ # Is there a reliable way to do this in the current process?
231
+ # It failed miserably before between Rake versions...
232
+ exec "#{Gem.ruby} -S #{$PROGRAM_NAME} -f #{Rake.application.rakefile} -T"
156
233
  end
@@ -12,18 +12,18 @@ class TestBasic < Test::Unit::TestCase
12
12
 
13
13
  sin="utf-8:utf-8,ascii"
14
14
  sout=Bsdconv.insert_phase(sin, "upper", Bsdconv::INTER, 1)
15
- assert_equal "UTF-8:UPPER:UTF-8,ASCII", sout
15
+ assert_equal "utf-8:upper:utf-8,ascii", sout
16
16
 
17
17
  sin=sout
18
18
  sout=Bsdconv.replace_phase(sin, "full", Bsdconv::INTER, 1)
19
- assert_equal "UTF-8:FULL:UTF-8,ASCII", sout
19
+ assert_equal "utf-8:full:utf-8,ascii", sout
20
20
 
21
21
  sin=sout
22
22
  sout=Bsdconv.replace_codec(sin, "big5", 2, 1)
23
- assert_equal "UTF-8:FULL:UTF-8,BIG5", sout
23
+ assert_equal "utf-8:full:utf-8,big5", sout
24
24
 
25
25
  sin=sout
26
26
  sout=Bsdconv.insert_codec(sin, "ascii", 0, 1)
27
- assert_equal "UTF-8,ASCII:FULL:UTF-8,BIG5", sout
27
+ assert_equal "utf-8,ascii:full:utf-8,big5", sout
28
28
  end
29
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-bsdconv
3
3
  version: !ruby/object:Gem::Version
4
- version: 11.1.0
4
+ version: 11.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Buganini Q
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-16 00:00:00.000000000 Z
11
+ date: 2014-05-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: ruby wrapper for bsdconv. bsdconv is a BSD licensed charset/encoding
14
14
  converter library with more functionalities than libiconv
@@ -18,12 +18,16 @@ extensions:
18
18
  - ext/ruby-bsdconv/extconf.rb
19
19
  extra_rdoc_files: []
20
20
  files:
21
- - .gitignore
22
- - README
21
+ - ".gitignore"
22
+ - README.md
23
23
  - Rakefile
24
- - example/example.rb
25
- - example/example2.rb
26
- - example/example3.rb
24
+ - doc/api.rst
25
+ - example/example_chunk.rb
26
+ - example/example_conv.rb
27
+ - example/example_conv_file.rb
28
+ - example/example_ctl.rb
29
+ - example/example_insert_replace.rb
30
+ - example/example_modules.rb
27
31
  - ext/ruby-bsdconv/bsdconv.c
28
32
  - ext/ruby-bsdconv/extconf.rb
29
33
  - ruby-bsdconv.gemspec
@@ -39,17 +43,17 @@ require_paths:
39
43
  - lib
40
44
  required_ruby_version: !ruby/object:Gem::Requirement
41
45
  requirements:
42
- - - '>='
46
+ - - ">="
43
47
  - !ruby/object:Gem::Version
44
48
  version: '0'
45
49
  required_rubygems_version: !ruby/object:Gem::Requirement
46
50
  requirements:
47
- - - '>='
51
+ - - ">="
48
52
  - !ruby/object:Gem::Version
49
53
  version: '0'
50
54
  requirements: []
51
55
  rubyforge_project:
52
- rubygems_version: 2.1.3
56
+ rubygems_version: 2.2.2
53
57
  signing_key:
54
58
  specification_version: 4
55
59
  summary: ruby wrapper for bsdconv
data/README DELETED
@@ -1,3 +0,0 @@
1
- https://rubygems.org/gems/ruby-bsdconv
2
-
3
- see example/* for examples
@@ -1,21 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'bsdconv'
4
-
5
- c=Bsdconv.new('utf-8:utf-8')
6
-
7
- if c.nil?
8
- abort(Bsdconv.error())
9
- end
10
-
11
- c.insert_phase('full',Bsdconv::INTER, 1)
12
- puts c.conv('test')
13
-
14
- p Bsdconv.codec_check(Bsdconv::FROM, "_utf-8")
15
- p Bsdconv.codec_check(Bsdconv::INTER, "_utf-8")
16
- puts 'From:'
17
- p Bsdconv.codecs_list(Bsdconv::FROM)
18
- puts 'Inter:'
19
- p Bsdconv.codecs_list(Bsdconv::INTER)
20
- puts 'To:'
21
- p Bsdconv.codecs_list(Bsdconv::TO)