module CorreiosApi class Rate attr_reader :service_name, :service_code, :price, :delivery_time_in_days, :max_delivery_time, :message, :errors def initialize service_name:, service_code:, price:, delivery_time_in_days:, max_delivery_time:, message: nil, errors: nil @service_name = service_name @service_code = service_code @price = transform_price(price) @delivery_time_in_days = delivery_time_in_days @max_delivery_time = transform_date(max_delivery_time) @message = message @errors = errors end private def transform_price price return nil unless price price.gsub(",", ".").to_f end def transform_date date return nil unless date Time.new(date) end end end