Class: ApiValidator::Assertion
- Inherits:
-
Object
- Object
- ApiValidator::Assertion
- Defined in:
- lib/api-validator/assertion.rb
Instance Attribute Summary collapse
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(path, value, options = {}) ⇒ Assertion
constructor
A new instance of Assertion.
- #stringified_value ⇒ Object
- #to_hash(options = {}) ⇒ Object
Constructor Details
#initialize(path, value, options = {}) ⇒ Assertion
Returns a new instance of Assertion.
6 7 8 |
# File 'lib/api-validator/assertion.rb', line 6 def initialize(path, value, = {}) @path, @value, @type, @format = path, value, .delete(:type), .delete(:format) end |
Instance Attribute Details
#format ⇒ Object (readonly)
Returns the value of attribute format.
5 6 7 |
# File 'lib/api-validator/assertion.rb', line 5 def format @format end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/api-validator/assertion.rb', line 5 def path @path end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
5 6 7 |
# File 'lib/api-validator/assertion.rb', line 5 def type @type end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
5 6 7 |
# File 'lib/api-validator/assertion.rb', line 5 def value @value end |
Instance Method Details
#stringified_value ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/api-validator/assertion.rb', line 19 def stringified_value if Regexp === value regex = value.to_s. sub(%r|\(\?-mix:(.*)\)|) { $1 }. gsub("\\A", "^"). gsub("\\Z", "$") "/#{regex}/" else value end end |
#to_hash(options = {}) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/api-validator/assertion.rb', line 10 def to_hash( = {}) _h = { :op => "test", :path => path, :value => stringified_value } _h.delete(:value) if type && value.nil? _h[:type] = "regexp" if Regexp === value _h[:type] = type if type _h[:format] = format if format _h end |