Class: Frontyard::ApplicationForm::DateTimeParamTransformer
- Inherits:
-
Data
- Object
- Data
- Frontyard::ApplicationForm::DateTimeParamTransformer
- Defined in:
- app/components/frontyard/application_form.rb
Instance Attribute Summary collapse
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
-
#keys ⇒ Object
readonly
Returns the value of attribute keys.
Instance Method Summary collapse
Instance Attribute Details
#hash ⇒ Object (readonly)
Returns the value of attribute hash
26 27 28 |
# File 'app/components/frontyard/application_form.rb', line 26 def hash @hash end |
#keys ⇒ Object (readonly)
Returns the value of attribute keys
26 27 28 |
# File 'app/components/frontyard/application_form.rb', line 26 def keys @keys end |
Instance Method Details
#call(time_converter: Time.zone.method(:local)) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/components/frontyard/application_form.rb', line 27 def call(time_converter: Time.zone.method(:local)) leaf = keys.pop data = keys.reduce(hash) do |memo, key| memo[key] ||= {} end values = [] # Check for both string and symbol keys datetime_keys = [ "#{leaf}(1i)", :"#{leaf}(1i)", "#{leaf}(2i)", :"#{leaf}(2i)", "#{leaf}(3i)", :"#{leaf}(3i)", "#{leaf}(4i)", :"#{leaf}(4i)", "#{leaf}(5i)", :"#{leaf}(5i)" ] datetime_keys.each_slice(2) do |string_key, symbol_key| value = data.delete(string_key) || data.delete(symbol_key) values << value if value end # Filter out nil values and provide defaults filtered_values = values.compact if filtered_values.empty? # If no values provided, use current time Time.current else # Pad with defaults for missing parts year = filtered_values[0] || Time.current.year month = filtered_values[1] || 1 day = filtered_values[2] || 1 hour = filtered_values[3] || 0 minute = filtered_values[4] || 0 time_converter.call(year, month, day, hour, minute) end end |