class Jpmobile::Mobile::AbstractMobile

携帯電話の抽象クラス。

Constants

MAIL_ADDRESS_REGEXP

対応するメールアドレスの正規表現

MAIL_CHARSET

メールのデフォルトのcharset

MAIL_CONTENT_TRANSFER_ENCODING

テキスト部分の content-transfer-encoding

USER_AGENT_REGEXP

対応するuser-agentの正規表現

Attributes

decorated[W]

Public Class Methods

add_user_agent_regexp(regexp) click to toggle source
# File lib/jpmobile/mobile/abstract_mobile.rb, line 228
def add_user_agent_regexp(regexp)
  @_user_agent_regexp = Regexp.union(user_agent_regexp, regexp)
end
carrier(env) click to toggle source
# File lib/jpmobile/mobile/abstract_mobile.rb, line 232
def carrier(env)
  ::Jpmobile::Mobile.carriers.each do |const|
    c = ::Jpmobile::Mobile.const_get(const)
    if c.check_carrier(env)
      res = ::Rack::Request.new(env)
      return c.new(env, res)
    end
  end

  nil
end
check_carrier(env) click to toggle source

リクエストがこのクラスに属するか調べる メソッド名に関して非常に不安

# File lib/jpmobile/mobile/abstract_mobile.rb, line 220
def check_carrier(env)
  user_agent_regexp && user_agent_regexp.match(env['HTTP_USER_AGENT'])
end
ip_address_class() click to toggle source
# File lib/jpmobile/mobile/abstract_mobile.rb, line 244
def ip_address_class
  Object.const_get("::Jpmobile::Mobile::IpAddresses::#{self.to_s.split(/::/).last}").new
rescue
  nil
end
new(env, request) click to toggle source
# File lib/jpmobile/mobile/abstract_mobile.rb, line 16
def initialize(env, request)
  @env            = env
  @request        = request
  @_variants      = nil
  @_mail_variants = nil
  @decorated      = nil
end
user_agent_regexp() click to toggle source
# File lib/jpmobile/mobile/abstract_mobile.rb, line 224
def user_agent_regexp
  @_user_agent_regexp ||= self::USER_AGENT_REGEXP
end
valid_ip?(remote_addr) click to toggle source

当該キャリアのIPアドレス帯域からのアクセスであれば true を返す。 そうでなければ false を返す。 IP空間が定義されていない場合は nil を返す。

# File lib/jpmobile/mobile/abstract_mobile.rb, line 211
def valid_ip?(remote_addr)
  @ip_list ||= ip_address_class
  return false unless @ip_list

  @ip_list.valid_ip?(remote_addr)
end

Public Instance Methods

apply_filter?() click to toggle source

Jpmobile::Filter を適用するかどうか

# File lib/jpmobile/mobile/abstract_mobile.rb, line 71
def apply_filter?
  true
end
apply_params_filter?() click to toggle source

Jpmobile::ParamsFilter を適用するかどうか

# File lib/jpmobile/mobile/abstract_mobile.rb, line 76
def apply_params_filter?
  true
end
content_transfer_encoding(headers) click to toggle source
# File lib/jpmobile/mobile/abstract_mobile.rb, line 142
def content_transfer_encoding(headers)
  transfer_encoding = headers['Content-Transfer-Encoding']
  case headers['Content-Type'].to_s
  when %r{text/plain}
    (transfer_encoding.to_s == MAIL_CONTENT_TRANSFER_ENCODING) ? transfer_encoding : MAIL_CONTENT_TRANSFER_ENCODING
  when %r{text/html}
    if self.decorated?
      'quoted-printable'
    else
      (transfer_encoding.to_s == MAIL_CONTENT_TRANSFER_ENCODING) ? transfer_encoding : MAIL_CONTENT_TRANSFER_ENCODING
    end
  else
    transfer_encoding
  end
end
decode_transfer_encoding(body, charset) click to toggle source
# File lib/jpmobile/mobile/abstract_mobile.rb, line 187
def decode_transfer_encoding(body, charset)
  body = Jpmobile::Util.set_encoding(body, charset)
  body = to_mail_internal(body, nil)
  Jpmobile::Util.force_encode(body, charset, Jpmobile::Util::UTF8)
end
decoratable?() click to toggle source
# File lib/jpmobile/mobile/abstract_mobile.rb, line 193
def decoratable?
  false
end
decorated?() click to toggle source
# File lib/jpmobile/mobile/abstract_mobile.rb, line 203
def decorated?
  @decorated
end
default_charset() click to toggle source
# File lib/jpmobile/mobile/abstract_mobile.rb, line 89
def default_charset
  'UTF-8'
end
display() click to toggle source

画面情報を Display クラスのインスタンスで返す。

# File lib/jpmobile/mobile/abstract_mobile.rb, line 49
def display
  @__displlay ||= Jpmobile::Mobile::Terminfo.new(self, @env)
rescue LoadError
  puts 'display method require jpmobile-terminfo plugin.'
end
ident() click to toggle source

契約者又は端末を識別する文字列があれば返す。

# File lib/jpmobile/mobile/abstract_mobile.rb, line 30
def ident
  ident_subscriber || ident_device
end
ident_device() click to toggle source

端末を識別する文字列があれば返す。

# File lib/jpmobile/mobile/abstract_mobile.rb, line 40
def ident_device
  nil
end
ident_subscriber() click to toggle source

