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/>.
16 class Quoterecord < ActiveRecord::Base
17 include Smr::Extensions::DateTimeWrapper
19 belongs_to :User, :foreign_key=>:id_user
20 belongs_to :Quote, :foreign_key=>:id_quote
21 belongs_to :Security, :foreign_key=>:id_security
22 has_one :Organization, :through => :Security
25 # possible values for 'column' field
27 # keys of this hash are the actual column values while the hash values are
28 # a human readable representation
29 # <b>ATTENTION</b>: the order matters for viewing
31 'secondary_rally' => 'Secondary Rally',
32 'natural_rally' => 'Natural Rally',
33 'upward' => 'Upward Trend',
34 'downward' => 'Downward Trend',
35 'natural_reaction' => 'Natural Reaction',
36 'secondary_reaction' => 'Secondary Reaction',
40 validates :id_user, :id_security, :id_quote, presence: true
41 validates :id_user, :id_security, :id_quote, :date_created, numericality: { greater_than: 0 }
42 validates :column, inclusion: { in: POSSIBLE_COLUMNS.keys, message: "%{value} is not a valid column name" }
44 # define scopes and ransack aliases for finding things
45 ransack_alias :ransackcolumns, :comment_or_Security_brief_or_Security_symbol_or_Organization_name
48 # returns array of possible values for :column field
54 # returns human readable +String+ for given column name, see get_columns()
55 def self.translate_column(column=self.column)
56 POSSIBLE_COLUMNS[column]
60 # tell whether this record has been sorted in to column
61 def is_column?(column_name)
62 self.column == column_name
66 # tell a human what happened
69 msg << 'UP hit' if self.is_uphit
70 msg << 'DOWN hit' if self.is_downhit
71 msg << 'classified quote' if msg.empty?
73 msg << 'on %s' % self.Security.to_s
75 msg << 'into %s column' % self.class.translate_column(self.column)
77 msg << 'which is a pivotal point' if self.is_pivotal_point
78 msg << 'and triggered SIGNAL' if self.is_signal