class Jpmobile::Mobile::AbstractMobile

携帯電話の抽象クラス。

Constants

MAIL_ADDRESS_REGEXP

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

MAIL_CHARSET

メールのデフォルトのcharset

MAIL_CONTENT_TRANSFER_ENCODING

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

USER_AGENT_REGEXP

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

Public Instance Methods

apply_filter?() click to toggle source

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

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

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

# File lib/jpmobile/mobile/abstract_mobile.rb, line 63
def apply_params_filter?
  true
end
content_transfer_encoding(headers) click to toggle source
# File lib/jpmobile/mobile/abstract_mobile.rb, line 123
def content_transfer_encoding(headers)
  transfer_encoding = headers['Content-Transfer-Encoding']
  case headers['Content-Type'].to_s
  when %rtext\/plain/
    transfer_encoding.to_s == MAIL_CONTENT_TRANSFER_ENCODING ? transfer_encoding : MAIL_CONTENT_TRANSFER_ENCODING
  when %rtext\/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 162
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 167
def decoratable?
  false
end
decorated=(boolean) click to toggle source
# File lib/jpmobile/mobile/abstract_mobile.rb, line 173
def decorated=(boolean)
  @decorated = boolean
end
decorated?() click to toggle source
# File lib/jpmobile/mobile/abstract_mobile.rb, line 176
def decorated?
  @decorated
end
default_charset() click to toggle source
# File lib/jpmobile/mobile/abstract_mobile.rb, line 74
def default_charset
  "UTF-8"
end
display() click to toggle source

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

# File lib/jpmobile/mobile/abstract_mobile.rb, line 36
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 25
def ident; ident_subscriber || ident_device; end
ident_device() click to toggle source

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

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

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

# File lib/jpmobile/mobile/abstract_mobile.rb, line 27
def ident_subscriber; nil; end
mail_charset(charset = nil) click to toggle source
# File lib/jpmobile/mobile/abstract_mobile.rb, line 118
def mail_charset(charset = nil)
  # (charset.nil? or charset == "") ? self.class::MAIL_CHARSET : charset
  # self.class::MAIL_CHARSET
  charset.nil? || charset == '' || charset =~ %rUS-ASCII/ ? self.class::MAIL_CHARSET : charset
end
mail_variants() click to toggle source
# File lib/jpmobile/mobile/abstract_mobile.rb, line 103
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 22
def position; return nil; end
smart_phone?() click to toggle source

smartphone かどうか

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

tablet かどうか

# File lib/jpmobile/mobile/abstract_mobile.rb, line 53
def tablet?
  false
end
to_external(str, content_type, charset) click to toggle source
# File lib/jpmobile/mobile/abstract_mobile.rb, line 71
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 68
def to_internal(str)
  str
end
to_mail_body(str) click to toggle source
# File lib/jpmobile/mobile/abstract_mobile.rb, line 115
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 159
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 138
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 153
def to_mail_internal(str, charset)
  str
end
to_mail_subject(str) click to toggle source

メール送信用

# File lib/jpmobile/mobile/abstract_mobile.rb, line 110
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').gsub(%r\n/, '') + "?=" }.
    join("\n\s")
end
to_mail_subject_encoded?(str) click to toggle source
# File lib/jpmobile/mobile/abstract_mobile.rb, line 156
def to_mail_subject_encoded?(str)
  str.match(%r\=\?#{mail_charset}\?B.+\?\=/)
end
utf8_to_mail_encode(str) click to toggle source
# File lib/jpmobile/mobile/abstract_mobile.rb, line 143
def utf8_to_mail_encode(str)
  case mail_charset
  when %rISO-2022-JP/
    Jpmobile::Util.utf8_to_jis(str)
  when %rShift_JIS/
    Jpmobile::Util.utf8_to_sjis(str)
  else
    str
  end
end
valid_ip?() click to toggle source
# File lib/jpmobile/mobile/abstract_mobile.rb, line 31
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 79
def variants
  return @_variants if @_variants

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

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

  @_variants || []
end

Public Class Methods

add_user_agent_regexp(regexp) click to toggle source
# File lib/jpmobile/mobile/abstract_mobile.rb, line 201
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 205
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 193
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 218
def ip_address_class
  eval("::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 9
def initialize(env, request)
  @env     = env
  @request = request
end
user_agent_regexp() click to toggle source
# File lib/jpmobile/mobile/abstract_mobile.rb, line 197
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 184
def valid_ip? remote_addr
  @ip_list ||= ip_address_class
  return false unless @ip_list

  @ip_list.valid_ip?(remote_addr)
end