# frozen_string_literal: true # Model Dictionary class Dictionary < ApplicationRecord # == Constants ============================================================ # == Attributes =========================================================== # == Extensions =========================================================== # == Relationships ======================================================== # == Validations ========================================================== validates :name, presence: true, length: { maximum: 255 }, uniqueness: true validates :shortcut, presence: true, length: { maximum: 50 }, uniqueness: true validates :description, presence: true, length: { maximum: 1000 } # == Scopes =============================================================== scope :by_short, ->(val) { where(shortcut: val) } # == Callbacks ============================================================ # == Class Methods ======================================================== def self.ret_all_to_tinymce ret = '' Dictionary.all.each do |dict| ret += dict.ret_a_tinymce_element end ret.chomp end # == Instance Methods ===================================================== def ret_a_tag "#{name}" end def ret_a_tinymce_element "{type: 'menuitem',text: '#{name}',onAction: function ()"\ " {editor.insertContent(' #{shortcut}');}}," end end