| Class | FragmentHash |
| In: |
lib/fragment_hash.rb
|
| Parent: | ActiveSupport::OrderedHash |
URL の fragment を構成するためのハッシュクラス。
| DUMMY_MOTION | = | "0".freeze |
# File lib/fragment_hash.rb, line 3
3: def initialize(fragment)
4: @motion = {}
5: @default_params = {}
6: if fragment
7: fragment.scan(/([a-z0-9]+)=([._a-z0-9]+)/) do |key, value|
8: values = value.split(/\./) # restSeparator in application.js
9: @motion[key] = values.shift
10: h = self[key] = {}.with_indifferent_access
11: values.each do |v|
12: k, v = v.split(/_/, 2)
13: h[k] = v
14: end
15: end
16: end
17: end
# File lib/fragment_hash.rb, line 19
19: def [](key)
20: return super(key.to_s) || {}.with_indifferent_access
21: end
既定のパラメータを参照する。
# File lib/fragment_hash.rb, line 31
31: def default_params(view)
32: @default_params[view] ||= {}
33: return @default_params[view]
34: end
fragment を文字列として返す。
# File lib/fragment_hash.rb, line 37
37: def to_fragment
38: parts = []
39: self.each do |view, hash|
40: next if /\A\[/ =~ view
41: a = ["#{view}=#{motion(view)}"]
42: hash.keys.sort.each do |key|
43: a << "#{key}_#{hash[key]}"
44: end
45: parts << a.join(".")
46: end
47: return parts.join(",")
48: end