jpmobile 5.0.0 → 5.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -3
  3. data/.rubocop.yml +123 -0
  4. data/CONTRIBUTING.md +16 -14
  5. data/Gemfile +6 -0
  6. data/Gemfile.lock +198 -0
  7. data/README.md +409 -0
  8. data/Rakefile +9 -9
  9. data/circle.yml +14 -0
  10. data/jpmobile.gemspec +9 -10
  11. data/lib/jpmobile.rb +6 -5
  12. data/lib/jpmobile/datum_conv.rb +35 -35
  13. data/lib/jpmobile/docomo_guid.rb +7 -8
  14. data/lib/jpmobile/email.rb +12 -12
  15. data/lib/jpmobile/emoticon.rb +85 -76
  16. data/lib/jpmobile/emoticon/au.rb +1284 -1284
  17. data/lib/jpmobile/emoticon/conversion_table.rb +3905 -3906
  18. data/lib/jpmobile/emoticon/docomo.rb +252 -252
  19. data/lib/jpmobile/emoticon/google.rb +9 -9
  20. data/lib/jpmobile/emoticon/softbank.rb +471 -471
  21. data/lib/jpmobile/emoticon/unicode.rb +9 -9
  22. data/lib/jpmobile/emoticon/z_combine.rb +20 -23
  23. data/lib/jpmobile/encoding.rb +1 -1
  24. data/lib/jpmobile/fallback_view_selector.rb +2 -3
  25. data/lib/jpmobile/filter.rb +44 -47
  26. data/lib/jpmobile/helpers.rb +38 -38
  27. data/lib/jpmobile/hook_action_view.rb +7 -7
  28. data/lib/jpmobile/hook_test_request.rb +0 -1
  29. data/lib/jpmobile/lookup_context.rb +1 -2
  30. data/lib/jpmobile/mail.rb +156 -134
  31. data/lib/jpmobile/mailer.rb +4 -4
  32. data/lib/jpmobile/mobile/abstract_mobile.rb +62 -36
  33. data/lib/jpmobile/mobile/android.rb +0 -1
  34. data/lib/jpmobile/mobile/android_tablet.rb +0 -1
  35. data/lib/jpmobile/mobile/au.rb +40 -28
  36. data/lib/jpmobile/mobile/black_berry.rb +0 -1
  37. data/lib/jpmobile/mobile/ddipocket.rb +1 -2
  38. data/lib/jpmobile/mobile/docomo.rb +47 -36
  39. data/lib/jpmobile/mobile/emobile.rb +1 -2
  40. data/lib/jpmobile/mobile/google_emoticon.rb +1 -1
  41. data/lib/jpmobile/mobile/ipad.rb +0 -1
  42. data/lib/jpmobile/mobile/iphone.rb +0 -1
  43. data/lib/jpmobile/mobile/smart_phone.rb +0 -1
  44. data/lib/jpmobile/mobile/softbank.rb +24 -20
  45. data/lib/jpmobile/mobile/tablet.rb +0 -1
  46. data/lib/jpmobile/mobile/unicode_emoticon.rb +15 -15
  47. data/lib/jpmobile/mobile/vodafone.rb +0 -1
  48. data/lib/jpmobile/mobile/willcom.rb +7 -7
  49. data/lib/jpmobile/mobile/windows_phone.rb +0 -1
  50. data/lib/jpmobile/path_set.rb +1 -1
  51. data/lib/jpmobile/position.rb +30 -14
  52. data/lib/jpmobile/rack/filter.rb +4 -4
  53. data/lib/jpmobile/rack/mobile_carrier.rb +0 -1
  54. data/lib/jpmobile/rack/params_filter.rb +7 -6
  55. data/lib/jpmobile/rails.rb +3 -4
  56. data/lib/jpmobile/request_with_mobile.rb +9 -6
  57. data/lib/jpmobile/resolver.rb +23 -17
  58. data/lib/jpmobile/session/active_record_store.rb +7 -9
  59. data/lib/jpmobile/session/mem_cache_store.rb +7 -9
  60. data/lib/jpmobile/sinatra.rb +1 -1
  61. data/lib/jpmobile/trans_sid.rb +15 -20
  62. data/lib/jpmobile/util.rb +61 -77
  63. data/lib/jpmobile/version.rb +1 -1
  64. data/lib/tasks/jpmobile_tasks.rake +35 -28
  65. data/spec/rack/jpmobile/android_spec.rb +5 -5
  66. data/spec/rack/jpmobile/au_spec.rb +74 -59
  67. data/spec/rack/jpmobile/black_berry_spec.rb +5 -5
  68. data/spec/rack/jpmobile/docomo_spec.rb +77 -64
  69. data/spec/rack/jpmobile/emoticon_spec.rb +137 -121
  70. data/spec/rack/jpmobile/filter_spec.rb +149 -128
  71. data/spec/rack/jpmobile/iphone_spec.rb +9 -8
  72. data/spec/rack/jpmobile/mobile_by_ua_spec.rb +22 -21
  73. data/spec/rack/jpmobile/params_filter_spec.rb +104 -96
  74. data/spec/rack/jpmobile/softbank_spec.rb +49 -42
  75. data/spec/rack/jpmobile/willcom_spec.rb +22 -18
  76. data/spec/rack/jpmobile/windows_phone.rb +5 -5
  77. data/spec/rack_helper.rb +9 -8
  78. data/spec/spec_helper.rb +5 -6
  79. data/spec/unit/decorated_mail_spec.rb +8 -9
  80. data/spec/unit/email_spec.rb +44 -44
  81. data/spec/unit/emoticon_spec.rb +57 -58
  82. data/spec/unit/encoding_spec.rb +35 -36
  83. data/spec/unit/is_carrier_spec.rb +49 -49
  84. data/spec/unit/mail_spec.rb +153 -143
  85. data/spec/unit/mobile/iphone_spec.rb +6 -7
  86. data/spec/unit/receive_mail_spec.rb +172 -173
  87. data/spec/unit/spec_helper.rb +6 -6
  88. data/spec/unit/util_spec.rb +125 -46
  89. data/spec/unit/valid_ip_spec.rb +35 -35
  90. data/spec/unit/variants_spec.rb +18 -19
  91. data/test/rails/overrides/Gemfile +54 -0
  92. data/test/rails/overrides/Gemfile.jpmobile +1 -2
  93. data/test/rails/overrides/app/controllers/admin/top_controller.rb +1 -1
  94. data/test/rails/overrides/app/controllers/docomo_guid_base_controller.rb +1 -1
  95. data/test/rails/overrides/app/controllers/filter_controller_base.rb +14 -6
  96. data/test/rails/overrides/app/controllers/hankaku_input_filter_controller.rb +1 -1
  97. data/test/rails/overrides/app/controllers/mobile_spec_controller.rb +1 -1
  98. data/test/rails/overrides/app/controllers/template_path_controller.rb +1 -2
  99. data/test/rails/overrides/app/controllers/trans_sid_base_controller.rb +18 -10
  100. data/test/rails/overrides/app/controllers/trans_sid_metal_controller.rb +0 -1
  101. data/test/rails/overrides/app/mailers/decorated_mailer.rb +3 -4
  102. data/test/rails/overrides/app/mailers/mobile_mailer.rb +5 -6
  103. data/test/rails/overrides/app/mailers/normal_mailer.rb +2 -3
  104. data/test/rails/overrides/autotest/discover.rb +2 -2
  105. data/test/rails/overrides/config/initializers/jpmobile_generator.rb +2 -2
  106. data/test/rails/overrides/config/routes.rb +95 -2
  107. data/test/rails/overrides/db/migrate/001_add_sessions_table.rb +2 -2
  108. data/test/rails/overrides/db/migrate/20100824062306_create_users.rb +1 -1
  109. data/test/rails/overrides/spec/controllers/docomo_guid_spec.rb +24 -25
  110. data/test/rails/overrides/spec/controllers/helpers_spec.rb +88 -88
  111. data/test/rails/overrides/spec/controllers/mobile_spec_controller_spec.rb +9 -9
  112. data/test/rails/overrides/spec/controllers/template_path_spec.rb +19 -19
  113. data/test/rails/overrides/spec/features/admin/top_spec.rb +7 -7
  114. data/test/rails/overrides/spec/features/filter_spec.rb +101 -102
  115. data/test/rails/overrides/spec/helpers/helpers_spec.rb +4 -4
  116. data/test/rails/overrides/spec/mailers/decorated_mailer_spec.rb +12 -12
  117. data/test/rails/overrides/spec/mailers/mobile_mailer_spec.rb +209 -194
  118. data/test/rails/overrides/spec/mailers/normal_mailer_spec.rb +10 -10
  119. data/test/rails/overrides/spec/rails_helper.rb +1 -1
  120. data/test/rails/overrides/spec/requests/docomo_spec.rb +13 -13
  121. data/test/rails/overrides/spec/requests/emobile_spec.rb +19 -19
  122. data/test/rails/overrides/spec/requests/pc_spec.rb +6 -6
  123. data/test/rails/overrides/spec/requests/softbank_emulator_spec.rb +6 -6
  124. data/test/rails/overrides/spec/requests/template_path_spec.rb +60 -60
  125. data/test/rails/overrides/spec/requests/trans_sid_spec.rb +89 -89
  126. data/test/sinatra/test/filter_test.rb +10 -11
  127. data/tools/e4u_conv.rb +0 -1
  128. metadata +18 -14
  129. data/README +0 -0
  130. data/README.rdoc +0 -308
