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)


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!
  # last_update = DigitalAsset.desc(:updated_at).try(:first).try :updated_at
  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

#audienceObject



156
157
158
# File 'app/models/digital_asset.rb', line 156

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

#content_orgObject



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_typeObject



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_idObject



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

def content_type_id
 first_non_finra.try(:content_type) 
end

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



95
96
97
# File 'app/models/digital_asset.rb', line 95

def doc_size
  first_non_finra.try(:size)
end

#finra_documentObject



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_codeObject



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

Returns:

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

Returns:

  • (Boolean)


122
123
124
# File 'app/models/digital_asset.rb', line 122

def is_institutional_use?
  audiences.index(DigitalAsset::Audience::INSTITUTIONAL_USE)
end

#is_investor_approved?Boolean Also known as: investor_approved?

Returns:

  • (Boolean)


117
118
119
# File 'app/models/digital_asset.rb', line 117

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

#pagesObject



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_extensionObject



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_pathObject



160
161
162
# File 'app/models/digital_asset.rb', line 160

def primary_path
  first_non_finra.try(:path)
end

#productObject



127
128
129
# File 'app/models/digital_asset.rb', line 127

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

#programObject



130
131
132
# File 'app/models/digital_asset.rb', line 130

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

#validate_future_expirationObject



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