Class: RSpecUUID::Matchers::UUIDMatcher
- Inherits:
-
Object
- Object
- RSpecUUID::Matchers::UUIDMatcher
- Defined in:
- lib/rspec-uuid/matchers.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(version = nil) ⇒ UUIDMatcher
constructor
A new instance of UUIDMatcher.
- #matches?(actual) ⇒ Boolean
Constructor Details
#initialize(version = nil) ⇒ UUIDMatcher
Returns a new instance of UUIDMatcher.
4 5 6 |
# File 'lib/rspec-uuid/matchers.rb', line 4 def initialize(version = nil) @version = version end |
Instance Method Details
#description ⇒ Object
26 27 28 |
# File 'lib/rspec-uuid/matchers.rb', line 26 def description @version ? "a UUID v#{@version}" : "a UUID" end |
#failure_message ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/rspec-uuid/matchers.rb', line 30 def if @actual_version "expected #{description}, found a UUID v#{@actual_version}" else "expected #{description}" end end |
#failure_message_when_negated ⇒ Object
38 39 40 |
# File 'lib/rspec-uuid/matchers.rb', line 38 def "did not expect #{description}" end |
#matches?(actual) ⇒ Boolean
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/rspec-uuid/matchers.rb', line 8 def matches?(actual) return false unless actual.is_a?(String) # https://www.uuidtools.com/what-is-uuid match = actual.match /^\h{8}-\h{4}-(\h{4})-\h{4}-\h{12}$/ return false unless match if @version # 1st nibble of 3rd section @actual_version = match[1].to_i(16) >> 12 @version == @actual_version else true end end |