@@ -1,4 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
1
  require 'jpmobile/mail'
3
2
  require 'jpmobile/lookup_context'
4
3
 
@@ -8,9 +7,9 @@ module Jpmobile
8
7
  module Mailer
9
8
  class Base < ActionMailer::Base
10
9
  self._view_paths = self._view_paths.dup
11
- self.view_paths.unshift(Jpmobile::Resolver.new(File.join(::Rails.root, "app/views")))
10
+ self.view_paths.unshift(Jpmobile::Resolver.new(File.join(::Rails.root, 'app/views')))
12
11
 
13
- def mail(headers={}, &block)
12
+ def mail(headers = {}, &block)
14
13
  tos = headers[:to] || self.default_params[:to]
15
14
  tos = tos.split(/,/)
16
15
 
@@ -27,7 +26,7 @@ module Jpmobile
27
26
 
28
27
  m = super(headers, &block)
29
28
 
30
- m.mobile = @mobile
29
+ m.mobile = @mobile
31
30
 
32
31
  # for decorated-mail manipulation
33
32
  m.rearrange! if @mobile.decorated?
@@ -37,6 +36,7 @@ module Jpmobile
37
36
 
38
37
  class << self
39
38
  protected
39
+
40
40
  def set_payload_for_mail(payload, mail) #:nodoc:
