Sha256: 5a7a6d06ffe2616dc4d2a1b82bb86d70aef8b3f2e8cc60a2ee9779055827b374
Contents?: true
Size: 1.64 KB
Versions: 1
Compression:
Stored size: 1.64 KB
Contents
# encoding: utf-8 module Okei # Stores and validates units of measure. # # Attributes: # +uuids+:: list of Units::Uuid objects assigned (referred to) the unit. # +code+:: literal cyrillic code ("КМ/Ч"). # +name+:: name of the unit ("Километры в час"). # +num+:: numeric code of the unit following the OKEI ("007"). # +int_code+:: a literal international code of the unit ("KMH"). # +base+:: literal cyrillic code of the basic unit of measure ("М/С"). # +factor+:: float number of basic units in a current unit (0.28). # +measure+:: the name of measurement ("СКОРОСТЬ") used for filtering units. # # Methods: # <tt>#uuid</tt>:: returns value of the first +uuids+ assigned to the unit. # <tt>.by_uuid(value)</tt>:: selects units by a given UUID. # # The first UUID can be set manually if necessary (when db populated from the # outer list). Otherwise it will be assigned by default on the unit creation. # # @example # unit = Unit.new( # name: "Километры в час", code: "КМ/Ч", num: "007", int_code: "KMH", # base: "М/С", factor: 0.28, measure: "СКОРОСТЬ" # uuid: "9ac7e74a-d51a-424c-8fcd-71b0b55f6658" # ) # class Unit < ActiveRecord::Base include Uuids::Base # Format of OKEI numeric codes (three digits). NUM_FORMAT = /\A\d{3}\z/ has_uuids validates :code, :name, :base, :factor, :measure, presence: true validates :code, :name, uniqueness: true, allow_nil: true validates :factor, allow_nil: true, numericality: { greater_than: 0.0 } validates :num, allow_nil: true, format: { with: NUM_FORMAT } end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
okei-1.0.2 | app/models/okei/unit.rb |