1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-24 15:49:39 +02:00

Initial pass at Synth-based ticker selection (#1392)

* Initial pass at Synth-based ticker selection

* Update _tickers.turbo_stream.erb

* Functional combobox display

* A few cleanup steps

* Linter

* Prevent long strings

* Another step towards functional combobox

* Deprecated files

* Custom Combobox implementation

* Lint

* Test suite fixes

* Lint

* Make direct use of mic codes

* Update splits

* Update trades_test.rb
This commit is contained in:
Josh Pigford 2024-10-30 09:23:44 -04:00 committed by GitHub
parent 490f44589e
commit cd91e66618
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 118 additions and 232 deletions

View file

@ -1,4 +1,5 @@
class Security < ApplicationRecord
include Providable
before_save :upcase_ticker
has_many :trades, dependent: :nullify, class_name: "Account::Trade"
@ -7,25 +8,6 @@ class Security < ApplicationRecord
validates :ticker, presence: true
validates :ticker, uniqueness: { scope: :exchange_mic, case_sensitive: false }
scope :search, ->(query) {
return none if query.blank? || query.length < 2
# Clean and normalize the search terms
sanitized_query = query.split.map do |term|
cleaned_term = term.gsub(/[^a-zA-Z0-9]/, " ").strip
next if cleaned_term.blank?
cleaned_term
end.compact.join(" | ")
return none if sanitized_query.blank?
sanitized_query = ActiveRecord::Base.connection.quote(sanitized_query)
where("search_vector @@ to_tsquery('simple', #{sanitized_query}) AND exchange_mic IS NOT NULL")
.select("securities.*, ts_rank_cd(search_vector, to_tsquery('simple', #{sanitized_query})) AS rank")
.reorder("rank DESC")
}
def current_price
@current_price ||= Security::Price.find_price(security: self, date: Date.current)
return nil if @current_price.nil?
@ -33,7 +15,7 @@ class Security < ApplicationRecord
end
def to_combobox_display
"#{ticker} - #{name} (#{exchange_acronym})"
"#{ticker} (#{exchange_acronym})"
end