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
data/Rakefile CHANGED
@@ -1,4 +1,4 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
2
  require 'rake/testtask'
3
3
  require 'fileutils'
4
4
  require 'pathname'
@@ -8,28 +8,28 @@ include FileUtils
8
8
  desc 'Default: run unit tests.'
9
9
  task :default => :test
10
10
 
11
- desc "Update misc tables"
11
+ desc 'Update misc tables'
12
12
  task :update do
13
- Dir.glob("tools/update_*.rb").each do |path|
13
+ Dir.glob('tools/update_*.rb').each do |path|
14
14
  ruby path
15
15
  end
16
16
  end
17
17
 
18
18
  namespace :test do
19
- desc "Preparation of external modules"
19
+ desc 'Preparation of external modules'
20
20
  task :prepare do
21
21
  external_repos = [
22
- "jpmobile-ipaddresses",
23
- "jpmobile-terminfo"
22
+ 'jpmobile-ipaddresses',
23
+ 'jpmobile-terminfo',
24
24
  ]
25
- github_prefix = "git://github.com/jpmobile"
26
- vendor_path = Pathname.new(Dir.pwd).join("vendor")
25
+ github_prefix = 'git://github.com/jpmobile'
26
+ vendor_path = Pathname.new(Dir.pwd).join('vendor')
27
27
  FileUtils.mkdir_p(vendor_path)
28
28
 
29
29
  FileUtils.cd(vendor_path) do
30
30
  external_repos.each do |repos|
31
31
  unless File.directory?("#{repos}/.git")
32
- Git.clone("#{github_prefix}/#{repos}.git", repos, {:path => vendor_path})
32
+ Git.clone("#{github_prefix}/#{repos}.git", repos, { :path => vendor_path })
33
33
  end
34
34
  end
35
35
  end
@@ -0,0 +1,14 @@
1
+ machine:
2
+ timezone:
3
+ Asia/Tokyo
4
+ ruby:
5
+ version: 2.4.0
6
+
7
+ database:
8
+ override:
9
+ - echo "Skip create database."
10
+
11
+ test:
12
+ override:
13
+ - bundle exec rubocop
14
+ - bundle exec rake test
@@ -1,24 +1,23 @@
1
- # -*- encoding: utf-8 -*-
2
1
  lib = File.expand_path('../lib', __FILE__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'jpmobile/version'
5
4
 
6
5
  Gem::Specification.new do |gem|
7
- gem.name = "jpmobile"
6
+ gem.name = 'jpmobile'
8
7
  gem.version = Jpmobile::VERSION
9
- gem.authors = ["Shin-ichiro OGAWA", "Yoji Shidara"]
10
- gem.email = ["rust.stnard@gmail.com"]
11
- gem.description = %q{A Rails plugin for mobile devices in Japan}
12
- gem.summary = %q{A Rails plugin for mobile devices in Japan}
8
+ gem.authors = ['Shin-ichiro OGAWA', 'Yoji Shidara']
9
+ gem.email = ['rust.stnard@gmail.com']
10
+ gem.description = 'A Rails plugin for mobile devices in Japan'
11
+ gem.summary = 'Rails plugin for mobile devices in Japan'
13
12
  gem.homepage = 'http://jpmobile-rails.org'
14
13
 
15
- gem.files = `git ls-files`.split($/)
14
+ gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
16
15
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
- gem.require_paths = ["lib"]
16
+ gem.require_paths = ['lib']
18
17
 
19
18
  gem.add_development_dependency 'rails', '~> 5.0.0'
20
- gem.add_development_dependency 'rspec', '3.5.0.beta4'
21
- gem.add_development_dependency 'rspec-rails', '3.5.0.beta4'
19
+ gem.add_development_dependency 'rspec'
20
+ gem.add_development_dependency 'rspec-rails'
22
21
  gem.add_development_dependency 'rspec-its'
23
22
  gem.add_development_dependency 'capybara-webkit'
24
23
  gem.add_development_dependency 'geokit'
@@ -1,7 +1,6 @@
1
- # -*- coding: utf-8 -*-
2
- $:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) ||
3
- $:.include?(File.expand_path(File.dirname(__FILE__)))
4
- require "jpmobile/version"
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__)) unless $LOAD_PATH.include?(File.dirname(__FILE__)) ||
2
+ $LOAD_PATH.include?(File.expand_path(File.dirname(__FILE__)))
3
+ require 'jpmobile/version'
5
4
  require 'singleton'
