Class: City

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document, Mongoid::Timestamps
Defined in:
lib/city.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.allObject



17
18
19
# File 'lib/city.rb', line 17

def self.all
  self.where( deleted_at: nil, is_active: true ).order_by( name: :desc )
end

.clearObject



56
57
58
59
60
# File 'lib/city.rb', line 56

def self.clear
  if Rails.env.test?
    City.all.each { |r| r.remove }
  end
end

.for_homepageObject



83
84
85
86
87
88
89
# File 'lib/city.rb', line 83

def self.for_homepage
  cities = City.all.order_by( :name => :asc )
  cities = cities.delete_if do |c|
    ( false == c.is_feature ) && ( 0 == c.galleries.length ) && ( 0 == c.reports.length )
  end
  return cities
end

.listObject



45
46
47
48
49
# File 'lib/city.rb', line 45

def self.list
  out = self.order_by( :name => :asc )
  # no_city = City.where( :cityname => 'no_city' ).first || City.create( :cityname => 'no_city', :name => 'No City' )
  [['', nil]] + out.map { |item| [ item.name, item.id ] }
end

.list_citynames(lang = 'en') ⇒ Object



51
52
53
54
# File 'lib/city.rb', line 51

def self.list_citynames lang = 'en'
  out = self.order_by( :name => :asc )
  [['', nil]] + out.map { |item| [ item['name_'+lang], item.cityname ] }
end

.method_missing(name, *args, &block) ⇒ Object



91
92
93
94
95
# File 'lib/city.rb', line 91

def self.method_missing name, *args, &block
  city = City.where( :cityname => name ).first
  return city if city
  super
end

.n_featuresObject



62
63
64
# File 'lib/city.rb', line 62

def self.n_features
  4
end

Instance Method Details

#j_reports(args = {}) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/city.rb', line 70

def j_reports args = {}
  out =  []
  self.reports.each do |r|
    rr = r.clone
    rr[:username] = r.user.username
    rr.created_at = r.created_at # pretty_date( r.created_at )
    rr[:tag_name] = r.tag.name unless r.tag.blank?
    rr[:tag_name] ||= ''
    out << rr
  end
  return out
end

#n_featuresObject



65
66
67
# File 'lib/city.rb', line 65

def n_features
  4
end

#slugObject



10
# File 'lib/city.rb', line 10

def slug; cityname; end

#slug=(s) ⇒ Object



11
# File 'lib/city.rb', line 11

def slug= s; cityname = s; end