Class: IssnRecord

Inherits:
ApplicationRecord
  • Object
show all
Defined in:
app/models2/issn_record.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.new_records(issn_records_params) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/models2/issn_record.rb', line 18

def self.new_records(issn_records_params)
  return [] unless issn_records_params
  issn_records = []
  IssnRecord.transaction do
    issn_records_params.each do |k, v|
      next if v['_destroy'] == '1'
      if v['body'].present?
        issn_record = IssnRecord.where(body: v['body'].gsub(/[^0-9x]/i, '')).first_or_create!
      elsif v['id'].present?
        issn_record = IssnRecord.find(v['id'])
      else
        v.delete('_destroy')
        issn_record = IssnRecord.create(v)
      end
      issn_records << issn_record
    end
  end
  issn_records
end

Instance Method Details

#normalize_issnObject



10
11
12
13
14
15
16
# File 'app/models2/issn_record.rb', line 10

def normalize_issn
  if StdNum::ISSN.valid?(body)
    self.body = StdNum::ISSN.normalize(body)
  else
    errors.add(:body)
  end
end