jpmobile 0.1.4 → 0.1.5
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/VERSION.yml
CHANGED
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
|
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
|
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 -
|
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 -
|
80
|
+
NKF.nkf("-m0 -x -w --ic=cp932", sjis_str).gsub(/\r\n/, "\n")
|
79
81
|
end
|
80
82
|
end
|
81
83
|
|
data/spec/unit/util_spec.rb
CHANGED
@@ -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
|
-
|
10
|
+
deep_apply(nil) {|obj| obj }.should equal(nil)
|
9
11
|
end
|
10
12
|
|
11
13
|
it 'trueのときはtrueを返すこと' do
|
12
|
-
|
14
|
+
deep_apply(true) {|obj| obj }.should equal(true)
|
13
15
|
end
|
14
16
|
|
15
17
|
it 'falseのときはそのまま値を返すこと' do
|
16
|
-
|
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
|
-
|
22
|
-
# 本来
|
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
|
-
|
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
|
-
|
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 = '
|
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 -
|
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 -
|
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
|
-
-
|
9
|
-
version: 0.1.
|
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:
|
18
|
+
date: 2011-01-20 00:00:00 +09:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|