Class: EasyUpnp::ArgumentValidator
- Inherits:
-
Object
- Object
- EasyUpnp::ArgumentValidator
show all
- Defined in:
- lib/easy_upnp/control_point/argument_validator.rb
Defined Under Namespace
Classes: AllowedValueValidator, Builder, RangeValidator, TypeValidator
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of ArgumentValidator.
96
97
98
|
# File 'lib/easy_upnp/control_point/argument_validator.rb', line 96
def initialize(validators)
@validators = validators
end
|
Class Method Details
.build(&block) ⇒ Object
121
122
123
|
# File 'lib/easy_upnp/control_point/argument_validator.rb', line 121
def self.build(&block)
Builder.new(&block).build
end
|
.from_xml(xml) ⇒ Object
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
# File 'lib/easy_upnp/control_point/argument_validator.rb', line 129
def self.from_xml(xml)
build do |v|
v.type(xml.xpath('dataType').text)
if (range = xml.xpath('allowedValueRange')).any?
min = range.xpath('minimum').text
max = range.xpath('maximum').text
step = range.xpath('step')
step = step.any? ? step.text : 1
v.in_range(min.to_i, max.to_i, step.to_i)
end
if (list = xml.xpath('allowedValueList')).any?
allowed_values = list.xpath('allowedValue').map { |x| x.text }
v.allowed_values(*allowed_values)
end
end
end
|
.no_op ⇒ Object
125
126
127
|
# File 'lib/easy_upnp/control_point/argument_validator.rb', line 125
def self.no_op
build
end
|
Instance Method Details
#allowed_values ⇒ Object
111
112
113
114
|
# File 'lib/easy_upnp/control_point/argument_validator.rb', line 111
def allowed_values
return nil unless @validators[AllowedValueValidator]
@validators[AllowedValueValidator].allowed_values
end
|
#required_class ⇒ Object
105
106
107
108
109
|
# File 'lib/easy_upnp/control_point/argument_validator.rb', line 105
def required_class
return nil unless @validators[TypeValidator]
c = @validators[TypeValidator].valid_classes
c.size == 1 ? c.first : c
end
|
#valid_range ⇒ Object
116
117
118
119
|
# File 'lib/easy_upnp/control_point/argument_validator.rb', line 116
def valid_range
return nil unless @validators[RangeValidator]
@validators[RangeValidator].range
end
|
#validate(value) ⇒ Object
100
101
102
103
|
# File 'lib/easy_upnp/control_point/argument_validator.rb', line 100
def validate(value)
@validators.each { |_, v| v.validate(value) }
true
end
|