6
5
  require 'rack/utils'
7
6
 
@@ -41,7 +40,7 @@ module Jpmobile
41
40
  autoload :UnicodeEmoticon, 'jpmobile/mobile/unicode_emoticon'
42
41
  autoload :GoogleEmoticon, 'jpmobile/mobile/google_emoticon'
43
42
 
44
- DEFAULT_CARRIERS = %w(Docomo Au Softbank Vodafone Emobile Willcom Ddipocket Ipad AndroidTablet Iphone Android WindowsPhone BlackBerry)
43
+ DEFAULT_CARRIERS = %w[Docomo Au Softbank Vodafone Emobile Willcom Ddipocket Ipad AndroidTablet Iphone Android WindowsPhone BlackBerry].freeze
45
44
 
46
45
  def self.carriers
47
46
  @carriers ||= DEFAULT_CARRIERS.dup
@@ -65,10 +64,12 @@ module Jpmobile
65
64
 
66
65
  autoload :FallbackViewSelector, 'jpmobile/fallback_view_selector'
67
66
 
67
+ autoload :ParamsOverCookie, 'jpmobile/trans_sid'
68
68
  autoload :TransSidRedirecting, 'jpmobile/trans_sid'
69
69
  autoload :TransSid, 'jpmobile/trans_sid'
70
70
 
71
71
  module_function
72
+
72
73
  def config
73
74
  ::Jpmobile::Configuration.instance
74
75
  end
@@ -5,68 +5,68 @@
5
5
  # 日本測量協会, 2002.
6
6
 
7
7
  module DatumConv
8
- GRS80 = [ 6378137, 298.257222101]
9
- Bessel = [6377397.155, 299.152813]
10
- Tokyo97toITRF94 = [-146.414, 507.337, 680.507]
11
- ITRF94toTokyo97 = [ 146.414,-507.337,-680.507]
12
- Deg2Rad = Math::PI/180
8
+ GRS80 = [6_378_137, 298.257222101].freeze
9
+ Bessel = [6_377_397.155, 299.152813].freeze
10
+ Tokyo97toITRF94 = [-146.414, 507.337, 680.507].freeze
11
+ ITRF94toTokyo97 = [146.414, -507.337, -680.507].freeze
12
+ Deg2Rad = Math::PI / 180
13
13
 
14
14
  # 緯度(度),経度(度),高度(m)を三次元直交座標(m)に変換する。
15
- def self.blh2xyz(b_deg,l_deg,he,datum)
15
+ def self.blh2xyz(b_deg, l_deg, he, datum)
16
16
  a = datum[0].to_f
17
- f = 1.0/datum[1]
17
+ f = 1.0 / datum[1]
18
18
  b = b_deg * Deg2Rad
19
19
  l = l_deg * Deg2Rad
20
20
 
21
21
  e2 = f * (2 - f)
22
- n = a / Math.sqrt(1 - e2 * Math.sin(b)**2 )
22
+ n = a / Math.sqrt(1 - e2 * Math.sin(b)**2)
23
23
 
24
- x = (n+he)*Math.cos(b)*Math.cos(l)
25
- y = (n+he)*Math.cos(b)*Math.sin(l)
26
- z = (n*(1-e2)+he)*Math.sin(b)
27
- return x,y,z
24
+ x = (n + he) * Math.cos(b) * Math.cos(l)
25
+ y = (n + he) * Math.cos(b) * Math.sin(l)
26
+ z = (n * (1 - e2) + he) * Math.sin(b)
27
+ return x, y, z
28
28
  end
29
29
 
30
30
  # 三次元直交座標(m)を緯度(度),経度(度),高度(m)に変換する。
31
- def self.xyz2blh(x,y,z,datum)
31
+ def self.xyz2blh(x, y, z, datum)
32
32
  a = datum[0].to_f
33
- f = 1.0/datum[1]
33
+ f = 1.0 / datum[1]
34
34
  e2 = f * (2 - f)
35
- l = Math.atan2(y,x)
35
+ l = Math.atan2(y, x)
36
36
 
