Module: Lab42::BasicConstraints::Implementation

Extended by:
Implementation
Included in:
Implementation
Defined in:
lib/lab42/basic_constraints/implementation.rb

Instance Method Summary collapse

Instance Method Details

#date(default: nil) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/lab42/basic_constraints/implementation.rb', line 7

def date default: nil
  require "date"
  Constraint.new(:date) do |value|
    Date.parse(value) rescue false
  end
    .set_default default do
    Date.today.iso8601
  end
end

#non_negative_intObject



17
18
19
20
21
22
# File 'lib/lab42/basic_constraints/implementation.rb', line 17

def non_negative_int
  Constraint.new :non_negative_int do |value|
    Integer === value && value >= 0
  end
    .set_default(0)
end

#not_yet_implementedObject

Raises:

  • (NotImplementedError)


31
32
33
# File 'lib/lab42/basic_constraints/implementation.rb', line 31

def not_yet_implemented
  raise NotImplementedError
end

#positive_numberObject



24
25
26
27
28
29
# File 'lib/lab42/basic_constraints/implementation.rb', line 24

def positive_number
  Constraint.new :positive_number do |value|
    Integer === value && value > 0 ||
      Float === value && value > 0.0
  end
end

#yearObject



35
36
37
38
39
40
41
42
# File 'lib/lab42/basic_constraints/implementation.rb', line 35

def year
  Constraint.new(:year) do |value|
    Integer === value
  end
    .set_default do 
      Time.now.utc.year
    end
end