41
41
  super
42
42
 
@@ -1,11 +1,10 @@
1
- # -*- coding: utf-8 -*-
2
1
  require 'ipaddr'
3
2
 
4
3
  module Jpmobile::Mobile
5
4
  # 携帯電話の抽象クラス。
6
5
  class AbstractMobile
7
6
  # メールのデフォルトのcharset
8
- MAIL_CHARSET = "ISO-2022-JP"
7
+ MAIL_CHARSET = 'ISO-2022-JP'.freeze
9
8
 
10
9
  def initialize(env, request)
11
10
  @env = env
@@ -20,17 +19,27 @@ module Jpmobile::Mobile
20
19
  # 対応するメールアドレスの正規表現
21
20
  MAIL_ADDRESS_REGEXP = nil
22
21
  # テキスト部分の content-transfer-encoding
23
- MAIL_CONTENT_TRANSFER_ENCODING = '7bit'
22
+ MAIL_CONTENT_TRANSFER_ENCODING = '7bit'.freeze
24
23
 
25
24
  # 緯度経度があれば Position のインスタンスを返す。
26
- def position; return nil; end
25
+ def position
26
+ nil
27
+ end
27
28
 
28
29
  # 契約者又は端末を識別する文字列があれば返す。
29
- def ident; ident_subscriber || ident_device; end
30
+ def ident
31
+ ident_subscriber || ident_device
32
+ end
33
+
30
34
  # 契約者を識別する文字列があれば返す。
31
- def ident_subscriber; nil; end
35
+ def ident_subscriber
36
+ nil
37
+ end
38
+
32
39
  # 端末を識別する文字列があれば返す。
33
- def ident_device; nil; end
40
+ def ident_device
41
+ nil
42
+ end
34
43
 
35
44
  def valid_ip?
36
45
  @__valid_ip ||= self.class.valid_ip? @request.ip
