Skip to content

Commit

Permalink
Display fund's type and sector
Browse files Browse the repository at this point in the history
  • Loading branch information
arielkirkwood committed May 5, 2024
1 parent 3118f75 commit 5b02150
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/models/fund.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Fund < ApplicationRecord
has_many :assets, through: :holdings

delegate :extract_holdings, to: :holdings_extractor
delegate :name, to: :underlying_asset
delegate :name, :type, :sector, to: :underlying_asset

validates :underlying_asset_id, uniqueness: true

Expand Down
9 changes: 7 additions & 2 deletions app/views/funds/_fund.html.erb
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
<div class="h3"><%= render @ticker %></div>
<%= tag.h1 fund.name %>

<div class="h6 mb-3">
<span class="badge text-bg-primary"><%= tag.strong fund.type.underscore.humanize %></span>
<span class="badge text-bg-primary"><%= tag.strong fund.sector %></span>
</div>

<hr>

<%= tag.blockquote class: 'blockquote' do %>
<figcaption class="blockquote-footer mt-0 mb-3">
<cite><strong>Betterment</strong></cite> says about this fund:
</figcaption>
<%= fund.betterment_detail %>
<% end %>

<hr>

<%= render fund.latest_portfolio %>
11 changes: 9 additions & 2 deletions lib/holdings/extraction_strategies/tcw.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,16 @@ def date
@date ||= Date.parse(worksheet[1][1].value)
end

def extract_holdings # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
def extract_holdings # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
working_sheet.map do |row|
asset = Asset.find_or_create_by!(name: row[:description], asset_class: asset_type(row[:security_type]))
asset = if (ticker = Assets::Ticker.where(ticker: row[:ticker]).first)
ticker.asset
elsif (cusip = Assets::CUSIP.where(cusip: row[:cusip]).first)
cusip.asset
elsif (sedol = Assets::SEDOL.where(sedol: row[:sedol]).first)
sedol.asset
end
asset = Asset.find_or_create_by!(name: row[:description], asset_class: asset_type(row[:security_type])) if asset.blank?

Assets::Ticker.find_or_create_by(asset:, ticker: row[:ticker]) if row[:ticker] != 'n/a'
Assets::Currency.find_or_create_by(asset:, currency: row[:asset_currency]) if asset_type(row[:security_type]) == 'CashEquivalent' && row[:asset_currency].present?
Expand Down

0 comments on commit 5b02150

Please sign in to comment.