Class: XRB::Query::Delegate

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

Instance Method Summary collapse

Constructor Details

#initialize(top = {}) ⇒ Delegate

Returns a new instance of Delegate.



20
21
22
23
24
25
# File 'lib/xrb/query.rb', line 20

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

Instance Method Details

#appendObject



49
50
51
52
53
54
55
56
57
# File 'lib/xrb/query.rb', line 49

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

#assign(value, encoded) ⇒ Object



59
60
61
62
63
64
65
66
67
68
# File 'lib/xrb/query.rb', line 59

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



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

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

#integer(key) ⇒ Object



35
36
37
# File 'lib/xrb/query.rb', line 35

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

#pairObject



70
71
72
73
74
75
76
77
# File 'lib/xrb/query.rb', line 70

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

#string(key, encoded) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/xrb/query.rb', line 27

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