My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# This class represents a physical commemorative plaque, which is either currently installed, or
# was once installed on a building, site or monument. Our definition of plaques is quite wide,
# encompassing 'traditional' blue plaques that commemorate a historic person's connection to a
# place, as well as plaques that commemorate buildings, events, and so on.
#
# === Attributes
# * +inscription+ - The text inscription on the plaque.
# * +inscription_is_stub+ - The inscription is incomplete and needs entering.
# * +erected_at+ - The date on which the plaque was erected. Optional.
# * +reference+ - An official reference number or identifier for the plaque. Sometimes marked on the actual plaque itself, sometimes only in promotional material. Optional.
# * +latitude+ - The latitude of the plaque's location (as a decimal). Optional.
# * +longitude+ - The longitude of the plaque's location (as a decimal). Optional.
# * +notes+ - A general purpose notes field for internal admin and data-collection purposes.
#
# === Associations
# * Location - The location where the plaque is (or was) installed. Optional.
# * Area - The area in which the plaque is (or was) installed. Optional.
# * Colour - The colour of the plaque. Optional.
# * Organisation - The organisation responsible for the plaque. Optional.
# * User - The user who first added the plaque to the website.
# * Language - The primary language of the inscripton on the plaque. Optional.
# * Photos - Photos of the plaque.
# * Verbs - The verbs used on the plaque's inscription.
class Plaque < ActiveRecord::Base

belongs_to :location, :counter_cache => true
has_one :area, :through => :location
belongs_to :colour, :counter_cache => true
belongs_to :organisation, :counter_cache => true
belongs_to :plaque_erected_year, :counter_cache => true
belongs_to :user, :counter_cache => true
belongs_to :language, :counter_cache => true
belongs_to :todo_item
# has_many :plaque_connections
has_many :personal_connections #, :through => :plaque_connections
has_many :photos
has_many :verbs, :through => :personal_connections

before_save :set_erected_year

named_scope :geolocated, :conditions => ["latitude IS NOT NULL"]
named_scope :ungeolocated, :conditions => {:latitude => nil}
named_scope :photographed, :conditions => ["photos_count > 0"]
named_scope :unphotographed, :conditions => {:photos_count => 0}
named_scope :coloured, :conditions => ["colour_id IS NOT NULL"]
named_scope :photographed_not_coloured, :conditions => ["photos_count > 0 AND colour_id IS NULL"]
named_scope :geo_no_location, :conditions => ["latitude IS NOT NULL AND location_id IS NULL"]
named_scope :detailed_address_no_geo, :conditions => ["latitude IS NULL AND 1 = ((SELECT name FROM locations WHERE locations.id = location_id) REGEXP '.*[0-9].*')"]
named_scope :no_connection, :conditions => {:plaque_connections_count => 0,:plaque_connections_count => nil }
named_scope :partial_inscription, :conditions => {:inscription_is_stub => 1 }
named_scope :partial_inscription_photo, :conditions => ["photos_count > 0 AND inscription_is_stub = 1"]

include ApplicationHelper
# validates_presence_of :latitude, :longtitude


def to_csv
[self.id, self.inscription_csv, self.organisation_name, self.erected_at_string, self.language_name, self.colour_name, self.location_name, self.area_name, self.country_name, "\"" + self.coordinates + "\""].join(",")
end

def inscription_csv
if self.inscription
'"' + self.inscription.gsub('"', '""') + '"'
else
""
end
end

def coordinates
if self.geolocated?
self.latitude.to_s + "," + self.longitude.to_s
else
""
end
end

def language_name
if self.language
self.language.name
else
""
end
end

def location_name
if self.location && self.location.name
'"' + self.location.name.gsub('"', '""') + '"'
else
""
end
end


def area_name
if self.location && self.location.area
self.location.area.name
else
""
end
end

def country_name
if self.location && self.location.area && self.location.area.country
self.location.area.country.name
else
""
end
end
def organisation_name
if self.organisation
self.organisation.name
else
""
end
end

def colour_name
if self.colour
self.colour.name
else
""
end
end

def location_string
if self.location
self.location.name
else
nil
end
end

def erected_at_string
if self.erected_at?
if self.erected_at.month == 1 && self.erected_at.day == 1
self.erected_at.year.to_s
else
self.erected_at.to_s
end
else
nil
end
end

def erected_at_string=(date)
if date.length == 4
self.erected_at = Date.parse(date + "-01-01")
else
self.erected_at = date
end
end

def parse_inscription
inscription = self.inscription
if inscription

