app/models/digital_asset.rb in daengine-0.4.0.4 vs app/models/digital_asset.rb in daengine-0.4.5
- old
+ new
@@ -36,10 +36,12 @@
scope :title_is, ->(title) { where(:title => title)}
scope :business_owner_is, ->(business_owner) { where(:business_owner => business_owner)}
scope :guid_is, ->(guid) { where(:guid => guid)}
# scope :funds_in, ->(fund_id) { where(:fund_ids.in => fund_id)}
scope :audience_in, ->(audience_id) {where(:audiences.in => audience_id)}
+ scope :audience_investor_approved, -> {where(:audiences.in => [Audience::INVESTOR_APPROVED])}
+
scope :content_organization_in, ->(content_organization_id) {where(:content_organization_ids.in => content_organization_id)}
scope :program_id_in, ->(program_id) {where(:program_ids.in => program_id)}
scope :sami_is, ->(sami_code) {where(:sami_code => sami_code)}
scope :sami_in, ->(sami_codes) {where(:sami_code.in => sami_codes)}
scope :path_is, ->(path) {where(:'documents.path' => path)}
@@ -51,10 +53,11 @@
scope :orderable, -> {where(orderable: true)}
scope :has_finra, -> {where(:'documents.content_type' => ContentType::FINRA)}
scope :audience_in, ->(audience) {where(:audiences.in => audience)}
scope :alphabetical, order_by(:title => :asc)
scope :not_xbrl, -> {excludes(:'documents.content_type' => ContentType::XBRL_DOCUMENT)}
+
#scope :order_by_fund, order_by[[:product_ids, :asc]]
#default_scope {not_in(:'documents.content_type' => ["LDJDCMAIK"])}
# validations
validates_presence_of :guid, :title, :changed_at, :published_at,
@@ -120,34 +123,39 @@
audiences.index(DigitalAsset::Audience::INSTITUTIONAL_USE)
end
alias :institutional_use? :is_institutional_use?
def product
- TaxonomyTerm.label_for_term(product_ids[0])
+ @product ||= TaxonomyTerm.label_for_term(product_ids[0])
end
def program
- TaxonomyTerm.label_for_term(program_ids[0])
+ @program ||= TaxonomyTerm.label_for_term(program_ids[0])
end
def content_org
- TaxonomyTerm.label_for_term(content_organization_ids[0])
+ @content_org ||= TaxonomyTerm.label_for_term(content_organization_ids[0])
end
def fund_code
- pid = product_ids.find {|pid| TaxonomyTerm.term_id_is(pid).first.try(:fund_code)}
- pid and TaxonomyTerm.term_id_is(pid)[0].try(:fund_code).try(:rjust, 5, '0')
+ if @fund_code
+ return @fund_code
+ end
+ pid = product_ids.find {|pid| TaxonomyTerm.find_term_by_id(pid).first.try(:fund_code)}
+ @fund_code = pid and TaxonomyTerm.find_term_by_id(pid)[0].try(:fund_code).try(:rjust, 5, '0')
end
def content_type
- TaxonomyTerm.label_for_term(content_type_id)
+ @content_type_label ||= TaxonomyTerm.label_for_term(content_type_id)
end
def content_type_id
first_non_finra.try(:content_type)
end
- def pages; first_non_finra.pages end
+ def pages
+ @pages ||= first_non_finra.pages
+ end
def audience
- TaxonomyTerm.label_for_term(audiences[0])
+ @audience ||= TaxonomyTerm.label_for_term(audiences[0])
end
def primary_path
first_non_finra.try(:path)
end