@@ -40,12 +49,12 @@ module Jpmobile::Mobile
40
49
  def display
41
50
  @__displlay ||= Jpmobile::Mobile::Terminfo.new(self, @env)
42
51
  rescue LoadError
43
- puts "display method require jpmobile-terminfo plugin."
52
+ puts 'display method require jpmobile-terminfo plugin.'
44
53
  end
45
54
 
46
55
  # クッキーをサポートしているか。
47
56
  def supports_cookie?
48
- return false
57
+ false
49
58
  end
50
59
 
51
60
  # smartphone かどうか
@@ -72,78 +81,86 @@ module Jpmobile::Mobile
72
81
  def to_internal(str)
73
82
  str
74
83
  end
84
+
75
85
  def to_external(str, content_type, charset)
76
86
  [str, charset]
77
87
  end
88
+
78
89
  def default_charset
79
- "UTF-8"
90
+ 'UTF-8'
80
91
  end
81
92
 
82
93
  # for view selector
83
94
  def variants
84
95
  return @_variants if @_variants
85
96
 
86
- @_variants = self.class.ancestors.select {|c| c.to_s =~ /^Jpmobile/ && c.to_s !~ /Emoticon/}.map do |klass|
97
+ @_variants = self.class.ancestors.select { |c| c.to_s =~ /^Jpmobile/ && c.to_s !~ /Emoticon/ }.map do |klass|
87
98
  klass = klass.to_s.
88
- gsub(/Jpmobile::/, '').
89
- gsub(/AbstractMobile::/, '').
90
- gsub(/Mobile::SmartPhone/, 'smart_phone').
91
- gsub(/Mobile::Tablet/, 'tablet').
92
- gsub(/::/, '_').
93
- gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
94
- gsub(/([a-z\d])([A-Z])/, '\1_\2').
95
- downcase
96
- klass =~ /abstract/ ? "mobile" : klass
99
+ gsub(/Jpmobile::/, '').
100
+ gsub(/AbstractMobile::/, '').
101
+ gsub(/Mobile::SmartPhone/, 'smart_phone').
102
+ gsub(/Mobile::Tablet/, 'tablet').
103
+ gsub(/::/, '_').
104
+ gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
105
+ gsub(/([a-z\d])([A-Z])/, '\1_\2').
106
+ downcase
107
+ (klass =~ /abstract/) ? 'mobile' : klass
97
108
  end
98
109
 
99
110
  if @_variants.include?('tablet')
100
- @_variants = @_variants.reject{|v| v == "mobile"}.map{|v| v.gsub(/mobile_/, "tablet_")}
101
- elsif @_variants.include?("smart_phone")
102
- @_variants = @_variants.reject{|v| v == "mobile"}.map{|v| v.gsub(/mobile_/, "smart_phone_")}
111
+ @_variants = @_variants.reject { |v| v == 'mobile' }.map { |v| v.gsub(/mobile_/, 'tablet_') }
112
+ elsif @_variants.include?('smart_phone')
113
+ @_variants = @_variants.reject { |v| v == 'mobile' }.map { |v| v.gsub(/mobile_/, 'smart_phone_') }
103
114
  end
104
115
 
105
116
  @_variants || []
106
117
  end
118
+
107
119
  def mail_variants
108
120
  return @_mail_variants if @_mail_variants
109
121
 
110
- @_mail_variants = variants == ['mobile'] ? [] : variants
122
+ @_mail_variants = (variants == ['mobile']) ? [] : variants
111
123
  end
112
124
 
113
125
  # メール送信用
114
126
  def to_mail_subject(str)
115
127
  Jpmobile::Util.fold_text(Jpmobile::Emoticon.unicodecr_to_utf8(str)).
116
- map{|text| "=?#{mail_charset}?B?" + [to_mail_encoding(text)].pack('m').gsub(/\n/, '') + "?=" }.
128
+ map { |text| "=?#{mail_charset}?B?" + [to_mail_encoding(text)].pack('m').delete("\n") + '?=' }.
117
129
  join("\n\s")
118
130
  end
131
+
119
132
  def to_mail_body(str)
120
133
  to_mail_encoding(str)
121
134
  end
135
+
122
136
  def mail_charset(charset = nil)
123
137
  # (charset.nil? or charset == "") ? self.class::MAIL_CHARSET : charset
