lib/swedish_pin/personnummer.rb in swedish-pin-1.0.0 vs lib/swedish_pin/personnummer.rb in swedish-pin-1.1.0
- old
+ new
@@ -6,10 +6,12 @@
#
# Determine if this is a _Personnummer_ or a _Samordningsnummer_ using {coordination_number?}.
#
# @see https://en.wikipedia.org/wiki/Personal_identity_number_(Sweden) Personnummer on Wikipedia.
class Personnummer
+ include Comparable
+
attr_reader :year, :month, :day, :sequence_number, :control_digit
# @!attribute [r] year
# The full year of the _personnummer_. For example +1989+.
# @return [Integer]
# @!attribute [r] month
@@ -172,9 +174,30 @@
# identified as +female+.
# @return [true, false]
def female?
sequence_number.even?
end
+
+ def ==(other)
+ if other.is_a?(self.class)
+ format_long == other.format_long
+ else
+ super
+ end
+ end
+
+ def <=>(other)
+ if other.is_a?(self.class)
+ format_long <=> other.format_long
+ else
+ super
+ end
+ end
+
+ def hash
+ [self.class, format_long].hash
+ end
+ alias_method :eql?, :==
private
def short_separator(now)
if year <= (now.year - 100)