Class: Familia::Validation::ArgumentMatcher
- Inherits:
-
Object
- Object
- Familia::Validation::ArgumentMatcher
- Defined in:
- lib/familia/validation/expectations.rb
Overview
Argument matcher for flexible command argument validation
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(type, *options) ⇒ ArgumentMatcher
constructor
A new instance of ArgumentMatcher.
-
#matches?(value) ⇒ Boolean
-
#to_s ⇒ Object
Constructor Details
#initialize(type, *options) ⇒ ArgumentMatcher
Returns a new instance of ArgumentMatcher.
322 323 324 325 |
# File 'lib/familia/validation/expectations.rb', line 322 def initialize(type, *) @type = type @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
320 321 322 |
# File 'lib/familia/validation/expectations.rb', line 320 def @options end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
320 321 322 |
# File 'lib/familia/validation/expectations.rb', line 320 def type @type end |
Instance Method Details
#matches?(value) ⇒ Boolean
327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
# File 'lib/familia/validation/expectations.rb', line 327 def matches?(value) case @type when :any_string value.is_a?(String) when :any_number value.to_s.match?(/^\d+$/) when :any_value true when :regex @options.first.match?(value.to_s) else false end end |
#to_s ⇒ Object
342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
# File 'lib/familia/validation/expectations.rb', line 342 def to_s case @type when :any_string '<any_string>' when :any_number '<any_number>' when :any_value '<any_value>' when :regex "<match:#{@options.first}>" else "<#{@type}>" end end |