<commit_before># == Schema Information
#
# Table name: services
#
#  id           :integer          not null, primary key
#  service_name :string           default(""), not null
#  description  :text             default(""), not null
#  price        :decimal(, )      default(0.0), not null
#  order_id     :integer
#  created_at   :datetime         not null
#  updated_at   :datetime         not null

class Service < ApplicationRecord

  has_many :orders, inverse_of: :service

  validates :description, presence: true,
                          length: { maximum: 2000 }

  validates :end_time, presence: { message: "was blank or contained invalid characters." }

  validates :price, presence: true,
                    numericality: { greater_than_or_equal_to: 0 }

  validates :service_name, presence: true,
                   length: { maximum: 50 },
                   uniqueness: true

  validates :start_time, presence: { message: "was blank or contained invalid characters." }

  before_save :process_time

  def string_to_hash(string)
      eval(string)
  end

  def parse_time
    [start_time, end_time].collect do |raw_time|
      time = string_to_hash raw_time
      parsed_time = "#{time[4]}:#{time[5]}"
      parsed_time << "0" if time[5] == 0
      parsed_time
    end

  end

  def set_time_attributes
    self.start_time, self.end_time = parse_time
  end

  def process_time
    set_time_attributes
  end

end<commit_msg>Fix time setters and validations<commit_after># == Schema Information
#
# Table name: services
#
#  id           :integer          not null, primary key
#  service_name :string           default(""), not null
#  description  :text             default(""), not null
#  price        :decimal(, )      default(0.0), not null
#  order_id     :integer
#  created_at   :datetime         not null
#  updated_at   :datetime         not null

class Service < ApplicationRecord
  attr_accessor :get_service_start, :get_service_end

  has_many :orders, inverse_of: :service

  validates :description, presence: true,
                          length: { maximum: 2000 }

  validates :end_time, presence: { message: "was blank or contained invalid characters." }

  validates :price, presence: true
  validates :price, numericality: { greater_than: 0, message: "must be greater than $0.00." }

  validates :service_name, presence: true,
                   length: { maximum: 50 },
                   uniqueness: true


  validates :start_time, presence: { message: "was blank or contained invalid characters." }

  before_validation :set_time, if: :times_are_present?

  def times_are_present?
    get_service_start.present? && get_service_end.present?
  end

  def times_are_valid?
    [get_service_start, get_service_end].all? do |time|
      time[4] != 0 && time[4].present? && time[5].present?
    end
  end

  def parse_time
    [get_service_start, get_service_end].map do |raw_time|
      parsed_time = "#{raw_time[4]}:#{raw_time[5]}"
      parsed_time << "0" if raw_time[5] == 0
    end
  end

  def set_time
    self.start_time, self.end_time = parse_time
  end

end
{'fraction_non_alphanumeric': 0.0964205095130603, 'fraction_numerical': 0.011286681715575621, 'mean_word_length': 2.679715302491103, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5285374', 'n_tokens_mistral': 974, 'n_tokens_neox': 936, 'n_words': 267}