Class: Manifestation
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Manifestation
- Defined in:
- app/models/manifestation.rb
Instance Attribute Summary collapse
-
#series_statement_id ⇒ Object
Returns the value of attribute series_statement_id.
Class Method Summary collapse
- .cached_numdocs ⇒ Object
-
.find_by_isbn(isbn) ⇒ Object
def volume_number volume_number_string.gsub(/D/, ‘ ’).split(“ ”) if volume_number_string end.
Instance Method Summary collapse
- #acquired_at ⇒ Object
- #check_isbn ⇒ Object
- #check_issn ⇒ Object
- #check_lccn ⇒ Object
- #check_pub_date ⇒ Object
- #clear_cached_numdocs ⇒ Object
- #convert_isbn ⇒ Object
- #delete_attachment ⇒ Object
- #delete_attachment=(value) ⇒ Object
- #hyphenated_isbn ⇒ Object
- #number_of_pages ⇒ Object
- #parent_of_series ⇒ Object
- #set_date_of_publication ⇒ Object
- #set_digest(options = {:type => 'sha1'}) ⇒ Object
- #set_new_serial_number ⇒ Object
- #set_volume_issue_number ⇒ Object
- #set_wrong_isbn ⇒ Object
- #title ⇒ Object
- #titles ⇒ Object
Instance Attribute Details
#series_statement_id ⇒ Object
Returns the value of attribute series_statement_id.
32 33 34 |
# File 'app/models/manifestation.rb', line 32 def series_statement_id @series_statement_id end |
Class Method Details
.cached_numdocs ⇒ Object
144 145 146 147 148 149 150 |
# File 'app/models/manifestation.rb', line 144 def self.cached_numdocs Rails.cache.fetch("manifestation_search_total"){ Manifestation.search do with(:periodical_master, false) end.total } end |
.find_by_isbn(isbn) ⇒ Object
def volume_number
volume_number_string.gsub(/\D/, ' ').split(" ") if volume_number_string
end
def issue_number
issue_number_string.gsub(/\D/, ' ').split(" ") if issue_number_string
end
def serial_number
serial_number_string.gsub(/\D/, ' ').split(" ") if serial_number_string
end
236 237 238 239 240 241 242 243 244 245 246 |
# File 'app/models/manifestation.rb', line 236 def self.find_by_isbn(isbn) lisbn = Lisbn.new(isbn) if lisbn.valid? #ISBN_Tools.cleanup!(isbn) if isbn.size == 10 Manifestation.where(:isbn => lisbn.isbn13).first || Manifestation.where(:isbn => lisbn).first else Manifestation.where(:isbn => lisbn).first || Manifestation.where(:isbn => lisbn.isbn10).first end end end |
Instance Method Details
#acquired_at ⇒ Object
248 249 250 |
# File 'app/models/manifestation.rb', line 248 def acquired_at items.order(:acquired_at).first.try(:acquired_at) end |
#check_isbn ⇒ Object
77 78 79 80 81 82 83 |
# File 'app/models/manifestation.rb', line 77 def check_isbn if isbn.present? unless Lisbn.new(isbn).valid? errors.add(:isbn) end end end |
#check_issn ⇒ Object
85 86 87 88 89 90 91 92 |
# File 'app/models/manifestation.rb', line 85 def check_issn if issn.present? self.issn = Lisbn.new(issn) unless StdNum::ISSN.valid?(issn) errors.add(:issn) end end end |
#check_lccn ⇒ Object
94 95 96 97 98 99 100 |
# File 'app/models/manifestation.rb', line 94 def check_lccn if lccn.present? unless StdNum::LCCN.valid?(lccn, true) errors.add(:lccn) end end end |
#check_pub_date ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/models/manifestation.rb', line 35 def check_pub_date logger.info "manifestaion#check pub_date=#{self.pub_date}" date = self.pub_date.to_s.gsub(' ', '').dup return if date.blank? unless date =~ /^\d+(-\d{0,2}){0,2}$/ errors.add(:pub_date); return end if date =~ /^[0-9]+$/ # => YYYY / YYYYMM / YYYYMMDD case date.length when 4 date = "#{date}-01-01" when 6 year = date.slice(0, 4) month = date.slice(4, 2) date = "#{year}-#{month}-01" when 8 year = date.slice(0, 4) month = date.slice(4, 2) day = date.slice(6, 2) date = "#{year}-#{month}-#{day}" else errors.add(:pub_date); return end else date_a = date.split(/\D/) #=> ex. YYYY / YYYY-MM / YYYY-MM-DD / YY-MM-DD year = date_a[0] month = date_a[1] day = date_a[2] date = "#{year}-01-01" unless month and day date = "#{year}-#{month}-01" unless day date = "#{year}-#{month}-#{day}" if year and month and day end begin date = Time.zone.parse(date) rescue errors.add(:pub_date) end end |
#clear_cached_numdocs ⇒ Object
152 153 154 |
# File 'app/models/manifestation.rb', line 152 def clear_cached_numdocs Rails.cache.delete("manifestation_search_total") end |
#convert_isbn ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 |
# File 'app/models/manifestation.rb', line 111 def convert_isbn num = Lisbn.new(isbn) if isbn if num if num.length == 10 self.isbn10 = num self.isbn = num.isbn13 elsif num.length == 13 self.isbn10 = num.isbn10 end end end |
#delete_attachment ⇒ Object
252 253 254 |
# File 'app/models/manifestation.rb', line 252 def ||= "0" end |
#delete_attachment=(value) ⇒ Object
256 257 258 |
# File 'app/models/manifestation.rb', line 256 def (value) = value end |
#hyphenated_isbn ⇒ Object
210 211 212 |
# File 'app/models/manifestation.rb', line 210 def hyphenated_isbn Lisbn.new(isbn).parts.join("-") end |
#number_of_pages ⇒ Object
160 161 162 163 164 165 166 167 168 |
# File 'app/models/manifestation.rb', line 160 def number_of_pages if self.start_page and self.end_page if self.start_page.present? and self.end_page.present? if self.start_page.to_s.match(/\D/).nil? and self.end_page.to_s.match(/\D/).nil? page = self.end_page.to_i - self.start_page.to_i + 1 end end end end |
#parent_of_series ⇒ Object
156 157 158 |
# File 'app/models/manifestation.rb', line 156 def parent_of_series original_manifestations end |
#set_date_of_publication ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'app/models/manifestation.rb', line 123 def set_date_of_publication return if pub_date.blank? date = pub_date.gsub(/(\.|\,|\/)/, '-') begin date = Time.zone.parse("#{date}") rescue ArgumentError begin date = Time.zone.parse("#{date}-01") date = date.end_of_month rescue ArgumentError begin date = Time.zone.parse("#{date}-12-01") date = date.end_of_month rescue ArgumentError nil end end end self.date_of_publication = date end |
#set_digest(options = {:type => 'sha1'}) ⇒ Object
214 215 216 217 218 219 220 |
# File 'app/models/manifestation.rb', line 214 def set_digest( = {:type => 'sha1'}) if .queued_for_write[:original] if File.exists?(.queued_for_write[:original]) self.file_hash = Digest::SHA1.hexdigest(File.open(.queued_for_write[:original].path, 'rb').read) end end end |
#set_new_serial_number ⇒ Object
181 182 183 184 185 186 187 |
# File 'app/models/manifestation.rb', line 181 def set_new_serial_number if self.serial_number_string.blank? or self.serial_number_string.tr('0-9','0-9').match(/\D/) self.serial_number = nil else self.serial_number = self.serial_number_string.tr('0-9','0-9').to_i end end |
#set_volume_issue_number ⇒ Object
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'app/models/manifestation.rb', line 189 def set_volume_issue_number if self.volume_number_string.blank? or self.volume_number_string.tr('0-9','0-9').match(/\D/) self.volume_number = nil else self.volume_number = self.volume_number_string.tr('0-9','0-9').to_i end if self.issue_number_string.blank? or self.issue_number_string.tr('0-9','0-9').match(/\D/) self.issue_number = nil else self.issue_number = self.issue_number_string.tr('0-9','0-9').to_i end #if self.volume_number && self.volume_number.to_s.length > 9 # self.volume_number = nil #end end |
#set_wrong_isbn ⇒ Object
102 103 104 105 106 107 108 109 |
# File 'app/models/manifestation.rb', line 102 def set_wrong_isbn if isbn.present? unless Lisbn.new(isbn).valid? self.wrong_isbn self.isbn = nil end end end |
#title ⇒ Object
206 207 208 |
# File 'app/models/manifestation.rb', line 206 def title titles end |
#titles ⇒ Object
170 171 172 173 174 175 176 177 178 179 |
# File 'app/models/manifestation.rb', line 170 def titles title = [] title << original_title.to_s.strip title << title_transcription.to_s.strip title << title_alternative.to_s.strip #title << original_title.wakati #title << title_transcription.wakati rescue nil #title << title_alternative.wakati rescue nil title end |