2 # This file is part of SMR.
4 # SMR is free software: you can redistribute it and/or modify it under the
5 # terms of the GNU General Public License as published by the Free Software
6 # Foundation, either version 3 of the License, or (at your option) any later
9 # SMR is distributed in the hope that it will be useful, but WITHOUT ANY
10 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License along with
14 # SMR. If not, see <http://www.gnu.org/licenses/>.
17 class SecurityMetal < ActiveRecord::Base
18 include Smr::Extensions::HelperMethods
19 include Smr::Extensions::SecurityTypemodelMandatoryMethods
21 self.inheritance_column = :none
22 has_one :Security, :foreign_key=>:id_security_metal, :inverse_of=>:SecurityMetal
25 # types of metals supported (may alter behaviour of some methods)
26 # NOTE: do NOT change the relations! just ADD!
27 enum type: { :base=>0, :precious=>1, :strategic=>2 }
30 #validates :id_security, numericality: { greater_than: 0 }
33 # Returns human readable String describing :type. It may be given as
34 # symbol, as string or as numerical index.
35 def SecurityMetal.describe_type(lookup)
37 :base => 'Base Metal',
38 :precious => 'Precious Metal',
39 :strategic => 'Strategic Metal',
42 if lookup.is_a?(Numeric) then
43 lookup = self.types.key(lookup) || ''
45 descriptions[lookup.to_sym]
49 # Describes type of the instance object.
51 SecurityMetal.describe_type(type)
55 # Returns humanreadable String describing the model itself.
56 def SecurityMetal.describe
57 'Industrialized Metal'
60 SecurityMetal.describe
64 # Returns a collection of all types in their described form.
66 # Useful for Select boxes in forms, also see SecurityMetal#describe_type. The
67 # :as_number option toggles whether symbols or integers are retured as
69 def self.types_for_form(options={ :as_number=>false })
70 SecurityMetal.types.map { |t|
72 SecurityMetal.describe_type(t.first),
73 options[:as_number] ? SecurityMetal.types[t.first] : t.first
79 # Human readable String composed of essential properties known by a
80 # SecurityMetal on its own. Useful as part to compose the name of a
84 (self.Security.id_organization != Smr::ID_UNIVERSE_ORGANIZATION ? self.Security.brief : nil),
85 SecurityMetal.describe_type(type),