hope 0.1.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/Gemfile +11 -0
  2. data/LICENSE.txt +20 -0
  3. data/README.rdoc +19 -0
  4. data/bin/hope-web +16 -0
  5. data/hope.gemspec +34 -0
  6. data/lib/hope.rb +103 -0
  7. data/lib/hope/core_ext/object.rb +78 -0
  8. data/lib/hope/engine.rb +189 -0
  9. data/lib/hope/event_type.rb +22 -0
  10. data/lib/hope/jars/antlr-runtime-3.2.jar +0 -0
  11. data/lib/hope/jars/cglib-nodep-2.2.jar +0 -0
  12. data/lib/hope/jars/commons-logging-1.1.1.jar +0 -0
  13. data/lib/hope/jars/esper-4.3.0.jar +0 -0
  14. data/lib/hope/jars/log4j-1.2.16.jar +0 -0
  15. data/lib/hope/jars/msgpack-0.6.0-devel.jar +0 -0
  16. data/lib/hope/listener/base.rb +40 -0
  17. data/lib/hope/server.rb +43 -0
  18. data/lib/hope/server/app.rb +40 -0
  19. data/lib/hope/server/public/css/Aristo/images/bg_fallback.png +0 -0
  20. data/lib/hope/server/public/css/Aristo/images/icon_sprite.png +0 -0
  21. data/lib/hope/server/public/css/Aristo/images/progress_bar.gif +0 -0
  22. data/lib/hope/server/public/css/Aristo/images/slider_handles.png +0 -0
  23. data/lib/hope/server/public/css/Aristo/images/ui-icons_222222_256x240.png +0 -0
  24. data/lib/hope/server/public/css/Aristo/images/ui-icons_454545_256x240.png +0 -0
  25. data/lib/hope/server/public/css/Aristo/jquery-ui-1.8.7.custom.css +703 -0
  26. data/lib/hope/server/public/css/hope.css +235 -0
  27. data/lib/hope/server/public/favicon.ico +0 -0
  28. data/lib/hope/server/public/hope.js +995 -0
  29. data/lib/hope/server/public/js/backbone-0.3.3.js +1011 -0
  30. data/lib/hope/server/public/js/backbone-0.5.1.js +1149 -0
  31. data/lib/hope/server/public/js/hope.js +993 -0
  32. data/lib/hope/server/public/js/inflection.js +656 -0
  33. data/lib/hope/server/public/js/jquery-1.6.1.js +8936 -0
  34. data/lib/hope/server/public/js/jquery-ui-1.8.14.custom.min.js +789 -0
  35. data/lib/hope/server/public/js/underscore-1.1.6.js +807 -0
  36. data/lib/hope/server/resources/engine.rb +60 -0
  37. data/lib/hope/server/resources/source.rb +22 -0
  38. data/lib/hope/server/resources/statement.rb +62 -0
  39. data/lib/hope/server/views/app.erb +24 -0
  40. data/lib/hope/source.rb +20 -0
  41. data/lib/hope/source/base.rb +30 -0
  42. data/lib/hope/source/sub.rb +24 -0
  43. data/lib/hope/source/twitter.rb +123 -0
  44. data/lib/hope/statement.rb +73 -0
  45. data/lib/hope/version.rb +3 -0
  46. metadata +241 -0
