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
82
83
84
|
# File 'app/models/digital_asset.rb', line 82
def self.bulk_processed?
(stale.count.to_f / self.count) <= 0.05
end
|
.purge! ⇒ Object
73
74
75
76
|
# File 'app/models/digital_asset.rb', line 73
def self.purge!
DigitalAsset.stale.destroy_all if bulk_processed?
end
|
Instance Method Details
#as_json(opts = {}) ⇒ Object
validates_uniqueness_of :guid
69
70
71
|
# File 'app/models/digital_asset.rb', line 69
def as_json(opts = {})
super(opts).merge({:comp_fundcode => fund_code, :content_type_id => content_type_id})
end
|
#content_org ⇒ Object
136
137
138
|
# File 'app/models/digital_asset.rb', line 136
def content_org
TaxonomyTerm.label_for_term(content_organization_ids[0])
end
|
#content_type_id ⇒ Object
148
149
150
|
# File 'app/models/digital_asset.rb', line 148
def content_type_id
first_non_finra.try(:content_type)
end
|
#content_type_ids ⇒ Object
Also known as:
doctype_ids
98
99
100
101
102
103
104
|
# File 'app/models/digital_asset.rb', line 98
def content_type_ids
ids = []
documents.try(:each) do |d|
ids << d.content_type
end
ids
end
|
#doc_changed_at(path) ⇒ Object
90
91
92
|
# File 'app/models/digital_asset.rb', line 90
def doc_changed_at(path)
path_is(path).try(:doc_changed_at)
end
|
#doc_size ⇒ Object
94
95
96
|
# File 'app/models/digital_asset.rb', line 94
def doc_size
first_non_finra.try(:size)
end
|
#expired? ⇒ Boolean
111
112
113
|
# File 'app/models/digital_asset.rb', line 111
def expired?
expires_at < Time.now
end
|
#finra_document ⇒ Object
115
116
117
118
|
# File 'app/models/digital_asset.rb', line 115
def finra_document
finra_idx = documents.index {|d| d.content_type == ContentType::FINRA}
documents[finra_idx] if finra_idx
end
|
#fund_code ⇒ Object
140
141
142
143
|
# File 'app/models/digital_asset.rb', line 140
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
|
#has_finra? ⇒ Boolean
107
108
109
|
# File 'app/models/digital_asset.rb', line 107
def has_finra?
finra_document != nil
end
|
#is_institutional_use? ⇒ Boolean
Also known as:
institutional_use?
#is_investor_approved? ⇒ Boolean
Also known as:
investor_approved?
#pages ⇒ Object
152
|
# File 'app/models/digital_asset.rb', line 152
def pages; first_non_finra.pages end
|
#path_is(path) ⇒ Object
86
87
88
|
# File 'app/models/digital_asset.rb', line 86
def path_is(path)
documents.where(path: path).first unless documents.blank?
end
|
#primary_extension ⇒ Object
162
163
164
|
# File 'app/models/digital_asset.rb', line 162
def primary_extension
first_non_finra.try(:path).try(:split,'.').try(:last).try(:upcase)
end
|
#primary_path ⇒ Object
158
159
160
|
# File 'app/models/digital_asset.rb', line 158
def primary_path
first_non_finra.try(:path)
end
|
#validate_future_expiration ⇒ Object
78
79
80
|
# File 'app/models/digital_asset.rb', line 78
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
|