Class: Params::Decoder

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/params/decoder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Base

#clean_params, #crypter?, #crypter_off!, #crypter_on!, #use_crypter?

Constructor Details

#initialize(*args) ⇒ Decoder

Returns a new instance of Decoder.



7
8
9
10
11
12
13
14
15
16
# File 'lib/params/decoder.rb', line 7

def initialize *args
	raise "Decoder needs params to encode" if !args || args.empty?
	args = args.flatten
	options 	= args.last
	if options.kind_of? Hash			
		@crypter 	= options.delete(:crypter) if options				
	end

	@params = args.first
end

Instance Attribute Details

#hashObject (readonly)

Returns the value of attribute hash.



5
6
7
# File 'lib/params/decoder.rb', line 5

def hash
  @hash
end

#paramsObject (readonly)

Returns the value of attribute params.



5
6
7
# File 'lib/params/decoder.rb', line 5

def params
  @params
end

Instance Method Details

#as_clean_hash(mode = :str) ⇒ Object



29
30
31
# File 'lib/params/decoder.rb', line 29

def as_clean_hash mode = :str
	clean_params(as_hash mode)
end

#as_hash(mode = :str) ⇒ Object

fx decoder.as_hash returns value of a



19
20
21
22
23
24
25
26
27
# File 'lib/params/decoder.rb', line 19

def as_hash mode = :str			
	@hash ||= Hash[decoded.split('&').collect{|p| p.split("=")}]
	case mode
	when :sym
		Hash[hash.map{ |k, v| [k.to_sym, v] }]
	else
		hash
	end
end

#decodedObject

decode in reverse order!



34
35
36
# File 'lib/params/decoder.rb', line 34

def decoded
	@decoded ||= use_crypter? ? crypter.decrypt(decoded_params) : decoded_params
end