Class: City
- Inherits:
-
Object
- Object
- City
- Includes:
- AuxModel, Mongoid::Document, Mongoid::Timestamps
- Defined in:
- lib/city.rb
Class Method Summary collapse
- .all ⇒ Object
- .clear ⇒ Object
- .for_homepage ⇒ Object
- .list ⇒ Object
- .list_citynames(lang = 'en') ⇒ Object
- .method_missing(name, *args, &block) ⇒ Object
- .n_features ⇒ Object
Instance Method Summary collapse
Methods included from AuxModel
Class Method Details
.all ⇒ Object
18 19 20 |
# File 'lib/city.rb', line 18 def self.all self.where( deleted_at: nil, is_active: true ).order_by( name: :desc ) end |
.clear ⇒ Object
57 58 59 60 61 |
# File 'lib/city.rb', line 57 def self.clear if Rails.env.test? City.all.each { |r| r.remove } end end |
.for_homepage ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/city.rb', line 84 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 |
.list ⇒ Object
46 47 48 49 50 |
# File 'lib/city.rb', line 46 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
52 53 54 55 |
# File 'lib/city.rb', line 52 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
92 93 94 95 96 |
# File 'lib/city.rb', line 92 def self.method_missing name, *args, &block city = City.where( :cityname => name ).first return city if city super end |
.n_features ⇒ Object
63 64 65 |
# File 'lib/city.rb', line 63 def self.n_features 4 end |
Instance Method Details
#j_reports(args = {}) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/city.rb', line 71 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_features ⇒ Object
66 67 68 |
# File 'lib/city.rb', line 66 def n_features 4 end |
#slug ⇒ Object
11 |
# File 'lib/city.rb', line 11 def slug; cityname; end |
#slug=(s) ⇒ Object
12 |
# File 'lib/city.rb', line 12 def slug= s; cityname = s; end |