Class: Jpmobile::Filter::Sjis

Inherits:
Base
  • Object
show all
Defined in:
lib/jpmobile/filter.rb

Overview

Shift_JISとUnicodeのフィルタ(NKFを使用)

Instance Method Summary (collapse)

Methods inherited from Base

#after, #before

Instance Method Details

- (Object) after_after(controller)

afterfilterを実行した後に実行する。



70
71
72
73
74
75
76
# File 'lib/jpmobile/filter.rb', line 70

def after_after(controller)
  unless controller.response.body.blank?
    # 500.htmlなどをUTF-8で書いたとき、docomoで文字化けするのを防ぐため
    # response_bodyが空の場合はShift_JISを指定しない
    controller.response.charset = "Shift_JIS"
  end
end

- (Boolean) apply_incoming?(controller)

to_internalを適用するべきかどうかを返す。

Returns:

  • (Boolean)


78
79
80
81
82
83
# File 'lib/jpmobile/filter.rb', line 78

def apply_incoming?(controller)
  # Vodafone 3G/Softbank(Shift-JISにすると絵文字で不具合が生じる)以外の
  # 携帯電話の場合に適用する。
  mobile = controller.request.mobile
  mobile && !(mobile.instance_of?(Jpmobile::Mobile::Vodafone)||mobile.instance_of?(Jpmobile::Mobile::Softbank))
end

- (Boolean) apply_outgoing?(controller)

Returns:

  • (Boolean)


84
85
86
87
# File 'lib/jpmobile/filter.rb', line 84

def apply_outgoing?(controller)
  [nil, "text/html", "application/xhtml+xml"].include?(controller.response.content_type) &&
    apply_incoming?(controller)
end

- (Object) to_external(str, controller)

UTF-8からShift_JISに変換する。



62
63
64
# File 'lib/jpmobile/filter.rb', line 62

def to_external(str, controller)
  NKF.nkf('-m0 -x -Ws', str)
end

- (Object) to_internal(str, controller)

Shift_JISからUTF-8に変換する。



66
67
68
# File 'lib/jpmobile/filter.rb', line 66

def to_internal(str, controller)
  NKF.nkf('-m0 -x -Sw', str)
end