携帯電話の抽象クラス。
対応するメールアドレスの正規表現
メールのデフォルトのcharset
テキスト部分の content-transfer-encoding
対応するuser-agentの正規表現
# File lib/jpmobile/mobile/abstract_mobile.rb, line 192 def self.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
リクエストがこのクラスに属するか調べる メソッド名に関して非常に不安
# File lib/jpmobile/mobile/abstract_mobile.rb, line 178 def self.check_carrier(env) self::USER_AGENT_REGEXP && env['HTTP_USER_AGENT'] =~ self::USER_AGENT_REGEXP end
# File lib/jpmobile/mobile/abstract_mobile.rb, line 9 def initialize(env, request) @env = env @request = request end
当該キャリアのIPアドレス帯域からのアクセスであれば
true
を返す。 そうでなければ false
を返す。 IP空間が定義されていない場合は nil
を返す。
# File lib/jpmobile/mobile/abstract_mobile.rb, line 34 def self.valid_ip? remote_addr @ip_list ||= ip_address_class return false unless @ip_list @ip_list.valid_ip?(remote_addr) end
Jpmobile::Rack::Filter を適用するかどうか
# File lib/jpmobile/mobile/abstract_mobile.rb, line 63 def apply_filter? true end
Jpmobile::Rack::ParamsFilter を適用するかどうか
# File lib/jpmobile/mobile/abstract_mobile.rb, line 68 def apply_params_filter? true end
# File lib/jpmobile/mobile/abstract_mobile.rb, line 119 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
# File lib/jpmobile/mobile/abstract_mobile.rb, line 158 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
# File lib/jpmobile/mobile/abstract_mobile.rb, line 163 def decoratable? false end
# File lib/jpmobile/mobile/abstract_mobile.rb, line 169 def decorated=(boolean) @decorated = boolean end
# File lib/jpmobile/mobile/abstract_mobile.rb, line 172 def decorated? @decorated end
# File lib/jpmobile/mobile/abstract_mobile.rb, line 79 def default_charset "UTF-8" end
画面情報を Display
クラスのインスタンスで返す。
# File lib/jpmobile/mobile/abstract_mobile.rb, line 46 def display @__displlay ||= Jpmobile::Mobile::Terminfo.new(self, @env) rescue LoadError puts "display method require jpmobile-terminfo plugin." end
契約者又は端末を識別する文字列があれば返す。
# File lib/jpmobile/mobile/abstract_mobile.rb, line 25 def ident; ident_subscriber || ident_device; end
端末を識別する文字列があれば返す。
# File lib/jpmobile/mobile/abstract_mobile.rb, line 29 def ident_device; nil; end
契約者を識別する文字列があれば返す。
# File lib/jpmobile/mobile/abstract_mobile.rb, line 27 def ident_subscriber; nil; end
# File lib/jpmobile/mobile/abstract_mobile.rb, line 115 def mail_charset(charset = nil) # (charset.nil? or charset == "") ? self.class::MAIL_CHARSET : charset self.class::MAIL_CHARSET end
緯度経度があれば Position のインスタンスを返す。
# File lib/jpmobile/mobile/abstract_mobile.rb, line 22 def position; return nil; end
smartphone かどうか
# File lib/jpmobile/mobile/abstract_mobile.rb, line 58 def smart_phone? false end
# File lib/jpmobile/mobile/abstract_mobile.rb, line 76 def to_external(str, content_type, charset) [str, charset] end
エンコーディング変換用
# File lib/jpmobile/mobile/abstract_mobile.rb, line 73 def to_internal(str) str end
# File lib/jpmobile/mobile/abstract_mobile.rb, line 112 def to_mail_body(str) to_mail_encoding(str) end
# File lib/jpmobile/mobile/abstract_mobile.rb, line 155 def to_mail_body_encoded?(str) Jpmobile::Util.jis?(str) end
# File lib/jpmobile/mobile/abstract_mobile.rb, line 134 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
# File lib/jpmobile/mobile/abstract_mobile.rb, line 149 def to_mail_internal(str, charset) str end
メール送信用
# File lib/jpmobile/mobile/abstract_mobile.rb, line 107 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').strip + "?=" }. join("\n\s") end
# File lib/jpmobile/mobile/abstract_mobile.rb, line 152 def to_mail_subject_encoded?(str) str.match(/\=\?#{mail_charset}\?B.+\?\=/) end
# File lib/jpmobile/mobile/abstract_mobile.rb, line 139 def utf8_to_mail_encode(str) case mail_charset when /ISO-2022-JP/ Jpmobile::Util.utf8_to_jis(str) when /Shift_JIS/ Jpmobile::Util.utf8_to_sjis(str) else str end end
# File lib/jpmobile/mobile/abstract_mobile.rb, line 41 def valid_ip? @__valid_ip ||= self.class.valid_ip? @request.ip end
for view selector
# File lib/jpmobile/mobile/abstract_mobile.rb, line 84 def variants return @_variants if @_variants @_variants = self.class.ancestors.select {|c| c.to_s =~ /^Jpmobile/}.map do |klass| klass = klass.to_s. gsub(/Jpmobile::/, ''). gsub(/AbstractMobile::/, ''). gsub(/Mobile::SmartPhone/, 'smart_phone'). 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?("smart_phone") @_variants = @_variants.reject{|v| v == "mobile"}.map{|v| v.gsub(/mobile/, "smart_phone")} end @_variants end