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
83
84
85
|
# File 'app/models/digital_asset.rb', line 83
def self.bulk_processed?
(stale.count.to_f / self.count) <= 0.05
end
|
.purge! ⇒ Object
74
75
76
77
|
# File 'app/models/digital_asset.rb', line 74
def self.purge!
DigitalAsset.stale.destroy_all if bulk_processed?
end
|
Instance Method Details
#as_json(opts = {}) ⇒ Object
validates_uniqueness_of :guid
70
71
72
|
# File 'app/models/digital_asset.rb', line 70
def as_json(opts = {})
super(opts).merge({:comp_fundcode => fund_code, :content_type_id => content_type_id})
end
|
#audience ⇒ Object
156
157
158
|
# File 'app/models/digital_asset.rb', line 156
def audience
@audience ||= TaxonomyTerm.label_for_term(audiences[0])
end
|
#content_org ⇒ Object
133
134
135
|
# File 'app/models/digital_asset.rb', line 133
def content_org
@content_org ||= TaxonomyTerm.label_for_term(content_organization_ids[0])
end
|
#content_type ⇒ Object
145
146
147
|
# File 'app/models/digital_asset.rb', line 145
def content_type
@content_type_label ||= TaxonomyTerm.label_for_term(content_type_id)
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
99
100
101
102
103
104
105
|
# File 'app/models/digital_asset.rb', line 99
def content_type_ids
ids = []
documents.try(:each) do |d|
ids << d.content_type
end
ids
end
|
#doc_changed_at(path) ⇒ Object
91
92
93
|
# File 'app/models/digital_asset.rb', line 91
def doc_changed_at(path)
path_is(path).try(:doc_changed_at)
end
|
#doc_size ⇒ Object
95
96
97
|
# File 'app/models/digital_asset.rb', line 95
def doc_size
first_non_finra.try(:size)
end
|
#finra_document ⇒ Object
112
113
114
115
|
# File 'app/models/digital_asset.rb', line 112
def finra_document
finra_idx = documents.index {|d| d.content_type == ContentType::FINRA}
documents[finra_idx] if finra_idx
end
|
#fund_code ⇒ Object
137
138
139
140
141
142
143
|
# File 'app/models/digital_asset.rb', line 137
def fund_code
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
|
#has_finra? ⇒ Boolean
108
109
110
|
# File 'app/models/digital_asset.rb', line 108
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
153
154
|
# File 'app/models/digital_asset.rb', line 152
def pages
@pages ||= first_non_finra.pages
end
|
#path_is(path) ⇒ Object
87
88
89
|
# File 'app/models/digital_asset.rb', line 87
def path_is(path)
documents.where(path: path).first unless documents.blank?
end
|
#primary_extension ⇒ Object
164
165
166
|
# File 'app/models/digital_asset.rb', line 164
def primary_extension
first_non_finra.try(:path).try(:split,'.').try(:last).try(:upcase)
end
|
#primary_path ⇒ Object
160
161
162
|
# File 'app/models/digital_asset.rb', line 160
def primary_path
first_non_finra.try(:path)
end
|
#product ⇒ Object
127
128
129
|
# File 'app/models/digital_asset.rb', line 127
def product
@product ||= TaxonomyTerm.label_for_term(product_ids[0])
end
|
#program ⇒ Object
130
131
132
|
# File 'app/models/digital_asset.rb', line 130
def program
@program ||= TaxonomyTerm.label_for_term(program_ids[0])
end
|
#validate_future_expiration ⇒ Object
79
80
81
|
# File 'app/models/digital_asset.rb', line 79
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
|