Sha256: 15376fb8e06ba8305b52e86feec2e8dd7b980575ec455be8d91e5199594e1ffe

Contents?: true

Size: 683 Bytes

Versions: 1

Compression:

Stored size: 683 Bytes

Contents

# encoding: utf-8

module Okei

  # Stores dictionary of words:
  #
  #     Word.new synonym: "МЕТРЫ", text: "М"
  #     Word.new synonym: "МЕТР",  text: "М"
  #
  # ...and units in their standard representation:
  #
  #     Word.new synonym: "КВ М", text: "М2"
  #     Word.new synonym: "М КВ", text: "М2"
  #
  class Word < ActiveRecord::Base

    validates :synonym, :text, presence: true
    validates :synonym, uniqueness: { case_sensitive: false }, allow_nil: true

    # Translates the line if a translation exists.
    # Otherwise returns source line unchanged.
    def self.translate(line)
      find_by_synonym(line).try(:text) || line
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
okei-0.0.2 app/models/okei/word.rb