124
138
  # self.class::MAIL_CHARSET
125
- charset.nil? || charset == '' || charset =~ /US-ASCII/i ? self.class::MAIL_CHARSET : charset
139
+ (charset.nil? || charset == '' || charset =~ /US-ASCII/i) ? self.class::MAIL_CHARSET : charset
126
140
  end
141
+
127
142
  def content_transfer_encoding(headers)
128
143
  transfer_encoding = headers['Content-Transfer-Encoding']
129
144
  case headers['Content-Type'].to_s
130
- when /text\/plain/
131
- transfer_encoding.to_s == MAIL_CONTENT_TRANSFER_ENCODING ? transfer_encoding : MAIL_CONTENT_TRANSFER_ENCODING
132
- when /text\/html/
145
+ when %r{text/plain}
146
+ (transfer_encoding.to_s == MAIL_CONTENT_TRANSFER_ENCODING) ? transfer_encoding : MAIL_CONTENT_TRANSFER_ENCODING
147
+ when %r{text/html}
133
148
  if self.decorated?
134
149
  'quoted-printable'
135
150
  else
136
- transfer_encoding.to_s == MAIL_CONTENT_TRANSFER_ENCODING ? transfer_encoding : MAIL_CONTENT_TRANSFER_ENCODING
151
+ (transfer_encoding.to_s == MAIL_CONTENT_TRANSFER_ENCODING) ? transfer_encoding : MAIL_CONTENT_TRANSFER_ENCODING
137
152
  end
138
153
  else
139
154
  transfer_encoding
140
155
  end
141
156
  end
157
+
142
158
  def to_mail_encoding(str)
143
159
  str = Jpmobile::Emoticon.utf8_to_unicodecr(str)
144
160
  str = Jpmobile::Emoticon.unicodecr_to_external(str, Jpmobile::Emoticon::CONVERSION_TABLE_TO_PC_EMAIL, false)
145
161
  Jpmobile::Util.encode(str, mail_charset)
146
162
  end
163
+
147
164
  def utf8_to_mail_encode(str)
148
165
  case mail_charset
149
166
  when /ISO-2022-JP/i
@@ -154,29 +171,35 @@ module Jpmobile::Mobile
154
171
  str
155
172
  end
156
173
  end
174
+
157
175
  def to_mail_internal(str, charset)
158
176
  str
159
177
  end
178
+
160
179
  def to_mail_subject_encoded?(str)
