Class: Trenni::Query::Delegate

Inherits:
Object
  • Object
show all
Defined in:
lib/trenni/query.rb

Instance Method Summary collapse

Constructor Details

#initialize(top = {}) ⇒ Delegate

Returns a new instance of Delegate.



34
35
36
37
38
39
# File 'lib/trenni/query.rb', line 34

def initialize(top = {})
	@top = top
	
	@current = @top
	@index = nil
end

Instance Method Details

#appendObject



63
64
65
66
67
68
69
70
71
# File 'lib/trenni/query.rb', line 63

def append
	if @index
		@current = @current.fetch(@index) do
			@current[@index] = []
		end
	end
	
	@index = @current.size
end

#assign(value, encoded) ⇒ Object



73
74
75
76
77
78
79
80
81
82
# File 'lib/trenni/query.rb', line 73

def assign(value, encoded)
	if encoded
		value = ::URI.decode_www_form_component(value)
	end
	
	@current[@index] = value
	
	@current = @top
	@index = nil
end

#index(key) ⇒ Object



53
54
55
56
57
58
59
60
61
# File 'lib/trenni/query.rb', line 53

def index(key)
	if @index
		@current = @current.fetch(@index) do
			@current[@index] = {}
		end
	end
	
	@index = key
end

#integer(key) ⇒ Object



49
50
51
# File 'lib/trenni/query.rb', line 49

def integer(key)
	index(key.to_i)
end

#pairObject



84
85
86
87
88
89
90
91
# File 'lib/trenni/query.rb', line 84

def pair
	if @index
		@current[@index] = true
	end
	
	@current = @top
	@index = nil
end

#string(key, encoded) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/trenni/query.rb', line 41

def string(key, encoded)
	if encoded
		key = ::URI.decode_www_form_component(key)
	end
	
	index(key.to_sym)
end