Class: Label
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Label
- Includes:
- Housekeeping, Shared::Depictions, Shared::IsData, Shared::Notes, Shared::PolymorphicAnnotator, Shared::Tags
- Defined in:
- app/models/label.rb
Overview
Text to be printed.
Defined Under Namespace
Classes: Code128, Generated, QrCode
Instance Attribute Summary collapse
-
#is_copy_edited ⇒ Boolean?
A curator assertion that the label has been checked and is ready for print.
-
#is_printed ⇒ Boolean?
When true the label has been sent to the printed, as asserted by the curator.
-
#label_object_id ⇒ String
Polymorphic id.
-
#label_object_type ⇒ String
Polymorphic type.
-
#style ⇒ String
The unique name for a corresponding CSS class.
-
#text ⇒ String
The text of the label.
-
#text_method ⇒ Object
Returns the value of attribute text_method.
-
#total ⇒ Integer
The number of copies to print.
Class Method Summary collapse
Instance Method Summary collapse
- #is_generated? ⇒ Boolean
- #set_text ⇒ Object protected
- #stub_text ⇒ Object protected
Methods included from Shared::IsData
#errors_excepting, #full_error_messages_excepting, #identical, #is_community?, #is_destroyable?, #is_editable?, #is_in_use?, #is_in_users_projects?, #metamorphosize, #similar
Methods included from Shared::PolymorphicAnnotator
#annotated_object_is_persisted?
Methods included from Shared::Depictions
#has_depictions?, #image_array=, #reject_depictions, #reject_images
Methods included from Shared::Tags
#reject_tags, #tag_with, #tagged?, #tagged_with?
Methods included from Shared::Notes
#concatenated_notes_string, #reject_notes
Methods included from Housekeeping
#has_polymorphic_relationship?
Methods inherited from ApplicationRecord
Instance Attribute Details
#is_copy_edited ⇒ Boolean?
Returns A curator assertion that the label has been checked and is ready for print. Not required prior to printing.
31 32 33 34 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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'app/models/label.rb', line 31 class Label < ApplicationRecord include Housekeeping include Shared::Notes include Shared::Tags include Shared::Depictions include Shared::PolymorphicAnnotator include Shared::IsData polymorphic_annotates('label_object', presence_validate: false) ignore_whitespace_on(:text) attr_accessor :text_method before_validation :stub_text, if: Proc.new { |c| c.text_method.present? } after_save :set_text, if: Proc.new { |c| c.text_method.present? } validates_presence_of :text, :total scope :unprinted, -> { where(is_printed: false) } def is_generated? false end def self.batch_create( collecting_event_query_params, label_attribute, total, preview ) q = Queries::CollectingEvent::Filter.new(collecting_event_query_params).all label_attribute = (label_attribute || '').to_sym if ![:verbatim_label, :document_label, :print_label].include?(label_attribute) raise TaxonWorks::Error, "Invalid label choice: '#{label_attribute}'" end max = 1_000 if q.count > max raise TaxonWorks::Error, "At most #{max} labels can be created at once" end total = [total, 1].max r = BatchResponse.new({ preview:, async: false, total_attempted: q.count }) self.transaction do begin q.pluck(:id, label_attribute).each do |ce_id, label_text| if label_text.blank? r.not_updated.push ce_id next end begin Label.create!( text: label_text, total:, label_object_id: ce_id, label_object_type: 'CollectingEvent', ) r.updated.push ce_id rescue ActiveRecord::RecordInvalid => e # Probably never occurs for Label given our pre-checks r.not_updated.push e.record.id r.errors[e.] = 0 unless r.errors[e.] r.errors[e.] += 1 end end end raise ActiveRecord::Rollback if r.preview end # end transaction r end protected def set_text update_column(:text, label_object.reload.send(text_method.to_sym)) end def stub_text assign_attributes(text: 'STUB') end end |
#is_printed ⇒ Boolean?
Returns When true the label has been sent to the printed, as asserted by the curator.
31 32 33 34 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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'app/models/label.rb', line 31 class Label < ApplicationRecord include Housekeeping include Shared::Notes include Shared::Tags include Shared::Depictions include Shared::PolymorphicAnnotator include Shared::IsData polymorphic_annotates('label_object', presence_validate: false) ignore_whitespace_on(:text) attr_accessor :text_method before_validation :stub_text, if: Proc.new { |c| c.text_method.present? } after_save :set_text, if: Proc.new { |c| c.text_method.present? } validates_presence_of :text, :total scope :unprinted, -> { where(is_printed: false) } def is_generated? false end def self.batch_create( collecting_event_query_params, label_attribute, total, preview ) q = Queries::CollectingEvent::Filter.new(collecting_event_query_params).all label_attribute = (label_attribute || '').to_sym if ![:verbatim_label, :document_label, :print_label].include?(label_attribute) raise TaxonWorks::Error, "Invalid label choice: '#{label_attribute}'" end max = 1_000 if q.count > max raise TaxonWorks::Error, "At most #{max} labels can be created at once" end total = [total, 1].max r = BatchResponse.new({ preview:, async: false, total_attempted: q.count }) self.transaction do begin q.pluck(:id, label_attribute).each do |ce_id, label_text| if label_text.blank? r.not_updated.push ce_id next end begin Label.create!( text: label_text, total:, label_object_id: ce_id, label_object_type: 'CollectingEvent', ) r.updated.push ce_id rescue ActiveRecord::RecordInvalid => e # Probably never occurs for Label given our pre-checks r.not_updated.push e.record.id r.errors[e.] = 0 unless r.errors[e.] r.errors[e.] += 1 end end end raise ActiveRecord::Rollback if r.preview end # end transaction r end protected def set_text update_column(:text, label_object.reload.send(text_method.to_sym)) end def stub_text assign_attributes(text: 'STUB') end end |
#label_object_id ⇒ String
Returns Polymorphic id.
31 32 33 34 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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'app/models/label.rb', line 31 class Label < ApplicationRecord include Housekeeping include Shared::Notes include Shared::Tags include Shared::Depictions include Shared::PolymorphicAnnotator include Shared::IsData polymorphic_annotates('label_object', presence_validate: false) ignore_whitespace_on(:text) attr_accessor :text_method before_validation :stub_text, if: Proc.new { |c| c.text_method.present? } after_save :set_text, if: Proc.new { |c| c.text_method.present? } validates_presence_of :text, :total scope :unprinted, -> { where(is_printed: false) } def is_generated? false end def self.batch_create( collecting_event_query_params, label_attribute, total, preview ) q = Queries::CollectingEvent::Filter.new(collecting_event_query_params).all label_attribute = (label_attribute || '').to_sym if ![:verbatim_label, :document_label, :print_label].include?(label_attribute) raise TaxonWorks::Error, "Invalid label choice: '#{label_attribute}'" end max = 1_000 if q.count > max raise TaxonWorks::Error, "At most #{max} labels can be created at once" end total = [total, 1].max r = BatchResponse.new({ preview:, async: false, total_attempted: q.count }) self.transaction do begin q.pluck(:id, label_attribute).each do |ce_id, label_text| if label_text.blank? r.not_updated.push ce_id next end begin Label.create!( text: label_text, total:, label_object_id: ce_id, label_object_type: 'CollectingEvent', ) r.updated.push ce_id rescue ActiveRecord::RecordInvalid => e # Probably never occurs for Label given our pre-checks r.not_updated.push e.record.id r.errors[e.] = 0 unless r.errors[e.] r.errors[e.] += 1 end end end raise ActiveRecord::Rollback if r.preview end # end transaction r end protected def set_text update_column(:text, label_object.reload.send(text_method.to_sym)) end def stub_text assign_attributes(text: 'STUB') end end |
#label_object_type ⇒ String
Returns Polymorphic type.
31 32 33 34 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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'app/models/label.rb', line 31 class Label < ApplicationRecord include Housekeeping include Shared::Notes include Shared::Tags include Shared::Depictions include Shared::PolymorphicAnnotator include Shared::IsData polymorphic_annotates('label_object', presence_validate: false) ignore_whitespace_on(:text) attr_accessor :text_method before_validation :stub_text, if: Proc.new { |c| c.text_method.present? } after_save :set_text, if: Proc.new { |c| c.text_method.present? } validates_presence_of :text, :total scope :unprinted, -> { where(is_printed: false) } def is_generated? false end def self.batch_create( collecting_event_query_params, label_attribute, total, preview ) q = Queries::CollectingEvent::Filter.new(collecting_event_query_params).all label_attribute = (label_attribute || '').to_sym if ![:verbatim_label, :document_label, :print_label].include?(label_attribute) raise TaxonWorks::Error, "Invalid label choice: '#{label_attribute}'" end max = 1_000 if q.count > max raise TaxonWorks::Error, "At most #{max} labels can be created at once" end total = [total, 1].max r = BatchResponse.new({ preview:, async: false, total_attempted: q.count }) self.transaction do begin q.pluck(:id, label_attribute).each do |ce_id, label_text| if label_text.blank? r.not_updated.push ce_id next end begin Label.create!( text: label_text, total:, label_object_id: ce_id, label_object_type: 'CollectingEvent', ) r.updated.push ce_id rescue ActiveRecord::RecordInvalid => e # Probably never occurs for Label given our pre-checks r.not_updated.push e.record.id r.errors[e.] = 0 unless r.errors[e.] r.errors[e.] += 1 end end end raise ActiveRecord::Rollback if r.preview end # end transaction r end protected def set_text update_column(:text, label_object.reload.send(text_method.to_sym)) end def stub_text assign_attributes(text: 'STUB') end end |
#style ⇒ String
Returns The unique name for a corresponding CSS class. # TODO: reference vocabulary file.
31 32 33 34 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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'app/models/label.rb', line 31 class Label < ApplicationRecord include Housekeeping include Shared::Notes include Shared::Tags include Shared::Depictions include Shared::PolymorphicAnnotator include Shared::IsData polymorphic_annotates('label_object', presence_validate: false) ignore_whitespace_on(:text) attr_accessor :text_method before_validation :stub_text, if: Proc.new { |c| c.text_method.present? } after_save :set_text, if: Proc.new { |c| c.text_method.present? } validates_presence_of :text, :total scope :unprinted, -> { where(is_printed: false) } def is_generated? false end def self.batch_create( collecting_event_query_params, label_attribute, total, preview ) q = Queries::CollectingEvent::Filter.new(collecting_event_query_params).all label_attribute = (label_attribute || '').to_sym if ![:verbatim_label, :document_label, :print_label].include?(label_attribute) raise TaxonWorks::Error, "Invalid label choice: '#{label_attribute}'" end max = 1_000 if q.count > max raise TaxonWorks::Error, "At most #{max} labels can be created at once" end total = [total, 1].max r = BatchResponse.new({ preview:, async: false, total_attempted: q.count }) self.transaction do begin q.pluck(:id, label_attribute).each do |ce_id, label_text| if label_text.blank? r.not_updated.push ce_id next end begin Label.create!( text: label_text, total:, label_object_id: ce_id, label_object_type: 'CollectingEvent', ) r.updated.push ce_id rescue ActiveRecord::RecordInvalid => e # Probably never occurs for Label given our pre-checks r.not_updated.push e.record.id r.errors[e.] = 0 unless r.errors[e.] r.errors[e.] += 1 end end end raise ActiveRecord::Rollback if r.preview end # end transaction r end protected def set_text update_column(:text, label_object.reload.send(text_method.to_sym)) end def stub_text assign_attributes(text: 'STUB') end end |
#text ⇒ String
Returns The text of the label.
31 32 33 34 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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'app/models/label.rb', line 31 class Label < ApplicationRecord include Housekeeping include Shared::Notes include Shared::Tags include Shared::Depictions include Shared::PolymorphicAnnotator include Shared::IsData polymorphic_annotates('label_object', presence_validate: false) ignore_whitespace_on(:text) attr_accessor :text_method before_validation :stub_text, if: Proc.new { |c| c.text_method.present? } after_save :set_text, if: Proc.new { |c| c.text_method.present? } validates_presence_of :text, :total scope :unprinted, -> { where(is_printed: false) } def is_generated? false end def self.batch_create( collecting_event_query_params, label_attribute, total, preview ) q = Queries::CollectingEvent::Filter.new(collecting_event_query_params).all label_attribute = (label_attribute || '').to_sym if ![:verbatim_label, :document_label, :print_label].include?(label_attribute) raise TaxonWorks::Error, "Invalid label choice: '#{label_attribute}'" end max = 1_000 if q.count > max raise TaxonWorks::Error, "At most #{max} labels can be created at once" end total = [total, 1].max r = BatchResponse.new({ preview:, async: false, total_attempted: q.count }) self.transaction do begin q.pluck(:id, label_attribute).each do |ce_id, label_text| if label_text.blank? r.not_updated.push ce_id next end begin Label.create!( text: label_text, total:, label_object_id: ce_id, label_object_type: 'CollectingEvent', ) r.updated.push ce_id rescue ActiveRecord::RecordInvalid => e # Probably never occurs for Label given our pre-checks r.not_updated.push e.record.id r.errors[e.] = 0 unless r.errors[e.] r.errors[e.] += 1 end end end raise ActiveRecord::Rollback if r.preview end # end transaction r end protected def set_text update_column(:text, label_object.reload.send(text_method.to_sym)) end def stub_text assign_attributes(text: 'STUB') end end |
#text_method ⇒ Object
Returns the value of attribute text_method.
44 45 46 |
# File 'app/models/label.rb', line 44 def text_method @text_method end |
#total ⇒ Integer
Returns The number of copies to print.
31 32 33 34 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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'app/models/label.rb', line 31 class Label < ApplicationRecord include Housekeeping include Shared::Notes include Shared::Tags include Shared::Depictions include Shared::PolymorphicAnnotator include Shared::IsData polymorphic_annotates('label_object', presence_validate: false) ignore_whitespace_on(:text) attr_accessor :text_method before_validation :stub_text, if: Proc.new { |c| c.text_method.present? } after_save :set_text, if: Proc.new { |c| c.text_method.present? } validates_presence_of :text, :total scope :unprinted, -> { where(is_printed: false) } def is_generated? false end def self.batch_create( collecting_event_query_params, label_attribute, total, preview ) q = Queries::CollectingEvent::Filter.new(collecting_event_query_params).all label_attribute = (label_attribute || '').to_sym if ![:verbatim_label, :document_label, :print_label].include?(label_attribute) raise TaxonWorks::Error, "Invalid label choice: '#{label_attribute}'" end max = 1_000 if q.count > max raise TaxonWorks::Error, "At most #{max} labels can be created at once" end total = [total, 1].max r = BatchResponse.new({ preview:, async: false, total_attempted: q.count }) self.transaction do begin q.pluck(:id, label_attribute).each do |ce_id, label_text| if label_text.blank? r.not_updated.push ce_id next end begin Label.create!( text: label_text, total:, label_object_id: ce_id, label_object_type: 'CollectingEvent', ) r.updated.push ce_id rescue ActiveRecord::RecordInvalid => e # Probably never occurs for Label given our pre-checks r.not_updated.push e.record.id r.errors[e.] = 0 unless r.errors[e.] r.errors[e.] += 1 end end end raise ActiveRecord::Rollback if r.preview end # end transaction r end protected def set_text update_column(:text, label_object.reload.send(text_method.to_sym)) end def stub_text assign_attributes(text: 'STUB') end end |
Class Method Details
.batch_create(collecting_event_query_params, label_attribute, total, preview) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'app/models/label.rb', line 58 def self.batch_create( collecting_event_query_params, label_attribute, total, preview ) q = Queries::CollectingEvent::Filter.new(collecting_event_query_params).all label_attribute = (label_attribute || '').to_sym if ![:verbatim_label, :document_label, :print_label].include?(label_attribute) raise TaxonWorks::Error, "Invalid label choice: '#{label_attribute}'" end max = 1_000 if q.count > max raise TaxonWorks::Error, "At most #{max} labels can be created at once" end total = [total, 1].max r = BatchResponse.new({ preview:, async: false, total_attempted: q.count }) self.transaction do begin q.pluck(:id, label_attribute).each do |ce_id, label_text| if label_text.blank? r.not_updated.push ce_id next end begin Label.create!( text: label_text, total:, label_object_id: ce_id, label_object_type: 'CollectingEvent', ) r.updated.push ce_id rescue ActiveRecord::RecordInvalid => e # Probably never occurs for Label given our pre-checks r.not_updated.push e.record.id r.errors[e.] = 0 unless r.errors[e.] r.errors[e.] += 1 end end end raise ActiveRecord::Rollback if r.preview end # end transaction r end |
Instance Method Details
#is_generated? ⇒ Boolean
54 55 56 |
# File 'app/models/label.rb', line 54 def is_generated? false end |
#set_text ⇒ Object (protected)
115 116 117 |
# File 'app/models/label.rb', line 115 def set_text update_column(:text, label_object.reload.send(text_method.to_sym)) end |
#stub_text ⇒ Object (protected)
119 120 121 |
# File 'app/models/label.rb', line 119 def stub_text assign_attributes(text: 'STUB') end |