161
180
  str.match(/\=\?#{mail_charset}\?B.+\?\=/i)
162
181
  end
182
+
163
183
  def to_mail_body_encoded?(str)
164
184
  Jpmobile::Util.jis?(str)
165
185
  end
186
+
166
187
  def decode_transfer_encoding(body, charset)
167
188
  body = Jpmobile::Util.set_encoding(body, charset)
168
189
  body = to_mail_internal(body, nil)
169
190
  Jpmobile::Util.force_encode(body, charset, Jpmobile::Util::UTF8)
170
191
  end
192
+
171
193
  def decoratable?
172
194
  false
173
195
  end
196
+
174
197
  def require_related_part?
175
198
  false
176
199
  end
177
- def decorated=(boolean)
178
- @decorated = boolean
179
- end
200
+
201
+ attr_writer :decorated
202
+
180
203
  def decorated?
181
204
  @decorated
182
205
  end
@@ -185,7 +208,7 @@ module Jpmobile::Mobile
185
208
  # 当該キャリアのIPアドレス帯域からのアクセスであれば +true+ を返す。
186
209
  # そうでなければ +false+ を返す。
187
210
  # IP空間が定義されていない場合は +nil+ を返す。
188
- def valid_ip? remote_addr
211
+ def valid_ip?(remote_addr)
189
212
  @ip_list ||= ip_address_class
190
213
  return false unless @ip_list
191
214
 
@@ -220,11 +243,13 @@ module Jpmobile::Mobile
220
243
 
221
244
  #
222
245
  def ip_address_class
223
- eval("::Jpmobile::Mobile::IpAddresses::#{self.to_s.split(/::/).last}").new rescue nil
246
+ Object.const_get("::Jpmobile::Mobile::IpAddresses::#{self.to_s.split(/::/).last}").new
247
+ rescue
248
+ nil
224
249
  end
225
250
  end
226
251
 
227
- #XXX: lib/jpmobile.rbのautoloadで先に各キャリアの定数を定義しているから動くのです
252
+ # XXX: lib/jpmobile.rbのautoloadで先に各キャリアの定数を定義しているから動くのです
228
253
  Jpmobile::Mobile.carriers.each do |carrier|
229
254
  carrier_class = Jpmobile::Mobile.const_get(carrier)
230
255
  next if carrier_class == self
@@ -235,6 +260,7 @@ module Jpmobile::Mobile
235
260
  end
236
261
 
237
262
  private
263
+
238
264
  # リクエストのパラメータ。
239
265
  def params
240
266
  if @request.respond_to? :parameters
@@ -1,4 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
1
  # =Android
3
2
 
4
3
  module Jpmobile::Mobile
@@ -1,4 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
1
  # =Android
3
2
 
4
3
  module Jpmobile::Mobile
@@ -1,4 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
1
  # =au携帯電話
3
2
 
4
3
  module Jpmobile::Mobile
@@ -7,52 +6,52 @@ module Jpmobile::Mobile
7
6
  class Au < AbstractMobile
8
7
  # 対応するUser-Agentの正規表現
9
8
  # User-Agent文字列中に "UP.Browser" を含むVodafoneの端末があるので注意が必要
10
- USER_AGENT_REGEXP = /^(?:KDDI|UP.Browser\/.+?)-(.+?) /
9
+ USER_AGENT_REGEXP = %r{^(?:KDDI|UP.Browser/.+?)-(.+?) }
11
10
  # 対応するメールアドレスの正規表現
12
11
  MAIL_ADDRESS_REGEXP = /.+@ezweb\.ne\.jp/
13
12
  # 簡易位置情報取得に対応していないデバイスID
14
13
  # http://www.au.kddi.com/ezfactory/tec/spec/eznavi.html
15
- LOCATION_UNSUPPORTED_DEVICE_ID = ["PT21", "TS25", "KCTE", "TST9", "KCU1", "SYT5", "KCTD", "TST8", "TST7", "KCTC", "SYT4", "KCTB", "KCTA", "TST6", "KCT9", "TST5", "TST4", "KCT8", "SYT3", "KCT7", "MIT1", "MAT3", "KCT6", "TST3", "KCT5", "KCT4", "SYT2", "MAT1", "MAT2", "TST2", "KCT3", "KCT2", "KCT1", "TST1", "SYT1"]
14
+ LOCATION_UNSUPPORTED_DEVICE_ID = %w[PT21 TS25 KCTE TST9 KCU1 SYT5 KCTD TST8 TST7 KCTC SYT4 KCTB KCTA TST6 KCT9 TST5 TST4 KCT8 SYT3 KCT7 MIT1 MAT3 KCT6 TST3 KCT5 KCT4 SYT2 MAT1 MAT2 TST2 KCT3 KCT2 KCT1 TST1 SYT1].freeze
16
15
  # GPS取得に対応していないデバイスID
17
- GPS_UNSUPPORTED_DEVICE_ID = ["PT21", "KC26", "SN28", "SN26", "KC23", "SA28", "TS25", "SA25", "SA24", "SN23", "ST14", "KC15", "SN22", "KC14", "ST13", "SN17", "SY15", "CA14", "HI14", "TS14", "KC13", "SN15", "SN16", "SY14", "ST12", "TS13", "CA13", "MA13", "HI13", "SN13", "SY13", "SN12", "SN14", "ST11", "DN11", "SY12", "KCTE", "TST9", "KCU1", "SYT5", "KCTD", "TST8", "TST7", "KCTC", "SYT4", "KCTB", "KCTA", "TST6", "KCT9", "TST5", "TST4", "KCT8", "SYT3", "KCT7", "MIT1", "MAT3", "KCT6", "TST3", "KCT5", "KCT4", "SYT2", "MAT1", "MAT2", "TST2", "KCT3", "KCT2", "KCT1", "TST1", "SYT1"]
16
+ GPS_UNSUPPORTED_DEVICE_ID = %w[PT21 KC26 SN28 SN26 KC23 SA28 TS25 SA25 SA24 SN23 ST14 KC15 SN22 KC14 ST13 SN17 SY15 CA14 HI14 TS14 KC13 SN15 SN16 SY14 ST12 TS13 CA13 MA13 HI13 SN13 SY13 SN12 SN14 ST11 DN11 SY12 KCTE TST9 KCU1 SYT5 KCTD TST8 TST7 KCTC SYT4 KCTB KCTA TST6 KCT9 TST5 TST4 KCT8 SYT3 KCT7 MIT1 MAT3 KCT6 TST3 KCT5 KCT4 SYT2 MAT1 MAT2 TST2 KCT3 KCT2 KCT1 TST1 SYT1].freeze
18
17
 
19
18
  # EZ番号(サブスクライバID)があれば返す。無ければ +nil+ を返す。
20
19
  def subno
21
- @request.env["HTTP_X_UP_SUBNO"]
20
+ @request.env['HTTP_X_UP_SUBNO']
22
21
  end
23
- alias :ident_subscriber :subno
22
+ alias_method :ident_subscriber, :subno
24
23
 
25
24
  # 位置情報があれば Position のインスタンスを返す。無ければ +nil+ を返す。
26
25
  def position
27
26
  return @__posotion if defined? @__posotion
28
- return @__posotion = nil if ( params["lat"].nil? || params['lat'] == '' || params["lon"].nil? || params["lon"] == '' )
27
+ return @__posotion = nil if params['lat'].nil? || params['lat'] == '' || params['lon'].nil? || params['lon'] == ''
29
28
  l = Jpmobile::Position.new
30
- l.options = params.reject {|x,v| !["ver", "datum", "unit", "lat", "lon", "alt", "time", "smaj", "smin", "vert", "majaa", "fm"].include?(x) }
31
- case params["unit"]
32
- when "1"
33
- l.lat = params["lat"].to_f
34
- l.lon = params["lon"].to_f
35
- when "0", "dms"
36
- raise "Invalid dms form" unless params["lat"] =~ /^([+-]?\d+)\.(\d+)\.(\d+\.\d+)$/
37
- l.lat = Jpmobile::Position.dms2deg($1,$2,$3)
38
- raise "Invalid dms form" unless params["lon"] =~ /^([+-]?\d+)\.(\d+)\.(\d+\.\d+)$/
39
- l.lon = Jpmobile::Position.dms2deg($1,$2,$3)
29
+ l.options = params.select { |x, _| %w[ver datum unit lat lon alt time smaj smin vert majaa fm].include?(x) }
30
+ case params['unit']
31
+ when '1'
32
+ l.lat = params['lat'].to_f
33
+ l.lon = params['lon'].to_f
34
+ when '0', 'dms'
35
+ raise 'Invalid dms form' unless params['lat'] =~ /^([+-]?\d+)\.(\d+)\.(\d+\.\d+)$/
36
+ l.lat = Jpmobile::Position.dms2deg(Regexp.last_match(1), Regexp.last_match(2), Regexp.last_match(3))
37
+ raise 'Invalid dms form' unless params['lon'] =~ /^([+-]?\d+)\.(\d+)\.(\d+\.\d+)$/
38
+ l.lon = Jpmobile::Position.dms2deg(Regexp.last_match(1), Regexp.last_match(2), Regexp.last_match(3))
40
39
  else
41
40
  return @__posotion = nil
42
41
  end
43
- if params["datum"] == "1"
42
+ if params['datum'] == '1'
44
43
  # ただし、params["datum"]=="tokyo"のとき(簡易位置情報)のときは、
45
44
  # 実際にはWGS84系のデータが渡ってくる
46
45
  # http://www.au.kddi.com/ezfactory/tec/spec/eznavi.html
47
46
  l.tokyo2wgs84!
48
47
  end
49
- return @__posotion = l
48
+ @__posotion = l
50
49
  end
51
50
 
52
51
  # デバイスIDを返す
53
52
  def device_id
54
53
  if @request.env['HTTP_USER_AGENT'] =~ USER_AGENT_REGEXP
55
- return $1
54
+ Regexp.last_match(1)
56
55
  else
57
56
  nil
58
57
  end
@@ -60,18 +59,28 @@ module Jpmobile::Mobile
60
59
 
61
60
  # 簡易位置情報取得に対応している場合は +true+ を返す。
62
61
  def supports_location?
63
- ! LOCATION_UNSUPPORTED_DEVICE_ID.include?(device_id)
62
+ !LOCATION_UNSUPPORTED_DEVICE_ID.include?(device_id)
64
63
  end
65
64
 
66
65
  # GPS位置情報取得に対応している場合は +true+ を返す。
67
66
  def supports_gps?
68
- ! GPS_UNSUPPORTED_DEVICE_ID.include?(device_id)
67
+ !GPS_UNSUPPORTED_DEVICE_ID.include?(device_id)
69
68
  end
70
69
 
71
70
  # cookieに対応しているか?
72
71
  def supports_cookie?
73
- protocol = @request.respond_to?(:scheme) ? @request.scheme : @request.protocol rescue "none"
74
- if protocol =~ /\Ahttps/
72
+ protocol =
73
+ begin
74
+ if @request.respond_to?(:scheme)
75
+ @request.scheme
76
+ else
77
+ @request.protocol
78
+ end
79
+ rescue
80
+ 'none'
81
+ end
82
+
83
+ if protocol.start_with?('https')
75
84
  false
76
85
  else
77
86
  true
@@ -85,13 +94,14 @@ module Jpmobile::Mobile
85
94
  # 文字コードを UTF-8 に変換
86
95
  str = Jpmobile::Util.sjis_to_utf8(str)
87
96
  # 数値参照を UTF-8 に変換
88
- Jpmobile::Emoticon::unicodecr_to_utf8(str)
97
+ Jpmobile::Emoticon.unicodecr_to_utf8(str)
89
98
  end
99
+
90
100
  def to_external(str, content_type, charset)
91
101
  # UTF-8を数値参照に
92
102
  str = Jpmobile::Emoticon.utf8_to_unicodecr(str)
93
103
  # 文字コードを Shift_JIS に変換
94
- if [nil, "text/html", "application/xhtml+xml"].include?(content_type)
104
+ if [nil, 'text/html', 'application/xhtml+xml'].include?(content_type)
95
105
  str = Jpmobile::Util.utf8_to_sjis(str)
96
106
  charset = default_charset unless str.empty?
97
107
  end
@@ -100,8 +110,9 @@ module Jpmobile::Mobile
100
110
 
101
111
  [str, charset]
102
112
  end
113
+
103
114
  def default_charset
104
- "Shift_JIS"
115
+ 'Shift_JIS'
105
116
  end
106
117
 
107
118
  # メール送信用
@@ -110,7 +121,7 @@ module Jpmobile::Mobile
110
121
  end
111
122
 
112
123
  def to_mail_internal(str, charset)
113
- if Jpmobile::Util.jis?(str) or Jpmobile::Util.ascii_8bit?(str) or charset == mail_charset
124
+ if Jpmobile::Util.jis?(str) || Jpmobile::Util.ascii_8bit?(str) || (charset == mail_charset)
114
125
  # 絵文字を数値参照に変換
115
126
  str = Jpmobile::Emoticon.external_to_unicodecr_au_mail(Jpmobile::Util.jis(str))
116
127
  str = Jpmobile::Util.jis_to_utf8(Jpmobile::Util.jis_win(str))
@@ -123,6 +134,7 @@ module Jpmobile::Mobile
123
134
  end
124
135
 
125
136
  private
137
+
126
138
  def to_mail_encoding(str)
127
139
  str = Jpmobile::Emoticon.utf8_to_unicodecr(str)
128
140
  str = Jpmobile::Util.utf8_to_jis(str)
@@ -1,4 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
1
  # =BlackBerry
3
2
 
4
3
  module Jpmobile::Mobile
@@ -1,11 +1,10 @@
1
- # -*- coding: utf-8 -*-
2
1
  # =DDI-POCKET
3
2
  module Jpmobile::Mobile
4
3
  # ==DDI-POCKET
5
4
  # スーパクラスはWillcom。
6
5
  class Ddipocket < Willcom
7
6
  # 対応するUser-Agentの正規表現
8
- USER_AGENT_REGEXP = /^Mozilla\/3.0\(DDIPOCKET/
7
+ USER_AGENT_REGEXP = %r{^Mozilla/3.0\(DDIPOCKET}
9
8
 
10
9
  MAIL_ADDRESS_REGEXP = nil # DdipocketはEmail判定だとWillcomと判定させたい
11
10
  end