jpmobile 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 1
4
- :patch: 4
4
+ :patch: 5
5
5
  :build:
data/lib/jpmobile/util.rb CHANGED
@@ -10,11 +10,12 @@ module Jpmobile
10
10
  end
11
11
  when Array
12
12
  obj.collect!{|value| deep_apply(value, &proc)}
13
- when NilClass, TrueClass, FalseClass, Tempfile, StringIO
14
- return obj
15
- else
13
+ when String
16
14
  obj = obj.to_param if obj.respond_to?(:to_param)
17
15
  proc.call(obj)
16
+ else
17
+ # NilClass, TrueClass, FalseClass, Tempfile, StringIO, etc...
18
+ return obj
18
19
  end
19
20
  end
20
21
 
@@ -32,11 +33,12 @@ module Jpmobile
32
33
  end
33
34
  when Symbol
34
35
  new_obj = proc.call(obj.to_s).to_sym
35
- when NilClass, TrueClass, FalseClass, Tempfile, StringIO
36
- new_obj = obj
37
- else
36
+ when String
38
37
  obj = obj.to_param if obj.respond_to?(:to_param)
39
38
  new_obj = proc.call(obj)
39
+ else
40
+ # NilClass, TrueClass, FalseClass, Tempfile, StringIO, etc...
41
+ new_obj = obj
40
42
  end
41
43
 
42
44
  new_obj
@@ -67,7 +69,7 @@ module Jpmobile
67
69
  if utf8_str.respond_to?(:encode)
68
70
  utf8_str.encode("Shift_JIS", :crlf_newline => true)
69
71
  else
70
- NKF.nkf("-m0 -x -Ws", utf8_str).gsub(/\n/, "\r\n")
72
+ NKF.nkf("-m0 -x -W --oc=cp932", utf8_str).gsub(/\n/, "\r\n")
71
73
  end
72
74
  end
73
75
 
@@ -75,7 +77,7 @@ module Jpmobile
75
77
  if sjis_str.respond_to?(:encode)
76
78
  sjis_str.encode("UTF-8", :universal_newline => true)
77
79
  else
78
- NKF.nkf("-m0 -x -Sw", sjis_str).gsub(/\r\n/, "\n")
80
+ NKF.nkf("-m0 -x -w --ic=cp932", sjis_str).gsub(/\r\n/, "\n")
79
81
  end
80
82
  end
81
83
 
@@ -4,31 +4,41 @@ require 'nkf'
4
4
  require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper')
5
5
 
6
6
  describe Jpmobile::Util, ".deep_apply" do
7
+ include Jpmobile::Util
8
+
7
9
  it 'nilのときはnilを返すこと' do
8
- Jpmobile::Util.deep_apply(nil) {|obj| obj }.should equal(nil)
10
+ deep_apply(nil) {|obj| obj }.should equal(nil)
9
11
  end
10
12
 
11
13
  it 'trueのときはtrueを返すこと' do
12
- Jpmobile::Util.deep_apply(true) {|obj| obj }.should equal(true)
14
+ deep_apply(true) {|obj| obj }.should equal(true)
13
15
  end
14
16
 
15
17
  it 'falseのときはそのまま値を返すこと' do
16
- Jpmobile::Util.deep_apply(false) {|obj| obj }.should equal(false)
18
+ deep_apply(false) {|obj| obj }.should equal(false)
17
19
  end
18
20
 
19
21
  it 'Tempfileのインスタンスのときはそのまま値を返すこと' do
20
22
  temp = Tempfile.new('test')
21
- Jpmobile::Util.deep_apply(temp) {|obj| obj}.object_id.should equal(temp.object_id)
22
- # 本来 Jpmobile::Util.deep_apply(temp) {|obj| obj }.should equal(temp) が通るべきのような。
23
+ deep_apply(temp) {|obj| obj}.object_id.should equal(temp.object_id)
24
+ # 本来 deep_apply(temp) {|obj| obj }.should equal(temp) が通るべきのような。
23
25
  # 参考 http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-list/41720
24
26
  end
25
27
 
26
28
  it 'StringIOのインスタンスのときはそのまま値を返すこと' do
27
29
  string_io = StringIO.new('test')
28
- Jpmobile::Util.deep_apply(string_io) {|obj| obj }.should equal(string_io)
30
+ deep_apply(string_io) {|obj| obj }.should equal(string_io)
29
31
  end
30
32
 
31
33
  it "utf8_to_sjis で改行コードが CRLF に変更されること" do
32
- Jpmobile::Util.utf8_to_sjis("UTF8\nTEXT\n").should == Jpmobile::Util.sjis("UTF8\r\nTEXT\r\n")
34
+ utf8_to_sjis("UTF8\nTEXT\n").should == sjis("UTF8\r\nTEXT\r\n")
35
+ end
36
+
37
+ it "0x8150がU+FFE3に変換されること" do
38
+ sjis_to_utf8(sjis("\x81\x50")).should == [0xffe3].pack("U")
39
+ end
40
+
41
+ it "U+FFE3が0x8150に変換されること" do
42
+ utf8_to_sjis([0xffe3].pack("U")).should == sjis("\x81\x50")
33
43
  end
34
44
  end
@@ -4,4 +4,4 @@
4
4
  # If you change this key, all old signed cookies will become invalid!
5
5
  # Make sure the secret is at least 30 characters and all random,
6
6
  # no regular words or you'll be exposed to dictionary attacks.
7
- RailsRoot::Application.config.secret_token = 'ddd89a5d8777a00430608bc36c9108b2b8c2bc7fa2c15270971d1535d01ac7f267227f4003bd3d2e251bec7f1c32b2bec39d7919e25fb7225962e499b9c38793'
7
+ RailsRoot::Application.config.secret_token = '48ba9ac780d58f5ec08701d73d252900c9e2d89cbcc0107da56f8aa2add56a3a5849505e5408e58fa9228118f85ff9ca214ce19f4c2fe2b2a696abcc44e3ec65'
@@ -67,7 +67,7 @@ module Jpmobile
67
67
  if utf8_str.respond_to?(:encode)
68
68
  utf8_str.encode("Shift_JIS", :crlf_newline => true)
69
69
  else
70
- NKF.nkf("-m0 -x -Ws", utf8_str).gsub(/\n/, "\r\n")
70
+ NKF.nkf("-m0 -x -W --oc=cp932", utf8_str).gsub(/\n/, "\r\n")
71
71
  end
72
72
  end
73
73
 
@@ -75,7 +75,7 @@ module Jpmobile
75
75
  if sjis_str.respond_to?(:encode)
76
76
  sjis_str.encode("UTF-8", :universal_newline => true)
77
77
  else
78
- NKF.nkf("-m0 -x -Sw", sjis_str).gsub(/\r\n/, "\n")
78
+ NKF.nkf("-m0 -x -w --ic=cp932", sjis_str).gsub(/\r\n/, "\n")
79
79
  end
80
80
  end
81
81
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 4
9
- version: 0.1.4
8
+ - 5
9
+ version: 0.1.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Yoji Shidara
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-17 00:00:00 +09:00
18
+ date: 2011-01-20 00:00:00 +09:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency