Sha256: 1da10e122b0f3a6895359a9a09cdbb5492db28b86cdb379d918e0ef446cf0a2e

Contents?: true

Size: 1.52 KB

Versions: 9

Compression:

Stored size: 1.52 KB

Contents

require 'date'
require_relative '../../models/student/student.rb'
require_relative './edit_student_presenter'

# == Replace_student_presenter
# Презентер для замены информации о студенте.
class Replace_student_presenter < Edit_student_presenter

  # Заполнение полей интерфейса текущими основными данными студента.
  def populate_fields
    self.get_student
    data = {
      "first_name" => self.student.first_name,
      "name" => self.student.name,
      "patronymic" => self.student.patronymic,
      "birthdate" => self.student.birthdate.strftime('%d.%m.%Y'),
    }
    self.view.update_view data
  end

  # Проверка валидности новых данных студента.
  #
  # @param student_data [Hash] Новые данные студента.
  # @return [Boolean] Возвращает true, если данные валидны и отличаются от текущих.
  def valid_data?(student_data)
    data = student_data.transform_values { |value| value.strip }
    self.logger.debug "Проверка валидности данных: #{data.to_s}"
    valid = super(data)
    unchanged = self.student.first_name == data["first_name"] &&
      self.student.name == data["name"] &&
      self.student.patronymic == data["patronymic"] &&
      self.student.birthdate.strftime('%d.%m.%Y') == data["birthdate"]
    res = valid && !unchanged
    self.logger.info "Валидность данных: #{res}"
    res
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
student_mvp-0.1.10 lib/presenters/edit_student/replace_student_presenter.rb
student_mvp-0.1.9 lib/presenters/edit_student/replace_student_presenter.rb
student_mvp-0.1.8 lib/presenters/edit_student/replace_student_presenter.rb
student_mvp-0.1.7 lib/presenters/edit_student/replace_student_presenter.rb
student_mvp-0.1.6 lib/presenters/edit_student/replace_student_presenter.rb
student_mvp-0.1.5 lib/presenters/edit_student/replace_student_presenter.rb
student_mvp-0.1.4 lib/presenters/edit_student/replace_student_presenter.rb
student_mvp-0.1.3 lib/presenters/edit_student/replace_student_presenter.rb
student_mvp-0.1.2 lib/presenters/edit_student/replace_student_presenter.rb