Class: IsbnRecord
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- IsbnRecord
- Defined in:
- app/models2/isbn_record.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.new_records(isbn_records_params) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/models2/isbn_record.rb', line 8 def self.new_records(isbn_records_params) return [] unless isbn_records_params isbn_records = [] IsbnRecord.transaction do isbn_records_params.each do |k, v| next if v['_destroy'] == '1' if v['body'].present? isbn_record = IsbnRecord.where(body: Lisbn.new(v['body'].gsub(/[^0-9x]/i, '')).isbn13).first_or_create! elsif v['id'].present? isbn_record = IsbnRecord.find(v['id']) else v.delete('_destroy') isbn_record = IsbnRecord.create(v) end isbn_records << isbn_record end end isbn_records end |
Instance Method Details
#normalize_isbn ⇒ Object
28 29 30 31 32 33 34 |
# File 'app/models2/isbn_record.rb', line 28 def normalize_isbn if StdNum::ISBN.valid?(body) self.body = StdNum::ISBN.normalize(body) else errors.add(:body) end end |
#valid_isbn? ⇒ Boolean
36 37 38 |
# File 'app/models2/isbn_record.rb', line 36 def valid_isbn? StdNum::ISBN.valid?(body) end |