Module: ValidatesTimeliness::ActiveRecord

Defined in:
lib/validates_timeliness/active_record/attribute_methods.rb,
lib/validates_timeliness/active_record/multiparameter_attributes.rb

Defined Under Namespace

Modules: AttributeMethods, MultiparameterAttributes

Class Method Summary collapse

Class Method Details

.extract_date_from_multiparameter_attributes(values) ⇒ Object



24
25
26
27
# File 'lib/validates_timeliness/active_record/multiparameter_attributes.rb', line 24

def extract_date_from_multiparameter_attributes(values)
  year = ValidatesTimeliness::Formats.unambiguous_year(values[0].rjust(2, "0"))
  [year, *values.slice(1, 2).map { |s| s.rjust(2, "0") }].join("-")
end

.extract_time_from_multiparameter_attributes(values) ⇒ Object



29
30
31
# File 'lib/validates_timeliness/active_record/multiparameter_attributes.rb', line 29

def extract_time_from_multiparameter_attributes(values)
  values[3..5].map { |s| s.rjust(2, "0") }.join(":")
end

.time_array_to_string(values, type) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/validates_timeliness/active_record/multiparameter_attributes.rb', line 11

def time_array_to_string(values, type)
  values.collect! {|v| v.to_s }

  case type
  when :date
    extract_date_from_multiparameter_attributes(values)
  when :time
    extract_time_from_multiparameter_attributes(values)
  when :datetime
    extract_date_from_multiparameter_attributes(values) + " " + extract_time_from_multiparameter_attributes(values)
  end
end