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
97
98
99
|
# File 'app/models/digital_asset.rb', line 97
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
79
80
81
|
# File 'app/models/digital_asset.rb', line 79
def self.purge!
DigitalAsset.stale.destroy_all if bulk_processed?
end
|
Instance Method Details
#audience ⇒ Object
167
168
169
|
# File 'app/models/digital_asset.rb', line 167
def audience
TaxonomyTerm.label_for_term(audiences[0])
end
|
#content_org ⇒ Object
151
152
153
|
# File 'app/models/digital_asset.rb', line 151
def content_org
TaxonomyTerm.label_for_term(content_organization_ids[0])
end
|
#content_type ⇒ 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
160
161
162
|
# File 'app/models/digital_asset.rb', line 160
def content_type
TaxonomyTerm.label_for_term(content_type_id)
end
|
#content_type_id ⇒ Object
163
164
165
|
# File 'app/models/digital_asset.rb', line 163
def content_type_id
:content_type
end
|
#expired? ⇒ Boolean
126
127
128
|
# File 'app/models/digital_asset.rb', line 126
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
122
123
124
|
# File 'app/models/digital_asset.rb', line 122
def has_finra?
finra_path.present?
end
|
#is_institutional_use? ⇒ Boolean
Also known as:
institutional_use?
140
141
142
|
# File 'app/models/digital_asset.rb', line 140
def is_institutional_use?
audiences.index(DigitalAsset::Audience::INSTITUTIONAL_USE)
end
|
#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
135
136
137
|
# File 'app/models/digital_asset.rb', line 135
def is_investor_approved?
audiences.index(DigitalAsset::Audience::INVESTOR_APPROVED)
end
|
#latest_doc_changed_at ⇒ Object
83
84
85
86
87
88
89
90
91
|
# File 'app/models/digital_asset.rb', line 83
def latest_doc_changed_at
doc_changed_at
end
|
#primary_extension ⇒ Object
175
176
177
|
# File 'app/models/digital_asset.rb', line 175
def primary_extension
self.try(:path).try(:split,'.').try(:last).try(:upcase)
end
|
#primary_path ⇒ Object
171
172
173
|
# File 'app/models/digital_asset.rb', line 171
def primary_path
:path
end
|
#product ⇒ Object
145
146
147
|
# File 'app/models/digital_asset.rb', line 145
def product
TaxonomyTerm.label_for_term(product_ids[0])
end
|
#program ⇒ Object
148
149
150
|
# File 'app/models/digital_asset.rb', line 148
def program
TaxonomyTerm.label_for_term(program_ids[0])
end
|
#validate_future_expiration ⇒ Object
93
94
95
|
# File 'app/models/digital_asset.rb', line 93
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
|