Class: DigitalAsset

Inherits:
Object
  • 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

Returns:

  • (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

#audienceObject



167
168
169
# File 'app/models/digital_asset.rb', line 167

def audience
  TaxonomyTerm.label_for_term(audiences[0])
end

#content_orgObject



151
152
153
# File 'app/models/digital_asset.rb', line 151

def content_org
  TaxonomyTerm.label_for_term(content_organization_ids[0])
end

#content_typeObject

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_idObject



163
164
165
# File 'app/models/digital_asset.rb', line 163

def content_type_id
 :content_type
end

#expired?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


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?

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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_atObject



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
  # documents.reduce(nil) do |latest_date, d|
  #   unless d.content_type == '549'
  #     latest_date = d.doc_changed_at if (latest_date == nil || latest_date < d.doc_changed_at)
  #   end
  #   latest_date
  # end
end

#primary_extensionObject



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_pathObject



171
172
173
# File 'app/models/digital_asset.rb', line 171

def primary_path
  :path
end

#productObject



145
146
147
# File 'app/models/digital_asset.rb', line 145

def product
  TaxonomyTerm.label_for_term(product_ids[0])
end

#programObject



148
149
150
# File 'app/models/digital_asset.rb', line 148

def program
  TaxonomyTerm.label_for_term(program_ids[0])
end

#validate_future_expirationObject



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