class Jpmobile::Mobile::AbstractMobile
携帯電話の抽象クラス。
Constants
- MAIL_ADDRESS_REGEXP
対応するメールアドレスの正規表現
- MAIL_CHARSET
メールのデフォルトのcharset
- MAIL_CONTENT_TRANSFER_ENCODING
テキスト部分の content-transfer-encoding
- USER_AGENT_REGEXP
対応するuser-agentの正規表現
Public Class Methods
add_user_agent_regexp(regexp)
click to toggle source
# File lib/jpmobile/mobile/abstract_mobile.rb, line 204 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 208 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 196 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 221 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 @_variants = nil @_mail_variants = nil @decorated = nil end
user_agent_regexp()
click to toggle source
# File lib/jpmobile/mobile/abstract_mobile.rb, line 200 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 187 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::Rack::Filter を適用するかどうか
# File lib/jpmobile/mobile/abstract_mobile.rb, line 61 def apply_filter? true end
apply_params_filter?()
click to toggle source
Jpmobile::Rack::ParamsFilter を適用するかどうか
# File lib/jpmobile/mobile/abstract_mobile.rb, line 66 def apply_params_filter? true end
content_transfer_encoding(headers)
click to toggle source
# File lib/jpmobile/mobile/abstract_mobile.rb, line 126 def content_transfer_encoding(headers) transfer_encoding = headers['Content-Transfer-Encoding'] case headers['Content-Type'].to_s when /text\/plain/ transfer_encoding.to_s == MAIL_CONTENT_TRANSFER_ENCODING ? transfer_encoding : MAIL_CONTENT_TRANSFER_ENCODING when /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 165 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 170 def decoratable? false end
decorated=(boolean)
click to toggle source
# File lib/jpmobile/mobile/abstract_mobile.rb, line 176 def decorated=(boolean) @decorated = boolean end
decorated?()
click to toggle source
# File lib/jpmobile/mobile/abstract_mobile.rb, line 179 def decorated? @decorated end
default_charset()
click to toggle source
# File lib/jpmobile/mobile/abstract_mobile.rb, line 77 def default_charset "UTF-8" end
display()
click to toggle source
画面情報を Display
クラスのインスタンスで返す。
# File lib/jpmobile/mobile/abstract_mobile.rb, line 39 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 28 def ident; ident_subscriber || ident_device; end
ident_device()
click to toggle source
端末を識別する文字列があれば返す。
# File lib/jpmobile/mobile/abstract_mobile.rb, line 32 def ident_device; nil; end
ident_subscriber()
click to toggle source
契約者を識別する文字列があれば返す。
# File lib/jpmobile/mobile/abstract_mobile.rb, line 30 def ident_subscriber; nil; end
mail_charset(charset = nil)
click to toggle source
# File lib/jpmobile/mobile/abstract_mobile.rb, line 121 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 106 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; return nil; end
smart_phone?()
click to toggle source
smartphone かどうか
# File lib/jpmobile/mobile/abstract_mobile.rb, line 51 def smart_phone? false end
tablet?()
click to toggle source
tablet かどうか
# File lib/jpmobile/mobile/abstract_mobile.rb, line 56 def tablet? false end
to_external(str, content_type, charset)
click to toggle source
# File lib/jpmobile/mobile/abstract_mobile.rb, line 74 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 71 def to_internal(str) str end
to_mail_body(str)
click to toggle source
# File lib/jpmobile/mobile/abstract_mobile.rb, line 118 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 162 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 141 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 156 def to_mail_internal(str, charset) str end
to_mail_subject(str)
click to toggle source
メール送信用
# File lib/jpmobile/mobile/abstract_mobile.rb, line 113 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(/\n/, '') + "?=" }. join("\n\s") end
to_mail_subject_encoded?(str)
click to toggle source
# File lib/jpmobile/mobile/abstract_mobile.rb, line 159 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 146 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 34 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 82 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 238 def params if @request.respond_to? :parameters @request.parameters else @request.params end end