37
- p = Math.sqrt(x**2+y**2)
38
- r = Math.sqrt(p**2+z**2)
39
- u = Math.atan2(z*((1-f)+e2*a/r),p)
40
- b = Math.atan2(z*(1-f)+e2*a*Math.sin(u)**3,(1-f)*(p-e2*a*Math.cos(u)**3))
37
+ p = Math.sqrt(x**2 + y**2)
38
+ r = Math.sqrt(p**2 + z**2)
39
+ u = Math.atan2(z * ((1 - f) + e2 * a / r), p)
40
+ b = Math.atan2(z * (1 - f) + e2 * a * Math.sin(u)**3, (1 - f) * (p - e2 * a * Math.cos(u)**3))
41
41
 
42
- he = p*Math.cos(b) + z*Math.sin(b) - a*Math.sqrt(1-e2*Math.sin(b)**2)
42
+ he = p * Math.cos(b) + z * Math.sin(b) - a * Math.sqrt(1 - e2 * Math.sin(b)**2)
43
43
 
44
44
  b_deg = b / Deg2Rad
45
45
  l_deg = l / Deg2Rad
46
- return b_deg,l_deg,he
46
+ return b_deg, l_deg, he
47
47
  end
48
48
 
49
49
  # 三次元直交座標でシフトする。
50
- def self.xyz2xyz(x,y,z,d)
51
- return x+d[0],y+d[1],z+d[2]
50
+ def self.xyz2xyz(x, y, z, d)
51
+ return x + d[0], y + d[1], z + d[2]
52
52
  end
53
53
 
54
54
  # 日本測地系から世界測地系に変換する。
55
- def self.tky2jgd(b,l,he=0)
56
- x,y,z = blh2xyz(b,l,he,Bessel)
57
- x,y,z = xyz2xyz(x,y,z,Tokyo97toITRF94)
58
- b,l,he = xyz2blh(x,y,z,GRS80)
59
- return b,l,he
55
+ def self.tky2jgd(b, l, he = 0)
56
+ x, y, z = blh2xyz(b, l, he, Bessel)
57
+ x, y, z = xyz2xyz(x, y, z, Tokyo97toITRF94)
58
+ b, l, he = xyz2blh(x, y, z, GRS80)
59
+ return b, l, he
60
60
  end
61
61
 
62
62
  # 世界測地系から日本測地系に変換する。
63
- def self.jgd2tky(b,l,he=0)
64
- x,y,z = blh2xyz(b,l,he,GRS80)
65
- x,y,z = xyz2xyz(x,y,z,ITRF94toTokyo97)
66
- b,l,he = xyz2blh(x,y,z,Bessel)
67
- return b,l,he
63
+ def self.jgd2tky(b, l, he = 0)
64
+ x, y, z = blh2xyz(b, l, he, GRS80)
65
+ x, y, z = xyz2xyz(x, y, z, ITRF94toTokyo97)
66
+ b, l, he = xyz2blh(x, y, z, Bessel)
67
+ return b, l, he
68
68
  end
69
69
  end
70
70
 
71
- #DatumConv.tky2jgd(b,l)
72
- #DatumConv.jgd2tky(b,l)
71
+ # DatumConv.tky2jgd(b,l)
72
+ # DatumConv.jgd2tky(b,l)
@@ -1,27 +1,26 @@
1
- # -*- coding: utf-8 -*-
2
- #DoCoMoの時guid=onの付与
1
+ # DoCoMoの時guid=onの付与
3
2
  class ActionController::Base #:nodoc:
4
3
  class_attribute :docomo_guid_mode
5
4
 
6
5
  class << self
7
- def docomo_guid(mode=:docomo)
6
+ def docomo_guid(mode = :docomo)
8
7
  include Jpmobile::DocomoGuid
9
8
  self.docomo_guid_mode = mode
10
9
  end
11
10
  end
12
11
  end
13
12
 
14
-
15
13
  module Jpmobile::DocomoGuid #:nodoc:
16
14
  protected
15
+
17
16
  def default_url_options
18
17
  result = super || {}
19
18
  return result unless request # for test process
20
19
  return result unless apply_add_guid?
21
- return result.merge({:guid => "ON"})
20
+ result.merge({ guid: 'ON' })
22
21
  end
23
22
 
