Class: Unico::MaterialClass
- Defined in:
- app/models/unico/material_class.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#number ⇒ Object
Returns the value of attribute number.
-
#parent_class_number ⇒ Object
Returns the value of attribute parent_class_number.
-
#parent_number ⇒ Object
Returns the value of attribute parent_number.
Class Method Summary collapse
Instance Method Summary collapse
- #children ⇒ Object
- #class_number_level ⇒ Object
- #editable? ⇒ Boolean
- #levels ⇒ Object
- #parent ⇒ Object
- #splitted_masked_number ⇒ Object
- #splitted_masked_number_filled ⇒ Object
- #to_s ⇒ Object
- #update_has_children ⇒ Object
Instance Attribute Details
#number ⇒ Object
Returns the value of attribute number.
5 6 7 |
# File 'app/models/unico/material_class.rb', line 5 def number @number end |
#parent_class_number ⇒ Object
Returns the value of attribute parent_class_number.
5 6 7 |
# File 'app/models/unico/material_class.rb', line 5 def parent_class_number @parent_class_number end |
#parent_number ⇒ Object
Returns the value of attribute parent_number.
5 6 7 |
# File 'app/models/unico/material_class.rb', line 5 def parent_number @parent_number end |
Class Method Details
.children(id, raw_class_number) ⇒ Object
31 32 33 34 |
# File 'app/models/unico/material_class.rb', line 31 def self.children(id, raw_class_number) where(arel_table[:class_number].matches("#{raw_class_number}%")) .where(arel_table[:id].not_eq(id)) end |
.term(q) ⇒ Object
24 25 26 27 28 29 |
# File 'app/models/unico/material_class.rb', line 24 def self.term(q) class_number_condition = arel_table[:class_number].matches "#{q.delete('.')}%" description_condition = arel_table[:description].matches "%#{q}%" where(class_number_condition.or(description_condition)) end |
Instance Method Details
#children ⇒ Object
48 49 50 51 52 |
# File 'app/models/unico/material_class.rb', line 48 def children return [] if class_number_level == levels self.class.children(id, raw_class_number) end |
#class_number_level ⇒ Object
54 55 56 |
# File 'app/models/unico/material_class.rb', line 54 def class_number_level splitted_masked_number_filled.size end |
#editable? ⇒ Boolean
44 45 46 |
# File 'app/models/unico/material_class.rb', line 44 def editable? !imported? end |
#levels ⇒ Object
58 59 60 |
# File 'app/models/unico/material_class.rb', line 58 def levels mask.split('.').size end |
#parent ⇒ Object
40 41 42 |
# File 'app/models/unico/material_class.rb', line 40 def parent self.class.find_by_class_number(raw_parent_class_number) end |
#splitted_masked_number ⇒ Object
66 67 68 69 70 |
# File 'app/models/unico/material_class.rb', line 66 def splitted_masked_number return [] unless masked_number.present? masked_number.split('.') end |
#splitted_masked_number_filled ⇒ Object
72 73 74 |
# File 'app/models/unico/material_class.rb', line 72 def splitted_masked_number_filled splitted_masked_number.select { |level| level.to_i > 0 } end |
#to_s ⇒ Object
36 37 38 |
# File 'app/models/unico/material_class.rb', line 36 def to_s "#{masked_number} - #{description}" end |
#update_has_children ⇒ Object
62 63 64 |
# File 'app/models/unico/material_class.rb', line 62 def update_has_children update_column(:has_children, children.any?) end |