Module: Metro2::Fields
- Included in:
- Metro2File, Records::Record
- Defined in:
- lib/metro_2/fields.rb
Instance Method Summary collapse
- #alphanumeric_const_field(name, required_length, val, permitted_chars = Metro2::ALPHANUMERIC) ⇒ Object
- #alphanumeric_field(name, required_length, permitted_chars = Metro2::ALPHANUMERIC) ⇒ Object
- #date_field(name) ⇒ Object
- #monetary_field(name) ⇒ Object
- #numeric_const_field(name, required_length, val, is_monetary = false) ⇒ Object
- #numeric_field(name, required_length, is_monetary: false, possible_values: nil) ⇒ Object
- #timestamp_field(name) ⇒ Object
Instance Method Details
#alphanumeric_const_field(name, required_length, val, permitted_chars = Metro2::ALPHANUMERIC) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/metro_2/fields.rb', line 44 def alphanumeric_const_field(name, required_length, val, permitted_chars = Metro2::ALPHANUMERIC) fields << name # getter define_method name do val end # to_metro2 define_method "#{name}_to_metro2" do Metro2.alphanumeric_to_metro2(val, required_length, permitted_chars, name) end end |
#alphanumeric_field(name, required_length, permitted_chars = Metro2::ALPHANUMERIC) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/metro_2/fields.rb', line 3 def alphanumeric_field(name, required_length, permitted_chars = Metro2::ALPHANUMERIC) fields << name # getter define_method name do instance_variable_get("@#{name}") end # setter (includes validations) define_method "#{name}=" do | val | instance_variable_set("@#{name}", val) end # to_metro2 define_method "#{name}_to_metro2" do val = instance_variable_get("@#{name}") Metro2.alphanumeric_to_metro2(val, required_length, permitted_chars, name) end end |
#date_field(name) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/metro_2/fields.rb', line 77 def date_field(name) fields << name # getter define_method name do instance_variable_get("@#{name}") end # setter (includes validations) define_method "#{name}=" do | val | instance_variable_set("@#{name}", val) end # to_metro2 define_method "#{name}_to_metro2" do # Right justified and zero-filled val = instance_variable_get("@#{name}") val = val&.strftime('%m%d%Y') Metro2.numeric_to_metro2(val, 8) end end |
#monetary_field(name) ⇒ Object
73 74 75 |
# File 'lib/metro_2/fields.rb', line 73 def monetary_field(name) numeric_field(name, 9, is_monetary: true) end |
#numeric_const_field(name, required_length, val, is_monetary = false) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/metro_2/fields.rb', line 59 def numeric_const_field(name, required_length, val, is_monetary = false) fields << name # getter define_method name do val end # to_metro2 define_method "#{name}_to_metro2" do Metro2.numeric_to_metro2(val, required_length, is_monetary: is_monetary) end end |
#numeric_field(name, required_length, is_monetary: false, possible_values: nil) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/metro_2/fields.rb', line 23 def numeric_field(name, required_length, is_monetary: false, possible_values: nil) fields << name # getter define_method name do instance_variable_get("@#{name}") end # setter (includes validations) define_method "#{name}=" do | val | instance_variable_set("@#{name}", val) end # to_metro2 define_method "#{name}_to_metro2" do val = instance_variable_get("@#{name}") Metro2.numeric_to_metro2(val, required_length, is_monetary: is_monetary, name: name, possible_values: possible_values) end end |
#timestamp_field(name) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/metro_2/fields.rb', line 100 def (name) fields << name # getter define_method name do instance_variable_get("@#{name}") end # setter (includes validations) define_method "#{name}=" do | val | instance_variable_set("@#{name}", val) end # to_metro2 define_method "#{name}_to_metro2" do # Right justified and zero-filled val = instance_variable_get("@#{name}") val = val&.strftime('%m%d%Y%H%M%S') Metro2.numeric_to_metro2(val, 14) end end |