Class: DigitalAsset
- Inherits:
-
Object
- Object
- DigitalAsset
- Includes:
- Mongoid::Document, Mongoid::Timestamps
- Defined in:
- app/models/digital_asset.rb
Defined Under Namespace
Classes: Document
Constant Summary collapse
- PROSPECTUS =
'542'
- FACTSHEET =
'533'
- COMMENTARY =
'532'
- ANNUAL_REPORT =
'529'
- SEMIANNUAL_REPORT =
'541'
- SAI =
'540'
- SUMMARY_PROSPECTUS =
'5380'
- OTHER =
''
Class Method Summary collapse
- .bulk_processed? ⇒ Boolean
-
.purge! ⇒ Object
validates_uniqueness_of :guid.
Instance Method Summary collapse
- #asset_type ⇒ Object
- #audience ⇒ Object
- #content_org ⇒ Object
- #content_type ⇒ Object
- #content_type_ids ⇒ Object (also: #doctype_ids)
- #finra_document ⇒ Object
- #has_finra? ⇒ Boolean
- #is_institutional_use? ⇒ Boolean
- #is_investor_approved? ⇒ Boolean
- #pages ⇒ Object
- #product ⇒ Object
- #program ⇒ Object
- #validate_future_expiration ⇒ Object
Class Method Details
.bulk_processed? ⇒ Boolean
78 79 80 |
# File 'app/models/digital_asset.rb', line 78 def self.bulk_processed? (stale.count.to_f / self.count) <= 0.05 end |
.purge! ⇒ Object
validates_uniqueness_of :guid
69 70 71 72 |
# File 'app/models/digital_asset.rb', line 69 def self.purge! # last_update = DigitalAsset.desc(:updated_at).try(:first).try :updated_at DigitalAsset.stale.destroy_all if bulk_processed? end |
Instance Method Details
#asset_type ⇒ Object
100 101 102 103 104 105 106 107 108 109 |
# File 'app/models/digital_asset.rb', line 100 def asset_type docs = documents.select { |d| d.content_type == PROSPECTUS || d.content_type == SAI || d.content_type == COMMENTARY || d.content_type == SEMIANNUAL_REPORT || d.content_type == ANNUAL_REPORT || d.content_type == FACTSHEET || d.content_type == SUMMARY_PROSPECTUS} docs.size == 1 ? docs[0].content_type : OTHER end |
#audience ⇒ Object
134 135 136 |
# File 'app/models/digital_asset.rb', line 134 def audience TaxonomyTerm.label_for_term(audiences[0]) end |
#content_org ⇒ Object
125 126 127 |
# File 'app/models/digital_asset.rb', line 125 def content_org TaxonomyTerm.label_for_term(content_organization_ids[0]) end |
#content_type ⇒ Object
128 129 130 131 |
# File 'app/models/digital_asset.rb', line 128 def content_type type_id = first_non_finra.try(:content_type) TaxonomyTerm.label_for_term(type_id) end |
#content_type_ids ⇒ Object Also known as: doctype_ids
82 83 84 85 86 87 88 |
# File 'app/models/digital_asset.rb', line 82 def content_type_ids ids = [] documents.try :each do |d| ids << d.content_type end ids end |
#finra_document ⇒ Object
95 96 97 98 |
# File 'app/models/digital_asset.rb', line 95 def finra_document finra_docs = documents.select {|d| d.content_type == '549'} finra_docs.size == 1 ? finra_docs[0] : nil end |
#has_finra? ⇒ Boolean
91 92 93 |
# File 'app/models/digital_asset.rb', line 91 def has_finra? finra_document != nil end |
#is_institutional_use? ⇒ Boolean
115 116 117 |
# File 'app/models/digital_asset.rb', line 115 def is_institutional_use? audiences.index('491') ? true : false end |
#is_investor_approved? ⇒ Boolean
111 112 113 |
# File 'app/models/digital_asset.rb', line 111 def is_investor_approved? audiences.index('490') ? true : false end |
#pages ⇒ Object
132 |
# File 'app/models/digital_asset.rb', line 132 def pages; first_non_finra.pages end |
#product ⇒ Object
119 120 121 |
# File 'app/models/digital_asset.rb', line 119 def product TaxonomyTerm.label_for_term(product_ids[0]) end |
#program ⇒ Object
122 123 124 |
# File 'app/models/digital_asset.rb', line 122 def program TaxonomyTerm.label_for_term(program_ids[0]) end |
#validate_future_expiration ⇒ Object
74 75 76 |
# File 'app/models/digital_asset.rb', line 74 def validate_future_expiration errors.add(:expires_at, "Expiration date must be at least 1 minute from now") unless expires_at and expires_at > 1.minute.from_now end |