Class: Paypal::Api::Parameter

Inherits:
Object
  • Object
show all
Defined in:
lib/paypal_api/support/parameter.rb

Direct Known Subclasses

Coerce, Default, Enum, Hash, Optional, Sequential

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Parameter

Returns a new instance of Parameter.



9
10
11
# File 'lib/paypal_api/support/parameter.rb', line 9

def initialize(value)
	@value = value
end

Instance Attribute Details

#valueObject

Returns the value of attribute value.



7
8
9
# File 'lib/paypal_api/support/parameter.rb', line 7

def value
  @value
end

Instance Method Details

#parameter_parse(val) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/paypal_api/support/parameter.rb', line 18

def parameter_parse(val)
	if @parameter.class == Class
		if val.class == @parameter
			return val
		else
			raise Paypal::InvalidParameter, "'#{val}'' is not of type #{@parameter.class}"
		end
	elsif @parameter.class == Regexp
		match = @parameter.match(val)
		if match
			return match[0]
		else
			raise Paypal::InvalidParameter, "'#{val}' does not match #{@parameter}"
		end
	elsif @parameter.class < Parameter
		return @parameter.parse(val)
	else
		raise Paypal::InvalidParameter, "#{@parameter.class} is an invalid parameter specification"
	end
end

#parse(anything) ⇒ Object



13
14
15
16
# File 'lib/paypal_api/support/parameter.rb', line 13

def parse(anything)
	@value = anything
	return @value
end