/app/models/spanish_to_english.rb

https://bitbucket.org/kapilnakhwa/demo-teachme · Ruby · 30 lines · 18 code · 6 blank · 6 comment · 0 complexity · 1e37144171abdb61105fd9b6e23a9b34 MD5 · raw file

  1. class SpanishToEnglish < ActiveRecord::Base
  2. set_table_name 'spanish_to_english'
  3. def self.random_words(num)
  4. #SpanishToEnglish.find(:all, :order => 'rand()', :limit => num)
  5. SpanishToEnglish.order('rand()').limit(num).all
  6. end
  7. # iterates over all records and saves lookup_keys
  8. def self.generate_lookup_keys
  9. #SpanishToEnglish.find(:all, :conditions => "lookup_key = ''").each do |word|
  10. SpanishToEnglish.where("lookup_key = ''").each do |word|
  11. lookup = word.spanish_word.gsub(/\(.*?\)/, '')
  12. # remove article from words
  13. lookup.gsub!(/(el|la) /, '')
  14. # split words at comma
  15. lookup_arr = lookup.split(",").collect do |lk|
  16. lk.strip!
  17. SpanishDictionary.map_word(lk)
  18. end
  19. word.lookup_key = lookup_arr.join(",")
  20. #word.lookup_key = SpanishDictionary.map_word(lookup)
  21. word.save
  22. end
  23. end
  24. end