Class: Item
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Item
- Defined in:
- app/models/item.rb
Instance Attribute Summary collapse
-
#library_id ⇒ Object
Returns the value of attribute library_id.
-
#manifestation_id ⇒ Object
Returns the value of attribute manifestation_id.
-
#use_restriction_id ⇒ Object
Returns the value of attribute use_restriction_id.
Instance Method Summary collapse
- #check_acquired_at_string ⇒ Object
- #select_acquired_at ⇒ Object
- #set_acquired_at ⇒ Object
- #title ⇒ Object
Instance Attribute Details
#library_id ⇒ Object
Returns the value of attribute library_id.
15 16 17 |
# File 'app/models/item.rb', line 15 def library_id @library_id end |
#manifestation_id ⇒ Object
Returns the value of attribute manifestation_id.
15 16 17 |
# File 'app/models/item.rb', line 15 def manifestation_id @manifestation_id end |
#use_restriction_id ⇒ Object
Returns the value of attribute use_restriction_id.
15 16 17 |
# File 'app/models/item.rb', line 15 def use_restriction_id @use_restriction_id end |
Instance Method Details
#check_acquired_at_string ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/models/item.rb', line 21 def check_acquired_at_string return if self.acquired_at_string.blank? case self.acquired_at_string when /^\d{4}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01]$)|^\d{4}-(0?[1-9]|1[0-2])-(0?[1-9]|[12]\d|3[01])$/ dates = self.acquired_at_string =~ /^\d{8}$/ ? ["#{self.acquired_at_string[0..3]}", "#{self.acquired_at_string[4..5]}", "#{self.acquired_at_string[6..7]}"] : self.acquired_at_string.split('-') date = Time.zone.parse(self.acquired_at_string) rescue nil if date dates[1] = "0#{dates[1]}" if dates[1].match(/^[1-9]$/) dates[2] = "0#{dates[2]}" if dates[2].match(/^[1-9]$/) if date.strftime("%m") == dates[1] self.acquired_at_string = dates.join('-'); return end end when /^\d{4}-(0?[1-9]|1[0-2])$/ dates = self.acquired_at_string.split('-') dates[1] = "0#{dates[1]}" if dates[1].match(/^[1-9]$/) self.acquired_at_string = dates.join('-'); return when /^\d{4}$/ return end errors.add(:acquired_at_string) end |
#select_acquired_at ⇒ Object
44 45 46 47 48 49 50 |
# File 'app/models/item.rb', line 44 def select_acquired_at if self.acquired_at return self.acquired_at.strftime("%Y%m") else return Time.now.strftime("%Y%m") end end |
#set_acquired_at ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/models/item.rb', line 52 def set_acquired_at return if acquired_at_string.blank? begin date = Time.zone.parse("#{acquired_at_string}") rescue ArgumentError begin date = Time.zone.parse("#{acquired_at_string}-01") date = date.end_of_month rescue ArgumentError begin date = Time.zone.parse("#{acquired_at_string}-12-01") date = date.end_of_month rescue ArgumentError nil end end end self.acquired_at = date end |
#title ⇒ Object
17 18 19 |
# File 'app/models/item.rb', line 17 def title manifestation.try(:original_title) end |