/app/models/spanish_to_english.rb
Ruby | 30 lines | 18 code | 6 blank | 6 comment | 0 complexity | 1e37144171abdb61105fd9b6e23a9b34 MD5 | raw file
- class SpanishToEnglish < ActiveRecord::Base
- set_table_name 'spanish_to_english'
- def self.random_words(num)
- #SpanishToEnglish.find(:all, :order => 'rand()', :limit => num)
- SpanishToEnglish.order('rand()').limit(num).all
- end
- # iterates over all records and saves lookup_keys
- def self.generate_lookup_keys
- #SpanishToEnglish.find(:all, :conditions => "lookup_key = ''").each do |word|
- SpanishToEnglish.where("lookup_key = ''").each do |word|
- lookup = word.spanish_word.gsub(/\(.*?\)/, '')
- # remove article from words
- lookup.gsub!(/(el|la) /, '')
- # split words at comma
- lookup_arr = lookup.split(",").collect do |lk|
- lk.strip!
- SpanishDictionary.map_word(lk)
- end
- word.lookup_key = lookup_arr.join(",")
- #word.lookup_key = SpanishDictionary.map_word(lookup)
- word.save
- end
- end
- end