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



33
34
35
# File 'app/models/gaku/address.rb', line 33

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

.secondaryObject



37
38
39
# File 'app/models/gaku/address.rb', line 37

def self.secondary
  where(primary: false)
end

Instance Method Details

#campus_address?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'app/models/gaku/address.rb', line 54

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

#empty?Boolean

Returns:

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



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

Returns:

  • (Boolean)


29
30
31
# File 'app/models/gaku/address.rb', line 29

def primary?
  primary
end

#state_textObject



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_sObject



19
20
21
# File 'app/models/gaku/address.rb', line 19

def to_s
  "#{city} #{address1}"
end