Class: InvalidDate

Inherits:
Date
  • Object
show all
Defined in:
lib/invalid_date.rb

Overview

As our form objects convert to the correct type on input, rather than use the typical mess of fetching values before validation that active record does, we will take the approach of having an invalid date which is simply an instance of Date whose valid? method returns false and the day, month and year values are whatever is provided

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(year, month, day) ⇒ InvalidDate

Returns a new instance of InvalidDate


13
14
15
16
17
# File 'lib/invalid_date.rb', line 13

def initialize(year, month, day)
  self.day = day
  self.month = month
  self.year = year
end

Instance Attribute Details

#dayObject

Returns the value of attribute day


6
7
8
# File 'lib/invalid_date.rb', line 6

def day
  @day
end

#monthObject

Returns the value of attribute month


6
7
8
# File 'lib/invalid_date.rb', line 6

def month
  @month
end

#yearObject

Returns the value of attribute year


6
7
8
# File 'lib/invalid_date.rb', line 6

def year
  @year
end

Class Method Details

.new(year, month, day) ⇒ Object


7
8
9
10
11
# File 'lib/invalid_date.rb', line 7

def self.new(year, month, day)
  super(1970, 1, 1).tap do |instance|
    instance.send(:initialize, year, month, day)
  end
end

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)

19
20
21
# File 'lib/invalid_date.rb', line 19

def blank?
  false
end

#valid?Boolean

Returns:

  • (Boolean)

23
24
25
# File 'lib/invalid_date.rb', line 23

def valid?
  false
end