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)


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

#audienceObject



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

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

#content_orgObject



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_labelObject

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

Returns:

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

Returns:

  • (Boolean)


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?

Returns:

  • (Boolean)


142
143
144
# File 'app/models/digital_asset.rb', line 142

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)


137
138
139
# File 'app/models/digital_asset.rb', line 137

def is_investor_approved?
  audiences.index(DigitalAsset::Audience::INVESTOR_APPROVED)
end

#latest_doc_changed_atObject



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
  # 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



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_pathObject



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

def primary_path
  :path
end

#productObject



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

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

#programObject



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

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

#validate_future_expirationObject



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