Class: SearchYJ::PageSizeAdjuster
- Inherits:
-
Object
- Object
- SearchYJ::PageSizeAdjuster
- Defined in:
- lib/searchyj/page_size_adjuster.rb
Overview
Manage cookie for page
Constant Summary collapse
- SIZE_PATTERN =
[10, 15, 20, 30, 40, 100]
- SIZE_DEFAULT =
- COOKIE_BASE =
'sB="n=<<n>>&nw=-1&fp_ipod=0&fp_pl=0"; ' \ 'path=/; ' \ 'expire=<<expire>>'
- EXPIRE_DELAY =
60 * 60 * 24
Instance Attribute Summary collapse
-
#size ⇒ Object
Returns the value of attribute size.
Instance Method Summary collapse
-
#attach_cookie(hash) ⇒ Hash
Attach the cookie string to the argument if @size has differed from the default value.
-
#initialize ⇒ PageSizeAdjuster
constructor
Initialize myself.
-
#optimize_page_size(size) ⇒ Number
Optimize the number of the page size for searching.
Constructor Details
#initialize ⇒ PageSizeAdjuster
Initialize myself.
20 21 22 23 |
# File 'lib/searchyj/page_size_adjuster.rb', line 20 def initialize @size = SIZE_DEFAULT @expire = Time.now.to_i + EXPIRE_DELAY end |
Instance Attribute Details
#size ⇒ Object
Returns the value of attribute size.
9 10 11 |
# File 'lib/searchyj/page_size_adjuster.rb', line 9 def size @size end |
Instance Method Details
#attach_cookie(hash) ⇒ Hash
Attach the cookie string to the argument if @size has differed from the default value.
46 47 48 49 50 51 52 |
# File 'lib/searchyj/page_size_adjuster.rb', line 46 def (hash) if @size > SIZE_DEFAULT hash['Cookie'] = end hash end |
#optimize_page_size(size) ⇒ Number
Optimize the number of the page size for searching.
33 34 35 36 37 38 39 |
# File 'lib/searchyj/page_size_adjuster.rb', line 33 def optimize_page_size(size) SIZE_PATTERN.reverse_each do |n| return n if size >= n end SIZE_DEFAULT end |