Class: Rack::Ketai::Carrier::Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/ketai/carrier/abstract.rb

Direct Known Subclasses

General, Mobile

Constant Summary collapse

USER_AGENT_REGEXP =
nil

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ Abstract

Returns a new instance of Abstract.



78
79
80
# File 'lib/rack/ketai/carrier/abstract.rb', line 78

def initialize(env)
  @env = env
end

Class Method Details

.filtersObject



61
62
63
# File 'lib/rack/ketai/carrier/abstract.rb', line 61

def filters
  []
end

.valid_addr?(remote_addr) ⇒ Boolean

Returns:

  • (Boolean)


65
66
67
68
69
70
71
72
73
74
# File 'lib/rack/ketai/carrier/abstract.rb', line 65

def valid_addr?(remote_addr)
  cidrs = nil
  begin
    cidrs = self::CIDRS
  rescue NameError
    return nil
  end
  remote = IPAddr.new(remote_addr)
  cidrs.any?{ |cidr| cidr.include?(remote) }
end

.valid_ip?Boolean

Returns:

  • (Boolean)


75
76
77
78
79
80
81
82
83
84
# File 'lib/rack/ketai/carrier/abstract.rb', line 75

def valid_addr?(remote_addr)
  cidrs = nil
  begin
    cidrs = self::CIDRS
  rescue NameError
    return nil
  end
  remote = IPAddr.new(remote_addr)
  cidrs.any?{ |cidr| cidr.include?(remote) }
end

Instance Method Details

#cache_sizeObject

キャッシュサイズ



160
161
162
# File 'lib/rack/ketai/carrier/abstract.rb', line 160

def cache_size
  nil
end

#deviceidObject

デバイスID 端末毎にユニーク



129
130
131
# File 'lib/rack/ketai/carrier/abstract.rb', line 129

def deviceid
  nil
end

#displayObject

ディスプレイ情報



149
150
151
# File 'lib/rack/ketai/carrier/abstract.rb', line 149

def display
  Rack::Ketai::Display.new
end

#featurephone?Boolean

フィーチャーフォンか

Returns:

  • (Boolean)


107
108
109
# File 'lib/rack/ketai/carrier/abstract.rb', line 107

def featurephone?
  false
end

#filtering(env, options = { }, &block) ⇒ Object



88
89
90
91
92
93
# File 'lib/rack/ketai/carrier/abstract.rb', line 88

def filtering(env, options = { }, &block)
  env = options[:disable_filter] ? env : filters(options).inject(env) { |env, filter| filter.inbound(env) }
  ret = block.call(env)
  ret = options[:disable_filter] ? ret : filters(options).reverse.inject(ret) { |r, filter| filter.outbound(*r) }
  ret
end

#filters(options = { }) ⇒ Object



95
96
97
98
99
# File 'lib/rack/ketai/carrier/abstract.rb', line 95

def filters(options = { })
  self.class.filters.collect do |klass|
    klass.new(options)
  end
end

#identObject

識別情報



134
135
136
# File 'lib/rack/ketai/carrier/abstract.rb', line 134

def ident
  subscriberid || deviceid
end

#mobile?Boolean

携帯端末か

Returns:

  • (Boolean)


102
103
104
# File 'lib/rack/ketai/carrier/abstract.rb', line 102

def mobile?
  false
end

#nameObject

機種名(略名)



139
140
141
# File 'lib/rack/ketai/carrier/abstract.rb', line 139

def name
  nil
end

#positionObject

位置情報



144
145
146
# File 'lib/rack/ketai/carrier/abstract.rb', line 144

def position
  nil
end

#requestObject



82
83
84
# File 'lib/rack/ketai/carrier/abstract.rb', line 82

def request
  @request ||= Rack::Request.new(@env)
end

#smartphone?Boolean

スマートフォンか

Returns:

  • (Boolean)


112
113
114
# File 'lib/rack/ketai/carrier/abstract.rb', line 112

def smartphone?
  false
end

#subscriberidObject

サブスクライバID 契約者毎にユニーク



123
124
125
# File 'lib/rack/ketai/carrier/abstract.rb', line 123

def subscriberid
  nil
end

#supports_cookie?Boolean

Cookieのサポート

Returns:

  • (Boolean)


165
166
167
# File 'lib/rack/ketai/carrier/abstract.rb', line 165

def supports_cookie?
  false
end

#tablet?Boolean

タブレットか

Returns:

  • (Boolean)


117
118
119
# File 'lib/rack/ketai/carrier/abstract.rb', line 117

def tablet?
  false
end

#valid_addr?Boolean Also known as: valid_ip?

キャリアのIPアドレス帯を利用しているか

Returns:

  • (Boolean)


154
155
156
# File 'lib/rack/ketai/carrier/abstract.rb', line 154

def valid_addr?
  self.class.valid_ip? @env['HTTP_X_FORWARDED_FOR'] ? @env['HTTP_X_FORWARDED_FOR'].sub(/,.+$/, '') : @env['REMOTE_ADDR']
end