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

.clearObject



71
72
73
74
75
# File 'lib/city.rb', line 71

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

.featureObject



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

def self.feature
  where( :is_feature => true )
end

.for_homepageObject



96
97
98
99
100
101
102
# File 'lib/city.rb', line 96

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



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

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



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

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



115
116
117
118
119
# File 'lib/city.rb', line 115

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

.n_featuresObject



77
78
79
# File 'lib/city.rb', line 77

def self.n_features
  4
end

.non_featureObject



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

def self.non_feature
  where( :is_feature => false )
end

Instance Method Details

#add_newsitem(doc) ⇒ Object



108
109
110
111
112
113
# File 'lib/city.rb', line 108

def add_newsitem doc
  # puts! self.newsitems, "city newsitems are"
  if 'Video' == doc.class.name
    self.newsitems << Newsitem.new({ :descr => '', :username => '', :video => doc })
  end
end

#j_reports(args = {}) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/city.rb', line 81

def j_reports args = {}
  out =  []
  self.reports.each do |r| # .page( params[:reports_page] 
    rr = r.clone
    # rr[:photo_url] = r.photo.photo.url( :mini ) unless r.photo.blank?
    # rr[:photo_url] ||= '/assets/missing.png'
    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