inscription_regex = /\A(.+?),?\s(([a-z]+ed|was born|grew up|taught|wrote\s\'[a-zA-Zü\s]+\')(\sand\s(([a-z]+ed)|was born|grew up|taught|wrote\s\'[a-zA-Zü\s]+\'))?)\s(at\s)?(.+?)(\.?)\Z/

if inscription =~ inscription_regex

subject = inscription[inscription_regex, 1]
predicates = inscription[inscription_regex, 2]
object = inscription[inscription_regex, 8]



subjects = []

subjects_regex =
%r{
(
(
\'?[A-Z][a-züA-Z]+\'?| # First name
([A-Z]\.)+ # or initial
)
(
\s
(
[A-Z][a-züA-Z]+| # additional name
de\s[A-Z][a-zA-Zü]+| # or de
[A-Z]\.)|( # or initial - eg F.
\,\sEarl\sof[A-Z][a-z]+|
\salias\s\'[A-Za-z]+\'| # alias
\s\'[A-Z][a-z]+\'|
\sof\s[A-Z][a-z]+|
\s\([A-Z][A-Za-zü\s]+\)
))+
)
(\s\(c?[\d]{4}-c?[\d]{4}\))? # Dates - eg {1934-2004}
(
\,?\s # optional comma, followed by a space
[a-zA-Z\s\,\d\-\'\&]+ # roles
)?
}x


subject.gsub(subjects_regex) do |s|
subjects << s
end



subjects.each do |subject|

person = Person.find_or_create_by_name_and_dates_and_roles(subject)

predicates.split(" and ").each do |predicate|
verb = Verb.find_or_create_by_name(predicate)

if object =~ /here(\s(in\s)?\d{4}-\d{4})?\.?/
if self.location
location = self.location
if object =~ /here\s(in\s)?\d{4}-\d{4}?\.?/
# started_at = Date.today
# ended_at = Date.today
started_at = DateTime.parse(object[/here\s(in\s)?(\d{4})-\d{4}\.?/, 2] + "-01-01")
ended_at = DateTime.parse(object[/here\s(in\s)?\d{4}-(\d{4})\.?/, 2] + "-01-01")
personal_connection = PersonalConnection.new(:person => person, :verb => verb, :location => location, :started_at => started_at, :ended_at => ended_at, :plaque => self)
else
personal_connection = PersonalConnection.new(:person => person, :verb => verb, :location => location,:plaque => self)
end
else
# Can't create connection as 'here' refers to
# an unspecified location.
break
end
else
location = Location.find_or_create_by_name(object)
personal_connection = PersonalConnection.new(:person => person, :verb => verb, :location => location, :plaque => self)
end

personal_connection.save!

end
end
end

return self.personal_connections

end

end

def geolocated?
!(self.latitude.nil?)
end

def photographed?
self.photos_count > 0
end

def unparse_inscription
if self.personal_connections.size > 0
self.personal_connections.each do |personal_connection|
personal_connection.destroy
end
end
end

def first_person
if personal_connections.size > 0
personal_connections[0].person.name
else
return nil
end
end

def people
people = Array.new
self.personal_connections.each do |personal_connection|
if personal_connection.person != nil && personal_connection.person.name != ""
people << personal_connection.person
end
end
return people.uniq
end

def as_json(options={})
# this example ignores the user's options
super(:only => [:id, :inscription, :reference, :latitude, :longitude, :erected_at, :created_at, :updated_at], :include => {:photos => {:only => :url}, :colour => {:only => :name}, :language => {:only => [:name, :alpha2]}, :location => {:only => :name, :include => {:area => {:only => :name, :include => {:country => {:only => [:name, :alpha2]}}}}}, :organisation => {:only => :name}})
end

private

def set_erected_year
if self.erected_at?
plaque_erected_year = PlaqueErectedYear.find_or_create_by_name(self.erected_at.year.to_s)
self.plaque_erected_year = plaque_erected_year
end
end
end

Change log

r653 by bbtommorris on Feb 16, 2011   Diff
Fix: Plaque#geolocated? returns T even if
lat= 0.0

If you create a plaque where the latitude
is 0.0. it doesn't show up as being
geolocated due to this code. It is at
least theoretically possible to locate
something with a latitude of 0.0 including
a plaque deserving of membership in the
Open Plaques database.

This was discovered while testing for
...
Go to: 
Sign in to write a code review

Older revisions

r584 by simon.harriyott on Aug 30, 2010   Diff
 Issue 219 : 'needs full inscription'
flag
n.b. includes migration to be raked
r583 by simon.harriyott on Aug 30, 2010   Diff
 Issue 229 : todo item: plaques with no
connection defined
r582 by simon.harriyott on Aug 30, 2010   Diff
New to do list: plaques with a
detailed location but no geolocation.
"detailed" means having a number in
it, which could indicate a house
number or post code, which may be
...
All revisions of this file

File info

Size: 9677 bytes, 291 lines
Powered by Google Project Hosting