契約者を識別する文字列があれば返す。

# File lib/jpmobile/mobile/abstract_mobile.rb, line 35
def ident_subscriber
  nil
end
mail_charset(charset = nil) click to toggle source
# File lib/jpmobile/mobile/abstract_mobile.rb, line 136
def mail_charset(charset = nil)
  # (charset.nil? or charset == "") ? self.class::MAIL_CHARSET : charset
  # self.class::MAIL_CHARSET
  (charset.nil? || charset == '' || charset =~ /US-ASCII/i) ? self.class::MAIL_CHARSET : charset
end
mail_variants() click to toggle source
# File lib/jpmobile/mobile/abstract_mobile.rb, line 119
def mail_variants
  return @_mail_variants if @_mail_variants

  @_mail_variants = (variants == ['mobile']) ? [] : variants
end
position() click to toggle source

緯度経度があれば Position のインスタンスを返す。

# File lib/jpmobile/mobile/abstract_mobile.rb, line 25
def position
  nil
end
smart_phone?() click to toggle source

smartphone かどうか

# File lib/jpmobile/mobile/abstract_mobile.rb, line 61
def smart_phone?
  false
end
tablet?() click to toggle source

tablet かどうか

# File lib/jpmobile/mobile/abstract_mobile.rb, line 66
def tablet?
  false
end
to_external(str, content_type, charset) click to toggle source
# File lib/jpmobile/mobile/abstract_mobile.rb, line 85
def to_external(str, content_type, charset)
  [str, charset]
end
to_internal(str) click to toggle source

エンコーディング変換用

# File lib/jpmobile/mobile/abstract_mobile.rb, line 81
def to_internal(str)
  str
end
to_mail_body(str) click to toggle source
# File lib/jpmobile/mobile/abstract_mobile.rb, line 132
def to_mail_body(str)
  to_mail_encoding(str)
end
to_mail_body_encoded?(str) click to toggle source
# File lib/jpmobile/mobile/abstract_mobile.rb, line 183
def to_mail_body_encoded?(str)
  Jpmobile::Util.jis?(str)
end
to_mail_encoding(str) click to toggle source
# File lib/jpmobile/mobile/abstract_mobile.rb, line 158
def to_mail_encoding(str)
  str = Jpmobile::Emoticon.utf8_to_unicodecr(str)
  str = Jpmobile::Emoticon.unicodecr_to_external(str, Jpmobile::Emoticon::CONVERSION_TABLE_TO_PC_EMAIL, false)
  Jpmobile::Util.encode(str, mail_charset)
end
to_mail_internal(str, charset) click to toggle source
# File lib/jpmobile/mobile/abstract_mobile.rb, line 175
def to_mail_internal(str, charset)
  str
end
to_mail_subject(str) click to toggle source

メール送信用

# File lib/jpmobile/mobile/abstract_mobile.rb, line 126
def to_mail_subject(str)
  Jpmobile::Util.fold_text(Jpmobile::Emoticon.unicodecr_to_utf8(str)).
    map {|text| "=?#{mail_charset}?B?" + [to_mail_encoding(text)].pack('m').delete("\n") + '?=' }.
    join("\n\s")
end
to_mail_subject_encoded?(str) click to toggle source
# File lib/jpmobile/mobile/abstract_mobile.rb, line 179
def to_mail_subject_encoded?(str)
  str.match(/=\?#{mail_charset}\?B.+\?=/i)
end
utf8_to_mail_encode(str) click to toggle source
# File lib/jpmobile/mobile/abstract_mobile.rb, line 164
def utf8_to_mail_encode(str)
  case mail_charset
  when /ISO-2022-JP/i
    Jpmobile::Util.utf8_to_jis(str)
  when /Shift_JIS/i
    Jpmobile::Util.utf8_to_sjis(str)
  else
    str
  end
end
valid_ip?() click to toggle source
# File lib/jpmobile/mobile/abstract_mobile.rb, line 44
def valid_ip?
  @__valid_ip ||= self.class.valid_ip? @request.ip
end
variants() click to toggle source

for view selector

# File lib/jpmobile/mobile/abstract_mobile.rb, line 94
def variants
  return @_variants if @_variants

  @_variants = self.class.ancestors.select {|c| c.to_s =~ /^Jpmobile/ && c.to_s !~ /Emoticon/ }.map do |klass|
    klass = klass.to_s.
              gsub(/Jpmobile::/, '').
              gsub(/AbstractMobile::/, '').
              gsub(/Mobile::SmartPhone/, 'smart_phone').
              gsub(/Mobile::Tablet/, 'tablet').
              gsub(/::/, '_').
              gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
              gsub(/([a-z\d])([A-Z])/, '\1_\2').
              downcase
    (klass =~ /abstract/) ? 'mobile' : klass
  end

  if @_variants.include?('tablet')
    @_variants = @_variants.reject {|v| v == 'mobile' }.map {|v| v.gsub(/mobile_/, 'tablet_') }
  elsif @_variants.include?('smart_phone')
    @_variants = @_variants.reject {|v| v == 'mobile' }.map {|v| v.gsub(/mobile_/, 'smart_phone_') }
  end

  @_variants || []
end

Private Instance Methods

params() click to toggle source

リクエストのパラメータ。

# File lib/jpmobile/mobile/abstract_mobile.rb, line 264
def params
  if @request.respond_to? :parameters
    @request.parameters
  else
    @request.params
  end
end