Class: Gaku::Address
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Gaku::Address
- Defined in:
- app/models/gaku/address.rb
Class Method Summary collapse
Instance Method Summary collapse
- #campus_address? ⇒ Boolean
- #empty? ⇒ Boolean
- #make_primary ⇒ Object
- #primary? ⇒ Boolean
- #state_text ⇒ Object
Class Method Details
.primary ⇒ Object
31 32 33 |
# File 'app/models/gaku/address.rb', line 31 def self.primary where(primary: true).first end |
.secondary ⇒ Object
35 36 37 |
# File 'app/models/gaku/address.rb', line 35 def self.secondary where(primary: false) end |
Instance Method Details
#campus_address? ⇒ Boolean
52 53 54 |
# File 'app/models/gaku/address.rb', line 52 def campus_address? addressable_type == 'Gaku::Campus' end |
#empty? ⇒ Boolean
47 48 49 50 |
# File 'app/models/gaku/address.rb', line 47 def empty? except_fields = %w(id created_at updated_at country_numcode) attributes.except(except_fields).all? { |_, v| v.nil? } end |
#make_primary ⇒ Object
21 22 23 24 25 |
# File 'app/models/gaku/address.rb', line 21 def make_primary addresses.where.not(id: id).update_all(primary: false) update_attribute(:primary, true) update_primary_address_field end |
#primary? ⇒ Boolean
27 28 29 |
# File 'app/models/gaku/address.rb', line 27 def primary? primary end |
#state_text ⇒ Object
39 40 41 42 43 44 45 |
# File 'app/models/gaku/address.rb', line 39 def state_text if state state.abbr.blank? ? state.name : state.abbr else state_name end end |