command0
2010-Apr-17 19:53 UTC
Having trouble looping through an array of Regular Expressions in a Rake task
Hey guys, I was wondering if someone could give me some insight on an issue I''m having. I am working on a Rails app that will be a data efficient, user friendly New King James Version of the Bible. What I am presently doing is making a Rake task to build all the chapters to all of the books. So I created an array of Regex''s, to insert the expression to look for, but when I loop through the array, I''m getting an error, and not sure why. This is what I have: desc "Build All Chapters" task :build_all_chapters => :environment do require ''mechanize'' agent = Mechanize.new agent.get("http://www.biblegateway.com/versions/New-King-James- Version-NKJV-Bible/#booklist") books = Book.all.count i = 0 book_names = Array[/Genesis/, /Exodus/, /Leviticus/, /Numbers/, / Deuteronomy/, /Joshua/, /Judges/, /Ruth/, /1\+Samuel/, /2\+Samuel/, /1\+Kings/, /2\+Kings/, /1\ +Chronicles/, /2\+Chronicles/, /Ezra/, /Nehemiah/, /Esther/, /Job/, /Psalm/, / Proverbs/, /Ecclesiastes/, /Song\+of\+Solomon/, /Isaiah/, /Jeremiah/, /Lamentations/, /Ezekiel/, / Daniel/, / Hosea/, /Joel/, /Amos/, /Obadiah/, /Jonah/, /Micah/, /Nahum/, /Habakkuk/, /Zephaniah/, / Haggai/, /Zechariah/, /Malachi/, /Matthew/, /Mark/, /Luke/, /John/, /Acts/, /Romans/, /1\ +Corinthians/, /2\+Corinthians/, /Galatians/, /Ephesians/, /Philippians/, /Colossians/, /1\ +Thessalonians/, /2\+Thessalonians/, /1\+Timothy/, /2\+Timothy/, /Titus/, /Philemon/, /Hebrews/, / search\=James/, /1\+Peter/, /2\+Peter/, /1\+John/, /2\+John/, /3\+John/, /Jude/, /Revelation/] books.times do book_names.each do |book_title| chapters = agent.page.links_with(book_title).count Chapter.create!(:name => "Chapter #{i += 1}", :book_id => i +1) end end end I get the error: undefined method `all?'' for /Genesis/:Regexp I''m not sure what this error means, and I haven''t had much luck on Google... Thanks in advance for your help. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2010-Apr-18 09:28 UTC
Re: Having trouble looping through an array of Regular Expressions in a Rake task
On Apr 17, 8:53 pm, command0 <justinbrinkerh...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I get the error: > > undefined method `all?'' for /Genesis/:Regexp > > I''m not sure what this error means, and I haven''t had much luck on > Google...Looks like you''re calling links_with incorrectly - looks like links_with is expecting a hash (eg :title => some_regex, :href => some_other_regex ) rather than just a bare regular expression Fred> > Thanks in advance for your help. > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.