24
- #guid=ONを付与すべきか否かを返す
23
+ # guid=ONを付与すべきか否かを返す
25
24
  def apply_add_guid?
26
25
  return true if docomo_guid_mode == :always
27
26
  return false if docomo_guid_mode == :none
@@ -34,10 +33,10 @@ module Jpmobile::DocomoGuid #:nodoc:
34
33
  return false unless request.mobile.valid_ip?
35
34
  end
36
35
 
37
- return true
36
+ true
38
37
  end
39
38
 
40
39
  def not_apply_guid_user_agent?
41
- request.user_agent.match(/(?:Googlebot|Y!J-SRD\/1\.0|Y!J-MBS\/1\.0)/)
40
+ request.user_agent.match(%r{(?:Googlebot|Y!J-SRD/1\.0|Y!J-MBS/1\.0)})
42
41
  end
43
42
  end
@@ -1,13 +1,9 @@
1
- # -*- coding: utf-8 -*-
2
1
  # =メールアドレスモジュール
3
2
  #
4
3
  module Jpmobile
5
4
  # email関連の処理
6
5
  class Email
7
6
  class << self
8
- @@japanese_mail_address_regexp = nil
9
- @@converting_content_type = ['text/plain', 'text/html']
10
-
11
7
  # メールアドレスよりキャリア情報を取得する
12
8
  # _param1_:: email メールアドレス
13
9
  # return :: Jpmobile::Mobileで定義されている携帯キャリアクラス
@@ -24,8 +20,8 @@ module Jpmobile
24
20
  Mobile.carriers.each do |const|
25
21
  c = Mobile.const_get(const)
26
22
  if c::MAIL_ADDRESS_REGEXP &&
