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
- #to_s ⇒ Object
Class Method Details
.primary ⇒ Object
33 34 35 |
# File 'app/models/gaku/address.rb', line 33 def self.primary where(primary: true).first end |
.secondary ⇒ Object
37 38 39 |
# File 'app/models/gaku/address.rb', line 37 def self.secondary where(primary: false) end |
Instance Method Details
#campus_address? ⇒ Boolean
54 55 56 |
# File 'app/models/gaku/address.rb', line 54 def campus_address? addressable_type == 'Gaku::Campus' end |
#empty? ⇒ Boolean
49 50 51 52 |
# File 'app/models/gaku/address.rb', line 49 def empty? except_fields = %w(id created_at updated_at country_numcode) attributes.except(except_fields).all? { |_, v| v.nil? } end |
#make_primary ⇒ Object
23 24 25 26 27 |
# File 'app/models/gaku/address.rb', line 23 def make_primary addresses.where.not(id: id).update_all(primary: false) update_attribute(:primary, true) # update_primary_address_field end |
#primary? ⇒ Boolean
29 30 31 |
# File 'app/models/gaku/address.rb', line 29 def primary? primary end |
#state_text ⇒ Object
41 42 43 44 45 46 47 |
# File 'app/models/gaku/address.rb', line 41 def state_text if state state.abbr.blank? ? state.name : state.abbr else state_name end end |
#to_s ⇒ Object
19 20 21 |
# File 'app/models/gaku/address.rb', line 19 def to_s "#{city} #{address1}" end |