Class: Date

Inherits:
Object show all
Defined in:
lib/conversion_test.rb,
lib/conversion/mode/human_input/class_decoration.rb

Overview

:nodoc:

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.to_french_human_input_converter_procObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/conversion_test.rb', line 40

def to_french_human_input_converter_proc
  proc { |value|
    value = value.convert_to(Conversion::HumanInputString)
    if value.nil?
      nil
    else
      # "d/m/y" => date(y,m,d)
      elements = value.split(/[-\/]/).convert_entries_to(Integer)
      begin
        Date.civil(elements[2], elements[1], elements[0])
      rescue
        value
      end
    end
  }
end

.to_human_input_converter_procObject

Returns a human_input converter Proc that converts “m/d/y” dates to Date object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/conversion/mode/human_input/class_decoration.rb', line 6

def to_human_input_converter_proc
  proc { |value|
    value = value.convert_to(Conversion::HumanInputString)
    if value.nil?
      nil
    else
      # "m/d/y" => date(y,m,d)
      elements = value.split(/[-\/]/).convert_entries_to(Integer)
      begin
        Date.civil(elements[2], elements[0], elements[1])
      rescue
        value
      end
    end
  }
end

Instance Method Details

#to_human_input_stringObject

Returns “m/d/y”

See Conversion::HumanInputString.to_converter_proc



27
28
29
30
# File 'lib/conversion/mode/human_input/class_decoration.rb', line 27

def to_human_input_string
  # date(y,m,d) => "m/d/y"
  "#{month}/#{day}/#{year}"
end