module RunSignup::DataCoercion
Public Instance Methods
coerce_for_api(hash)
click to toggle source
# File lib/run_signup/data_coercion.rb, line 37 def coerce_for_api hash hash.each do |k, v| hash[k] = coerce_value_for_api v end end
coerce_from_api(hash)
click to toggle source
# File lib/run_signup/data_coercion.rb, line 4 def coerce_from_api hash if hash hash.each do |k, v| hash[k] = coerce_value_from_api v if k == 'events' hash[k] = hash[k].map { |event| RunSignup::Event.new(event) } end end end hash end
coerce_value_for_api(value)
click to toggle source
# File lib/run_signup/data_coercion.rb, line 43 def coerce_value_for_api value case value when true 'T' when false 'F' else value end end
coerce_value_from_api(value)
click to toggle source
# File lib/run_signup/data_coercion.rb, line 16 def coerce_value_from_api value if value.is_a?(Array) value.map { |v1| coerce_value_from_api(v1) } elsif value.is_a?(Hash) coerce_from_api(value) else case value when 'T' true when 'F' false when /^\d{1,2}\/\d{1,2}\/\d{4} \d{2}:\d{2}$/ DateTime.strptime(value, '%m/%d/%Y %H:%M').to_s when /^\d{1,2}\/\d{1,2}\/\d{4}$/ Date.strptime(value, '%m/%d/%Y').to_s else value end end end