Class: Gaku::Address

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/gaku/address.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.primaryObject



31
32
33
# File 'app/models/gaku/address.rb', line 31

def self.primary
  where(primary: true).first
end

.secondaryObject



35
36
37
# File 'app/models/gaku/address.rb', line 35

def self.secondary
  where(primary: false)
end

Instance Method Details

#campus_address?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'app/models/gaku/address.rb', line 52

def campus_address?
  addressable_type == 'Gaku::Campus'
end

#empty?Boolean

Returns:

  • (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_primaryObject



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

Returns:

  • (Boolean)


27
28
29
# File 'app/models/gaku/address.rb', line 27

def primary?
  primary
end

#state_textObject



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