@@ -0,0 +1,656 @@
1
+ /*
2
+ Copyright (c) 2010 Ryan Schuft (ryan.schuft@gmail.com)
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in
12
+ all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ THE SOFTWARE.
21
+ */
22
+
23
+ /*
24
+ This code is based in part on the work done in Ruby to support
25
+ infection as part of Ruby on Rails in the ActiveSupport's Inflector
26
+ and Inflections classes. It was initally ported to Javascript by
27
+ Ryan Schuft (ryan.schuft@gmail.com) in 2007.
28
+
29
+ The code is available at http://code.google.com/p/inflection-js/
30
+
31
+ The basic usage is:
32
+ 1. Include this script on your web page.
33
+ 2. Call functions on any String object in Javascript
34
+
35
+ Currently implemented functions:
36
+
37
+ String.pluralize(plural) == String
38
+ renders a singular English language noun into its plural form
39
+ normal results can be overridden by passing in an alternative
40
+
41
+ String.singularize(singular) == String
42
+ renders a plural English language noun into its singular form
43
+ normal results can be overridden by passing in an alterative
44
+
45
+ String.camelize(lowFirstLetter) == String
46
+ renders a lower case underscored word into camel case
47
+ the first letter of the result will be upper case unless you pass true
48
+ also translates "/" into "::" (underscore does the opposite)
49
+
50
+ String.underscore() == String
51
+ renders a camel cased word into words seperated by underscores
52
+ also translates "::" back into "/" (camelize does the opposite)
53
+
54
+ String.humanize(lowFirstLetter) == String
55
+ renders a lower case and underscored word into human readable form
56
+ defaults to making the first letter capitalized unless you pass true
57
+
58
+ String.capitalize() == String
59
+ renders all characters to lower case and then makes the first upper
60
+
61
+ String.dasherize() == String
62
+ renders all underbars and spaces as dashes
63
+
64
+ String.titleize() == String
65
+ renders words into title casing (as for book titles)
66
+
67
+ String.demodulize() == String
68
+ renders class names that are prepended by modules into just the class
69
+
70
+ String.tableize() == String
71
+ renders camel cased singular words into their underscored plural form
72
+
73
+ String.classify() == String
74
+ renders an underscored plural word into its camel cased singular form
75
+
76
+ String.foreign_key(dropIdUbar) == String
77
+ renders a class name (camel cased singular noun) into a foreign key
78
+ defaults to seperating the class from the id with an underbar unless
79
+ you pass true
80
+
81
+ String.ordinalize() == String
82
+ renders all numbers found in the string into their sequence like "22nd"
83
+ */
84
+
85
+ /*
86
+ This sets up a container for some constants in its own namespace
87
+ We use the window (if available) to enable dynamic loading of this script
88
+ Window won't necessarily exist for non-browsers.
89
+ */
90
+ if (window && !window.InflectionJS)
91
+ {
92
+ window.InflectionJS = null;
93
+ }
94
+
95
+ /*
96
+ This sets up some constants for later use
97
+ This should use the window namespace variable if available
98
+ */
99
+ InflectionJS =
100
+ {
101
+ /*
102
+ This is a list of nouns that use the same form for both singular and plural.
103
+ This list should remain entirely in lower case to correctly match Strings.
104
+ */
105
+ uncountable_words: [
106
+ 'equipment', 'information', 'rice', 'money', 'species', 'series',
107
+ 'fish', 'sheep', 'moose', 'deer', 'news'
108
+ ],
109
+
110
+ /*
111
+ These rules translate from the singular form of a noun to its plural form.
112
+ */
113
+ plural_rules: [
114
+ [new RegExp('(m)an$', 'gi'), '$1en'],
115
+ [new RegExp('(pe)rson$', 'gi'), '$1ople'],
116
+ [new RegExp('(child)$', 'gi'), '$1ren'],
117
+ [new RegExp('^(ox)$', 'gi'), '$1en'],
118
+ [new RegExp('(ax|test)is$', 'gi'), '$1es'],
119
+ [new RegExp('(octop|vir)us$', 'gi'), '$1i'],
120
+ [new RegExp('(alias|status)$', 'gi'), '$1es'],
121
+ [new RegExp('(bu)s$', 'gi'), '$1ses'],
122
+ [new RegExp('(buffal|tomat|potat)o$', 'gi'), '$1oes'],
123
+ [new RegExp('([ti])um$', 'gi'), '$1a'],
124
+ [new RegExp('sis$', 'gi'), 'ses'],
125
+ [new RegExp('(?:([^f])fe|([lr])f)$', 'gi'), '$1$2ves'],
126
+ [new RegExp('(hive)$', 'gi'), '$1s'],
127
+ [new RegExp('([^aeiouy]|qu)y$', 'gi'), '$1ies'],
128
+ [new RegExp('(x|ch|ss|sh)$', 'gi'), '$1es'],
129
+ [new RegExp('(matr|vert|ind)ix|ex$', 'gi'), '$1ices'],
130
+ [new RegExp('([m|l])ouse$', 'gi'), '$1ice'],
131
+ [new RegExp('(quiz)$', 'gi'), '$1zes'],
132
+ [new RegExp('s$', 'gi'), 's'],
133
+ [new RegExp('$', 'gi'), 's']
134
+ ],
135
+
136
+ /*
137
+ These rules translate from the plural form of a noun to its singular form.
138
+ */
139
+ singular_rules: [
140
+ [new RegExp('(m)en$', 'gi'), '$1an'],
141
+ [new RegExp('(pe)ople$', 'gi'), '$1rson'],
142
+ [new RegExp('(child)ren$', 'gi'), '$1'],
143
+ [new RegExp('([ti])a$', 'gi'), '$1um'],
144
+ [new RegExp('((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$','gi'), '$1$2sis'],
145
+ [new RegExp('(hive)s$', 'gi'), '$1'],
146
+ [new RegExp('(tive)s$', 'gi'), '$1'],
147
+ [new RegExp('(curve)s$', 'gi'), '$1'],
148
+ [new RegExp('([lr])ves$', 'gi'), '$1f'],
149
+ [new RegExp('([^fo])ves$', 'gi'), '$1fe'],
150
+ [new RegExp('([^aeiouy]|qu)ies$', 'gi'), '$1y'],
151
+ [new RegExp('(s)eries$', 'gi'), '$1eries'],
152
+ [new RegExp('(m)ovies$', 'gi'), '$1ovie'],
153
+ [new RegExp('(x|ch|ss|sh)es$', 'gi'), '$1'],
154
+ [new RegExp('([m|l])ice$', 'gi'), '$1ouse'],
155
+ [new RegExp('(bus)es$', 'gi'), '$1'],
156
+ [new RegExp('(o)es$', 'gi'), '$1'],
157
+ [new RegExp('(shoe)s$', 'gi'), '$1'],
158
+ [new RegExp('(cris|ax|test)es$', 'gi'), '$1is'],
159
+ [new RegExp('(octop|vir)i$', 'gi'), '$1us'],
160
+ [new RegExp('(alias|status)es$', 'gi'), '$1'],
161
+ [new RegExp('^(ox)en', 'gi'), '$1'],
162
+ [new RegExp('(vert|ind)ices$', 'gi'), '$1ex'],
163
+ [new RegExp('(matr)ices$', 'gi'), '$1ix'],
164
+ [new RegExp('(quiz)zes$', 'gi'), '$1'],
165
+ [new RegExp('s$', 'gi'), '']
166
+ ],
167
+
168
+ /*
169
+ This is a list of words that should not be capitalized for title case
170
+ */
171
+ non_titlecased_words: [
172
+ 'and', 'or', 'nor', 'a', 'an', 'the', 'so', 'but', 'to', 'of', 'at',
173
+ 'by', 'from', 'into', 'on', 'onto', 'off', 'out', 'in', 'over',
174
+ 'with', 'for'
175
+ ],
176
+
177
+ /*
178
+ These are regular expressions used for converting between String formats
179
+ */
180
+ id_suffix: new RegExp('(_ids|_id)$', 'g'),
181
+ underbar: new RegExp('_', 'g'),
182
+ space_or_underbar: new RegExp('[\ _]', 'g'),
183
+ uppercase: new RegExp('([A-Z])', 'g'),
184
+ underbar_prefix: new RegExp('^_'),
185
+
186
+ /*
187
+ This is a helper method that applies rules based replacement to a String
188
+ Signature:
189
+ InflectionJS.apply_rules(str, rules, skip, override) == String
190
+ Arguments:
191
+ str - String - String to modify and return based on the passed rules
192
+ rules - Array: [RegExp, String] - Regexp to match paired with String to use for replacement
193
+ skip - Array: [String] - Strings to skip if they match
194
+ override - String (optional) - String to return as though this method succeeded (used to conform to APIs)
195
+ Returns:
196
+ String - passed String modified by passed rules
197
+ Examples:
198
+ InflectionJS.apply_rules("cows", InflectionJs.singular_rules) === 'cow'
199
+ */
200
+ apply_rules: function(str, rules, skip, override)
201
+ {
202
+ if (override)
203
+ {
204
+ str = override;
205
+ }
206
+ else
207
+ {
208
+ var ignore = (skip.indexOf(str.toLowerCase()) > -1);
209
+ if (!ignore)
210
+ {
211
+ for (var x = 0; x < rules.length; x++)
212
+ {
213
+ if (str.match(rules[x][0]))
214
+ {
215
+ str = str.replace(rules[x][0], rules[x][1]);
216
+ break;
217
+ }
218
+ }
219
+ }
220
+ }
221
+ return str;
222
+ }
223
+ };
224
+
225
+ /*
226
+ This lets us detect if an Array contains a given element
227
+ Signature:
228
+ Array.indexOf(item, fromIndex, compareFunc) == Integer
229
+ Arguments:
230
+ item - Object - object to locate in the Array
231
+ fromIndex - Integer (optional) - starts checking from this position in the Array
232
+ compareFunc - Function (optional) - function used to compare Array item vs passed item
233
+ Returns:
234
+ Integer - index position in the Array of the passed item
235
+ Examples:
236
+ ['hi','there'].indexOf("guys") === -1
237
+ ['hi','there'].indexOf("hi") === 0
238
+ */
239
+ if (!Array.prototype.indexOf)
240
+ {
241
+ Array.prototype.indexOf = function(item, fromIndex, compareFunc)
242
+ {
243
+ if (!fromIndex)
244
+ {
245
+ fromIndex = -1;
246
+ }
247
+ var index = -1;
248
+ for (var i = fromIndex; i < this.length; i++)
249
+ {
250
+ if (this[i] === item || compareFunc && compareFunc(this[i], item))
251
+ {
252
+ index = i;
253
+ break;
254
+ }
255
+ }
256
+ return index;
257
+ };
258
+ }
259
+
260
+ /*
261
+ You can override this list for all Strings or just one depending on if you
262
+ set the new values on prototype or on a given String instance.
263
+ */
264
+ if (!String.prototype._uncountable_words)
265
+ {
266
+ String.prototype._uncountable_words = InflectionJS.uncountable_words;
267
+ }
268
+
269
+ /*
270
+ You can override this list for all Strings or just one depending on if you
271
+ set the new values on prototype or on a given String instance.
272
+ */
273
+ if (!String.prototype._plural_rules)
274
+ {
275
+ String.prototype._plural_rules = InflectionJS.plural_rules;
276
+ }
277
+
278
+ /*
279
+ You can override this list for all Strings or just one depending on if you
280
+ set the new values on prototype or on a given String instance.
281
+ */
282
+ if (!String.prototype._singular_rules)
283
+ {
284
+ String.prototype._singular_rules = InflectionJS.singular_rules;
285
+ }
286
+
287
+ /*
288
+ You can override this list for all Strings or just one depending on if you
289
+ set the new values on prototype or on a given String instance.
290
+ */
291
+ if (!String.prototype._non_titlecased_words)
292
+ {
293
+ String.prototype._non_titlecased_words = InflectionJS.non_titlecased_words;
294
+ }
295
+
296
+ /*
297
+ This function adds plurilization support to every String object
298
+ Signature:
299
+ String.pluralize(plural) == String
300
+ Arguments:
301
+ plural - String (optional) - overrides normal output with said String
302
+ Returns:
303
+ String - singular English language nouns are returned in plural form
304
+ Examples:
305
+ "person".pluralize() == "people"
306
+ "octopus".pluralize() == "octopi"
307
+ "Hat".pluralize() == "Hats"
308
+ "person".pluralize("guys") == "guys"
309
+ */
310
+ if (!String.prototype.pluralize)
311
+ {
312
+ String.prototype.pluralize = function(plural)
313
+ {
314
+ return InflectionJS.apply_rules(
315
+ this,
316
+ this._plural_rules,
317
+ this._uncountable_words,
318
+ plural
319
+ );
320
+ };
321
+ }
322
+
323
+ /*
324
+ This function adds singularization support to every String object
325
+ Signature:
326
+ String.singularize(singular) == String
327
+ Arguments:
328
+ singular - String (optional) - overrides normal output with said String
329
+ Returns:
330
+ String - plural English language nouns are returned in singular form
331
+ Examples:
332
+ "people".singularize() == "person"
333
+ "octopi".singularize() == "octopus"
334
+ "Hats".singularize() == "Hat"
335
+ "guys".singularize("person") == "person"
336
+ */
337
+ if (!String.prototype.singularize)
338
+ {
339
+ String.prototype.singularize = function(singular)
340
+ {
341
+ return InflectionJS.apply_rules(
342
+ this,
343
+ this._singular_rules,
344
+ this._uncountable_words,
345
+ singular
346
+ );
347
+ };
348
+ }
349
+
350
+ /*
351
+ This function adds camelization support to every String object
352
+ Signature:
353
+ String.camelize(lowFirstLetter) == String
354
+ Arguments:
355
+ lowFirstLetter - boolean (optional) - default is to capitalize the first
356
+ letter of the results... passing true will lowercase it
357
+ Returns:
358
+ String - lower case underscored words will be returned in camel case
359
+ additionally '/' is translated to '::'
360
+ Examples:
361
+ "message_properties".camelize() == "MessageProperties"
362
+ "message_properties".camelize(true) == "messageProperties"
363
+ */
364
+ if (!String.prototype.camelize)
365
+ {
366
+ String.prototype.camelize = function(lowFirstLetter)
367
+ {
368
+ var str = this.toLowerCase();
369
+ var str_path = str.split('/');
370
+ for (var i = 0; i < str_path.length; i++)
371
+ {
372
+ var str_arr = str_path[i].split('_');
373
+ var initX = ((lowFirstLetter && i + 1 === str_path.length) ? (1) : (0));
374
+ for (var x = initX; x < str_arr.length; x++)
375
+ {
376
+ str_arr[x] = str_arr[x].charAt(0).toUpperCase() + str_arr[x].substring(1);
377
+ }
378
+ str_path[i] = str_arr.join('');
379
+ }
380
+ str = str_path.join('::');
381
+ return str;
382
+ };
383
+ }
384
+
385
+ /*
386
+ This function adds underscore support to every String object
387
+ Signature:
388
+ String.underscore() == String
389
+ Arguments:
390
+ N/A
391
+ Returns:
392
+ String - camel cased words are returned as lower cased and underscored
393
+ additionally '::' is translated to '/'
394
+ Examples:
395
+ "MessageProperties".camelize() == "message_properties"
396
+ "messageProperties".underscore() == "message_properties"
397
+ */
398
+ if (!String.prototype.underscore)
399
+ {
400
+ String.prototype.underscore = function()
401
+ {
402
+ var str = this;
403
+ var str_path = str.split('::');
404
+ for (var i = 0; i < str_path.length; i++)
405
+ {
406
+ str_path[i] = str_path[i].replace(InflectionJS.uppercase, '_$1');
407
+ str_path[i] = str_path[i].replace(InflectionJS.underbar_prefix, '');
408
+ }
409
+ str = str_path.join('/').toLowerCase();
410
+ return str;
411
+ };
412
+ }
413
+
414
+ /*
415
+ This function adds humanize support to every String object
416
+ Signature:
417
+ String.humanize(lowFirstLetter) == String
418
+ Arguments:
419
+ lowFirstLetter - boolean (optional) - default is to capitalize the first
420
+ letter of the results... passing true will lowercase it
421
+ Returns:
422
+ String - lower case underscored words will be returned in humanized form
423
+ Examples:
424
+ "message_properties".humanize() == "Message properties"
425
+ "message_properties".humanize(true) == "message properties"
426
+ */
427
+ if (!String.prototype.humanize)
428
+ {
429
+ String.prototype.humanize = function(lowFirstLetter)
430
+ {
431
+ var str = this.toLowerCase();
432
+ str = str.replace(InflectionJS.id_suffix, '');
433
+ str = str.replace(InflectionJS.underbar, ' ');
434
+ if (!lowFirstLetter)
435
+ {
436
+ str = str.capitalize();
437
+ }
438
+ return str;
439
+ };
440
+ }
441
+
442
+ /*
443
+ This function adds capitalization support to every String object
444
+ Signature:
445
+ String.capitalize() == String
446
+ Arguments:
447
+ N/A
448
+ Returns:
449
+ String - all characters will be lower case and the first will be upper
450
+ Examples:
451
+ "message_properties".capitalize() == "Message_properties"
452
+ "message properties".capitalize() == "Message properties"
453
+ */
454
+ if (!String.prototype.capitalize)
455
+ {
456
+ String.prototype.capitalize = function()
457
+ {
458
+ var str = this.toLowerCase();
459
+ str = str.substring(0, 1).toUpperCase() + str.substring(1);
460
+ return str;
461
+ };
462
+ }
463
+
464
+ /*
465
+ This function adds dasherization support to every String object
466
+ Signature:
467
+ String.dasherize() == String
468
+ Arguments:
469
+ N/A
470
+ Returns:
471
+ String - replaces all spaces or underbars with dashes
472
+ Examples:
473
+ "message_properties".capitalize() == "message-properties"
474
+ "Message Properties".capitalize() == "Message-Properties"
475
+ */
476
+ if (!String.prototype.dasherize)
477
+ {
478
+ String.prototype.dasherize = function()
479
+ {
480
+ var str = this;
481
+ str = str.replace(InflectionJS.space_or_underbar, '-');
482
+ return str;
483
+ };
484
+ }
485
+
486
+ /*
487
+ This function adds titleize support to every String object
488
+ Signature:
489
+ String.titleize() == String
490
+ Arguments:
491
+ N/A
492
+ Returns:
493
+ String - capitalizes words as you would for a book title
494
+ Examples:
495
+ "message_properties".titleize() == "Message Properties"
496
+ "message properties to keep".titleize() == "Message Properties to Keep"
497
+ */
498
+ if (!String.prototype.titleize)
499
+ {
500
+ String.prototype.titleize = function()
501
+ {
502
+ var str = this.toLowerCase();
503
+ str = str.replace(InflectionJS.underbar, ' ');
504
+ var str_arr = str.split(' ');
505
+ for (var x = 0; x < str_arr.length; x++)
506
+ {
507
+ var d = str_arr[x].split('-');
508
+ for (var i = 0; i < d.length; i++)
509
+ {
510
+ if (this._non_titlecased_words.indexOf(d[i].toLowerCase()) < 0)
511
+ {
512
+ d[i] = d[i].capitalize();
513
+ }
514
+ }
515
+ str_arr[x] = d.join('-');
516
+ }
517
+ str = str_arr.join(' ');
518
+ str = str.substring(0, 1).toUpperCase() + str.substring(1);
519
+ return str;
520
+ };
521
+ }
522
+
523
+ /*
524
+ This function adds demodulize support to every String object
525
+ Signature:
526
+ String.demodulize() == String
527
+ Arguments:
528
+ N/A
529
+ Returns:
530
+ String - removes module names leaving only class names (Ruby style)
531
+ Examples:
532
+ "Message::Bus::Properties".demodulize() == "Properties"
533
+ */
534
+ if (!String.prototype.demodulize)
535
+ {
536
+ String.prototype.demodulize = function()
537
+ {
538
+ var str = this;
539
+ var str_arr = str.split('::');
540
+ str = str_arr[str_arr.length - 1];
541
+ return str;
542
+ };
543
+ }
544
+
545
+ /*
546
+ This function adds tableize support to every String object
547
+ Signature:
548
+ String.tableize() == String
549
+ Arguments:
550
+ N/A
551
+ Returns:
552
+ String - renders camel cased words into their underscored plural form
553
+ Examples:
554
+ "MessageBusProperty".tableize() == "message_bus_properties"
555
+ */
556
+ if (!String.prototype.tableize)
557
+ {
558
+ String.prototype.tableize = function()
559
+ {
560
+ var str = this;
561
+ str = str.underscore().pluralize();
562
+ return str;
563
+ };
564
+ }
565
+
566
+ /*
567
+ This function adds classification support to every String object
568
+ Signature:
569
+ String.classify() == String
570
+ Arguments:
571
+ N/A
572
+ Returns:
573
+ String - underscored plural nouns become the camel cased singular form
574
+ Examples:
575
+ "message_bus_properties".classify() == "MessageBusProperty"
576
+ */
577
+ if (!String.prototype.classify)
578
+ {
579
+ String.prototype.classify = function()
580
+ {
581
+ var str = this;
582
+ str = str.camelize().singularize();
583
+ return str;
584
+ };
585
+ }
586
+
587
+ /*
588
+ This function adds foreign key support to every String object
589
+ Signature:
590
+ String.foreign_key(dropIdUbar) == String
591
+ Arguments:
592
+ dropIdUbar - boolean (optional) - default is to seperate id with an
593
+ underbar at the end of the class name, you can pass true to skip it
594
+ Returns:
595
+ String - camel cased singular class names become underscored with id
596
+ Examples:
597
+ "MessageBusProperty".foreign_key() == "message_bus_property_id"
598
+ "MessageBusProperty".foreign_key(true) == "message_bus_propertyid"
599
+ */
600
+ if (!String.prototype.foreign_key)
601
+ {
602
+ String.prototype.foreign_key = function(dropIdUbar)
603
+ {
604
+ var str = this;
605
+ str = str.demodulize().underscore() + ((dropIdUbar) ? ('') : ('_')) + 'id';
606
+ return str;
607
+ };
608
+ }
609
+
610
+ /*
611
+ This function adds ordinalize support to every String object
612
+ Signature:
613
+ String.ordinalize() == String
614
+ Arguments:
615
+ N/A
616
+ Returns:
617
+ String - renders all found numbers their sequence like "22nd"
618
+ Examples:
619
+ "the 1 pitch".ordinalize() == "the 1st pitch"
620
+ */
621
+ if (!String.prototype.ordinalize)
622
+ {
623
+ String.prototype.ordinalize = function()
624
+ {
625
+ var str = this;
626
+ var str_arr = str.split(' ');
627
+ for (var x = 0; x < str_arr.length; x++)
628
+ {
629
+ var i = parseInt(str_arr[x]);
630
+ if (i === NaN)
631
+ {
632
+ var ltd = str_arr[x].substring(str_arr[x].length - 2);
633
+ var ld = str_arr[x].substring(str_arr[x].length - 1);
634
+ var suf = "th";
635
+ if (ltd != "11" && ltd != "12" && ltd != "13")
636
+ {
637
+ if (ld === "1")
638
+ {
639
+ suf = "st";
640
+ }
641
+ else if (ld === "2")
642
+ {
643
+ suf = "nd";
644
+ }
645
+ else if (ld === "3")
646
+ {
647
+ suf = "rd";
648
+ }
649
+ }
650
+ str_arr[x] += suf;
651
+ }
652
+ }
653
+ str = str_arr.join(' ');
654
+ return str;
655
+ };
656
+ }