Class: DigitalAsset
- Inherits:
-
Object
show all
- Includes:
- Mongoid::Document, Mongoid::Timestamps
- Defined in:
- app/models/digital_asset.rb
Defined Under Namespace
Classes: Audience, ContentType, Document
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.bulk_processed? ⇒ Boolean
99
100
101
|
# File 'app/models/digital_asset.rb', line 99
def self.bulk_processed?
(stale.count.to_f / self.count) <= 0.05
end
|
.purge! ⇒ Object
def as_json(opts = {})
super(opts).merge({:comp_fundcode => fund_codes, :content_type_id => content_type_id, :latest_doc_changed_at => latest_doc_changed_at})
end
81
82
83
|
# File 'app/models/digital_asset.rb', line 81
def self.purge!
DigitalAsset.stale.destroy_all if bulk_processed?
end
|
Instance Method Details
#content_org ⇒ Object
153
154
155
|
# File 'app/models/digital_asset.rb', line 153
def content_org
TaxonomyTerm.label_for_term(content_organization_ids[0])
end
|
#content_type_label ⇒ Object
def fund_code
pid = product_ids.find {|pid| TaxonomyTerm.term_id_is(pid)[0].try(:fund_code)}
pid and TaxonomyTerm.term_id_is(pid)[0].try(:fund_code).try(:rjust, 5, '0')
end
162
163
164
|
# File 'app/models/digital_asset.rb', line 162
def content_type_label
TaxonomyTerm.label_for_term(content_type_id)
end
|
#expired? ⇒ Boolean
128
129
130
|
# File 'app/models/digital_asset.rb', line 128
def expired?
expires_at < Time.now
end
|
#has_finra? ⇒ Boolean
def content_type_ids
ids = []
documents.try(:each) do |d|
ids << d.content_type
end
ids
end alias :doctype_ids :content_type_ids
124
125
126
|
# File 'app/models/digital_asset.rb', line 124
def has_finra?
finra_path.present?
end
|
#is_institutional_use? ⇒ Boolean
Also known as:
institutional_use?
#is_investor_approved? ⇒ Boolean
Also known as:
investor_approved?
def finra_document
finra_idx = documents.index {|d| d.content_type == ContentType::FINRA}
documents[finra_idx] if finra_idx
end
#latest_doc_changed_at ⇒ Object
85
86
87
88
89
90
91
92
93
|
# File 'app/models/digital_asset.rb', line 85
def latest_doc_changed_at
doc_changed_at
end
|
#primary_extension ⇒ Object
174
175
176
|
# File 'app/models/digital_asset.rb', line 174
def primary_extension
self.try(:path).try(:split,'.').try(:last).try(:upcase)
end
|
#primary_path ⇒ Object
170
171
172
|
# File 'app/models/digital_asset.rb', line 170
def primary_path
:path
end
|
#validate_future_expiration ⇒ Object
95
96
97
|
# File 'app/models/digital_asset.rb', line 95
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
|