27
- header.match(/(\S+@[A-Za-z0-9\-\.\_]+)/) &&
28
- $1.match(/^#{c::MAIL_ADDRESS_REGEXP}$/)
23
+ header.match(/(\S+@[A-Za-z0-9\-\.\_]+)/) &&
24
+ Regexp.last_match(1).match(/^#{c::MAIL_ADDRESS_REGEXP}$/)
29
25
  return c
30
26
  end
31
27
  end
@@ -37,17 +33,21 @@ module Jpmobile
37
33
  nil
38
34
  end
39
35
 
40
- def japanese_mail_address_regexp=(regexp)
41
- @@japanese_mail_address_regexp = regexp
42
- end
36
+ attr_writer :japanese_mail_address_regexp
43
37
 
44
38
  def japanese_mail?(header)
45
- @@japanese_mail_address_regexp and header.match(@@japanese_mail_address_regexp)
39
+ @japanese_mail_address_regexp and header.match(@japanese_mail_address_regexp)
40
+ end
41
+
42
+ attr_writer :converting_content_type
43
+
44
+ def converting_content_type
45
+ @converting_content_type ||= ['text/plain', 'text/html']
46
46
  end
47
47
 
48
48
  def convertable?(content_type)
49
- if @@converting_content_type.respond_to?(:each)
50
- @@converting_content_type.each do |c|
49
+ if converting_content_type.respond_to?(:each)
50
+ converting_content_type.each do |c|
51
51
  return true if content_type.match(c)
52
52
  end
53
53
  end
@@ -1,27 +1,25 @@
1
- # -*- coding: utf-8 -*-
2
-
3
1
  require 'scanf'
4
2
  require 'nkf'
5
3
 
6
4
  module Jpmobile
7
5
  # 絵文字関連処理
8
6
  module Emoticon
9
- %w( DOCOMO_SJIS_TO_UNICODE DOCOMO_UNICODE_TO_SJIS ).each do |const|
7
+ %w[DOCOMO_SJIS_TO_UNICODE DOCOMO_UNICODE_TO_SJIS].each do |const|
10
8
  autoload const, 'jpmobile/emoticon/docomo'
11
9
  end
12
- %w( AU_SJIS_TO_UNICODE AU_UNICODE_TO_EMAILJIS AU_SJIS_TO_EMAIL_JIS AU_EMAILJIS_TO_UNICODE ).each do |const|
10
+ %w[AU_SJIS_TO_UNICODE AU_UNICODE_TO_EMAILJIS AU_SJIS_TO_EMAIL_JIS AU_EMAILJIS_TO_UNICODE].each do |const|
13
11
  autoload const, 'jpmobile/emoticon/au'
14
12
  end
15
- %w(
13
+ %w[
16
14
  SOFTBANK_UNICODE_TO_WEBCODE SOFTBANK_WEBCODE_TO_UNICODE
17
15
  SOFTBANK_UNICODE_TO_SJIS SOFTBANK_SJIS_TO_UNICODE
18
- ).each do |const|
16
+ ].each do |const|
19
17
  autoload const, 'jpmobile/emoticon/softbank'
20
18
  end
21
- %w( CONVERSION_TABLE_TO_DOCOMO CONVERSION_TABLE_TO_AU CONVERSION_TABLE_TO_SOFTBANK ).each do |const|
19
+ %w[CONVERSION_TABLE_TO_DOCOMO CONVERSION_TABLE_TO_AU CONVERSION_TABLE_TO_SOFTBANK].each do |const|
22
20
  autoload const, 'jpmobile/emoticon/conversion_table'
23
21
  end
24
- %w(
22
+ %w[
25
23
  SJIS_TO_UNICODE UNICODE_TO_SJIS
26
24
  SJIS_REGEXP SOFTBANK_WEBCODE_REGEXP DOCOMO_SJIS_REGEXP AU_SJIS_REGEXP SOFTBANK_UNICODE_REGEXP
27
25
  EMOTICON_UNICODES UTF8_REGEXP
@@ -30,13 +28,13 @@ module Jpmobile
30
28
  GOOGLE_EMOTICONS GOOGLE_EMOTICON_REGEXP GOOGLE_EMOTICON_TO_CARRIER_EMOTICON
31
29
  CONVERSION_TABLE_TO_UNICODE_EMOTICON CONVERSION_TABLE_TO_GOOGLE_EMOTICON
32
30
  GETA_CODE GETA
33
- ).each do |const|
31
+ ].each do |const|
34
32
  autoload const, 'jpmobile/emoticon/z_combine'
35
33
  end
36
- %w( GOOGLE_TO_DOCOMO_UNICODE GOOGLE_TO_AU_UNICODE GOOGLE_TO_SOFTBANK_UNICODE ).each do |const|
34
+ %w[GOOGLE_TO_DOCOMO_UNICODE GOOGLE_TO_AU_UNICODE GOOGLE_TO_SOFTBANK_UNICODE].each do |const|
37
35
  autoload const, 'jpmobile/emoticon/google'
38
36
  end
39
- %w( UNICODE_TO_DOCOMO_UNICODE UNICODE_TO_AU_UNICODE UNICODE_TO_SOFTBANK_UNICODE ).each do |const|
37
+ %w[UNICODE_TO_DOCOMO_UNICODE UNICODE_TO_AU_UNICODE UNICODE_TO_SOFTBANK_UNICODE].each do |const|
40
38
  autoload const, 'jpmobile/emoticon/unicode'
41
39
  end
42
40
 
@@ -45,7 +43,7 @@ module Jpmobile
45
43
  str.gsub(DOCOMO_SJIS_REGEXP) do |match|
46
44
  sjis = match.unpack('n').first
47
45
  unicode = DOCOMO_SJIS_TO_UNICODE[sjis]
48
- unicode ? ("&#x%04x;"%unicode) : match
46
+ unicode ? ('&#x%04x;' % unicode) : match
49
47
  end
50
48
  end
51
49
 
@@ -54,7 +52,7 @@ module Jpmobile
54
52
  str.gsub(AU_SJIS_REGEXP) do |match|
55
53
  sjis = match.unpack('n').first
56
54
  unicode = AU_SJIS_TO_UNICODE[sjis]
57
- unicode ? ("&#x%04x;"%unicode) : match
55
+ unicode ? ('&#x%04x;' % unicode) : match
58
56
  end
59
57
  end
60
58
 
@@ -65,7 +63,7 @@ module Jpmobile
65
63
  jis_string.gsub(/[\x21-\x7e]{2}/) do |match|
66
64
  jis = match.unpack('n').first
67
65
  unicode = AU_EMAILJIS_TO_UNICODE[jis]
68
- unicode ? Jpmobile::Util.ascii_8bit("\x1b\x28\x42&#x%04x;\x1b\x24\x42"%unicode) : match
66
+ unicode ? Jpmobile::Util.ascii_8bit("\x1b\x28\x42&#x%04x;\x1b\x24\x42" % unicode) : match
69
67
  end
70
68
  end
71
69
  end
@@ -75,17 +73,19 @@ module Jpmobile
75
73
  # SoftBank Unicode
76
74
  str.gsub(SOFTBANK_UNICODE_REGEXP) do |match|
77
75
  unicode = match.unpack('U').first
78
- "&#x%04x;" % (unicode+0x1000)
76
+ '&#x%04x;' % (unicode + 0x1000)
79
77
  end
80
78
  end
79
+
81
80
  def self.external_to_unicodecr_softbank_sjis(str)
82
81
  # SoftBank Shift_JIS
83
82
  str.gsub(SOFTBANK_SJIS_REGEXP) do |match|
84
83
  sjis = match.unpack('n').first
85
84
  unicode = SOFTBANK_SJIS_TO_UNICODE[sjis]
86
- "&#x%04x;" % (unicode+0x1000)
85
+ '&#x%04x;' % (unicode + 0x1000)
87
86
  end
88
87
  end
88
+
89
89
  def self.external_to_unicodecr_vodafone(str)
90
90
  external_to_unicodecr_softbank(str)
91
91
  end
@@ -103,7 +103,7 @@ module Jpmobile
103
103
  when GETA_CODE
104
104
  GETA
105
105
  when Integer
106
- "&#x%04x;" % emoticon
106
+ '&#x%04x;' % emoticon
107
107
  when String
108
108
  emoticon
109
109
  end
@@ -120,15 +120,14 @@ module Jpmobile
120
120
  unicodes = match.unpack('U*')
121
121
  unicodes = unicodes.first if unicodes.size == 1
122
122
 
123
- if emoticon = GOOGLE_EMOTICON_TO_CARRIER_EMOTICON[unicodes]
124
- case emoticon
125
- when GETA_CODE
126
- GETA
127
- when Integer
128
- "&#x%04x;" % emoticon
129
- when String
130
- emoticon
131
- end
123
+ emoticon = GOOGLE_EMOTICON_TO_CARRIER_EMOTICON[unicodes]
124
+ case emoticon
125
+ when GETA_CODE
126
+ GETA
127
+ when Integer
128
+ '&#x%04x;' % emoticon
129
+ when String
130
+ emoticon
132
131
  else
133
132
  # 変換できなければ〓に
134
133
  GETA
@@ -143,32 +142,33 @@ module Jpmobile
143
142
  #
144
143
  # 携帯側エンコーディングがShift_JIS場合は +to_sjis+ に +true+ を指定する。
145
144
  # +true+ を指定すると変換テーブルに文字列が指定されている場合にShift_JISで出力される。
146
- def self.unicodecr_to_external(str, conversion_table=nil, to_sjis=true)
145
+ def self.unicodecr_to_external(str, conversion_table = nil, to_sjis = true)
147
146
  str.gsub(/&#x([0-9a-f]{4});/i) do |match|
148
- unicode = $1.scanf("%x").first
147
+ unicode = Regexp.last_match(1).scanf('%x').first
149
148
 
150
- if conversion_table
151
- converted = conversion_table[unicode] # キャリア間変換
152
- else
153
- converted = unicode # 変換しない
154
- end
149
+ converted = if conversion_table
150
+ conversion_table[unicode] # キャリア間変換
151
+ else
152
+ unicode # 変換しない
153
+ end
155
154
 
156
155
  # 携帯側エンコーディングに変換する
157
156
  case converted
158
157
  when Integer
159
158
  # 変換先がUnicodeで指定されている。つまり対応する絵文字がある。
160
- if sjis = UNICODE_TO_SJIS[converted]
159
+ sjis = UNICODE_TO_SJIS[converted]
160
+ if sjis
161
161
  if to_sjis
162
162
  Jpmobile::Util.sjis([sjis].pack('n'))
163
163
  else
164
- [converted].pack("U")
164
+ [converted].pack('U')
165
165
  end
166
- elsif SOFTBANK_UNICODE_TO_WEBCODE[converted-0x1000]
167
- [converted-0x1000].pack('U')
166
+ elsif SOFTBANK_UNICODE_TO_WEBCODE[converted - 0x1000]
167
+ [converted - 0x1000].pack('U')
168
168
  elsif converted == GETA_CODE
169
169
  # PCで〓を表示する場合
170
170
  GETA
171
- elsif UNICODE_EMOTICONS.include?(converted) or GOOGLE_EMOTICONS.include?(converted)
171
+ elsif UNICODE_EMOTICONS.include?(converted) || GOOGLE_EMOTICONS.include?(converted)
172
172
  if unicode == GETA_CODE
173
173
  GETA
174
174
  else
@@ -181,7 +181,7 @@ module Jpmobile
181
181
  end
182
182
  when String
183
183
  # 変換先が数値参照だと、再変換する
184
- if converted.match(/&#x([0-9a-f]{4});/i)
184
+ if converted =~ /&#x([0-9a-f]{4});/i
185
185
  self.unicodecr_to_external(converted, conversion_table, to_sjis)
186
186
  else
187
187
  # 変換先が文字列で指定されている。
@@ -193,21 +193,23 @@ module Jpmobile
193
193
  end
194
194
  end
195
195
  end
196
+
196
197
  # +str+ のなかでUnicode数値文字参照で表記された絵文字をUTF-8に置換する。
197
198
  def self.unicodecr_to_utf8(str)
198
199
  str.gsub(/&#x([0-9a-f]{4});/i) do |match|
199
- unicode = $1.scanf("%x").first
200
- if UNICODE_TO_SJIS[unicode] || SOFTBANK_UNICODE_TO_WEBCODE[unicode-0x1000]
200
+ unicode = Regexp.last_match(1).scanf('%x').first
201
+ if UNICODE_TO_SJIS[unicode] || SOFTBANK_UNICODE_TO_WEBCODE[unicode - 0x1000]
201
202
  [unicode].pack('U')
202
203
  else
203
204
  match
204
205
  end
205
206
  end
206
207
  end
208
+
207
209
  # +str+ のなかでUTF-8で表記された絵文字をUnicode数値文字参照に置換する。
208
210
  def self.utf8_to_unicodecr(str)
209
211
  str.gsub(UTF8_REGEXP) do |match|
210
- "&#x%04x;" % match.unpack('U').first
212
+ '&#x%04x;' % match.unpack('U').first
211
213
  end
212
214
  end
213
215
 
@@ -215,17 +217,19 @@ module Jpmobile
215
217
  # au 専用
216
218
  def self.unicodecr_to_au_email(in_str)
217
219
  str = Jpmobile::Util.ascii_8bit(in_str)
218
- regexp = Regexp.compile(Jpmobile::Util.ascii_8bit("&#x([0-9a-f]{4});"), Regexp::IGNORECASE)
220
+ regexp = Regexp.compile(Jpmobile::Util.ascii_8bit('&#x([0-9a-f]{4});'), Regexp::IGNORECASE)
219
221
  str = str.gsub(regexp) do |match|
220
- unicode = $1.scanf("%x").first
222
+ unicode = Regexp.last_match(1).scanf('%x').first
221
223
  converted = CONVERSION_TABLE_TO_AU[unicode]
222
224
 
223
225
  # メール用エンコーディングに変換する
224
226
  case converted
225
227
  when Integer
226
- if sjis = UNICODE_TO_SJIS[converted]
227
- if email_jis = SJIS_TO_EMAIL_JIS[sjis]
228
- Jpmobile::Util.ascii_8bit("\x1b\x24\x42#{[email_jis].pack('n')}\x1b\x28\x42")
228
+ sjis = UNICODE_TO_SJIS[converted]
229
+ if sjis
230
+ email_jis = SJIS_TO_EMAIL_JIS[sjis]
231
+ if email_jis
232
+ Jpmobile::Util.ascii_8bit("\x1b\x24\x42#{[email_jis].pack("n")}\x1b\x28\x42")
229
233
  else
230
234
  Jpmobile::Util.ascii_8bit([sjis].pack('n'))
231
235
  end
@@ -247,13 +251,14 @@ module Jpmobile
247
251
  # softbank 専用
248
252
  def self.unicodecr_to_softbank_email(str)
249
253
  str.gsub(/&#x([0-9a-f]{4});/i) do |match|
250
- unicode = $1.scanf("%x").first
254
+ unicode = Regexp.last_match(1).scanf('%x').first
251
255
  converted = CONVERSION_TABLE_TO_SOFTBANK[unicode]
252
256
 
253
257
  # メール用エンコーディングに変換する
254
258
  case converted
255
259
  when Integer
256
- if sjis = SOFTBANK_UNICODE_TO_SJIS[converted-0x1000]
260
+ sjis = SOFTBANK_UNICODE_TO_SJIS[converted - 0x1000]
261
+ if sjis
257
262
  Jpmobile::Util.sjis([sjis].pack('n'))
258
263
  else
259
264
  match
@@ -267,53 +272,57 @@ module Jpmobile
267
272
  end
268
273
  end
269
274
 
270
- @@pc_emoticon_image_path = nil
271
- @@pc_emoticon_yaml = nil
272
- @@pc_emoticon_hash = nil
273
-
274
275
  def self.pc_emoticon_image_path
275
- @@pc_emoticon_image_path
276
+ @pc_emoticon_image_path
276
277
  end
278
+
277
279
  def self.pc_emoticon_image_path=(path)
278
- @@pc_emoticon_image_path=(path)
280
+ @pc_emoticon_image_path = path
279
281
  end
280
282
 
281
283
  def self.pc_emoticon_yaml=(file)
282
- @@pc_emoticon_yaml = file
284
+ @pc_emoticon_yaml = file
283
285
  end
286
+
284
287
  def self.pc_emoticon_yaml
285
- @@pc_emoticon_yaml
288
+ @pc_emoticon_yaml
286
289
  end
287
290
 
288
291
  def self.pc_emoticon?
289
- if @@pc_emoticon_yaml and File.exist?(@@pc_emoticon_yaml) and @@pc_emoticon_image_path
292
+ if @pc_emoticon_yaml && File.exist?(@pc_emoticon_yaml) && @pc_emoticon_image_path
293
+ return true if @pc_emoticon_hash
290
294
 
291
- unless @@pc_emoticon_hash
292
- begin
293
- yaml_hash = YAML.load_file(@@pc_emoticon_yaml)
294
- @@pc_emoticon_hash = Hash[*(yaml_hash.values.inject([]){ |r, v| r += v.to_a.flatten; r})]
295
- @@pc_emoticon_image_path.chop if @@pc_emoticon_image_path.match(/\/$/)
295
+ begin
296
+ yaml_hash = YAML.load_file(@pc_emoticon_yaml)
297
+ @pc_emoticon_hash = Hash[*(yaml_hash.values.inject([]) { |r, v| r += v.to_a.flatten; r })]
298
+ @pc_emoticon_image_path.chop if @pc_emoticon_image_path =~ %r{/$}
296
299
 
297
- return true
298
- rescue
299
- end
300
- else
301
300
  return true
301
+ rescue
302
302
  end
303
303
  end
304
304
 
305
- return false
305
+ false
306
306
  end
307
307
 
308
308
  def self.emoticons_to_image(str)
309
- if @@pc_emoticon_hash
310
- utf8_to_unicodecr(str).gsub(/&#x([0-9a-f]{4});/i) do |match|
311
- img = @@pc_emoticon_hash[$1.upcase] || (@@pc_emoticon_hash[("%x" % ($1.scanf("%x").first - 0x1000)).upcase] rescue nil)
312
- if img
313
- "<img src=\"#{@@pc_emoticon_image_path}/#{img}.gif\" alt=\"#{img}\" />"
314
- else
315
- ""
316
- end
309
+ return str unless @pc_emoticon_hash
310
+
311
+ utf8_to_unicodecr(str).gsub(/&#x([0-9a-f]{4});/i) do
312
+ img = @pc_emoticon_hash[Regexp.last_match(1).upcase]
313
+ unless img
314
+ img =
315
+ begin
316
+ @pc_emoticon_hash[('%x' % (Regexp.last_match(1).scanf('%x').first - 0x1000)).upcase]
317
+ rescue
318
+ nil
319
+ end
320
+ end
321
+
322
+ if img
323
+ "<img src=\"#{@pc_emoticon_image_path}/#{img}.gif\" alt=\"#{img}\" />"
324
+ else
325
+ ''
317
326
  end
318
327
  end
319
328
  end