Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9240585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:12:51+00:00 2026-06-18T08:12:51+00:00

I have a rake task that is pretty simple and works as I expect.

  • 0

I have a rake task that is pretty simple and works as I expect.

 task :qualify => :environment do
 require 'classifier'
 # encoding: utf-8
 test = Skirt.where(:asin => "B007O9MXF0")
 w = %w{ rayon wool cotton polyester nylon spandex}  
a = test.first.content
b = test.first.title
c = a + b
w.each do |w|
    if c[/#{w}/]
        c = w
    else
        c
    end
end     

good ={}
skirt = Skirt.where(:quality => "Good")
skirt.each do |f|
    good[f.content] = [f.quality]   
end

bad = {}
skirt = Skirt.where(:quality => "Bad")
skirt.each do |f|
    bad[f.content] = [f.quality]    
end
classifier = Classifier::Bayes.new('Good', 'Bad')

good.each {|good| classifier.train_good "Good"}
bad.each {|bad| classifier.train_bad "Bad"}

puts classifier.classify(a), 
        c,
        test.first.color,
        a+b
    end

Now I am trying to get something a little more complex, but using the exact same idea and it does not work.
See the code below:
desc “Import details”
task :import_clean => :environment do

       require 'sucker'
       require 'mechanize'
       require 'nokogiri'
       require 'open-uri'
       require 'carrierwave'
       require 'rmagick'
       require 'csv'
       # encoding: utf-8

          skirt = Skirt.where(:quality => "Good")
good = {}   
skirt_type = ""

skirt.each do |f|
    content_title = f.content + f.title
    good[content_title] = [f.quality]   
end

bad = {}
skirt = Skirt.where(:quality => "Bad")
skirt.each do |f|
    content_title = f.content + f.title
    bad[content_title] = [f.quality]    
end
classifier = Classifier::Bayes.new('Good', 'Bad')

good.each {|good| classifier.train_good "Good"}

bad.each {|bad| classifier.train_bad "Bad"}


request = Sucker.new(
    :associate_tag => 'thenewoutpro-20',  
    :key    => 'AKIAJXNLXYCBU3NJAIJQ',
    :secret => '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',
    :locale => :us)

    request << {
         "Operation"     => "ItemSearch",
         "SearchIndex"   => "Apparel",
         "Keywords"      => ["women", "skirt"], 
         "ResponseGroup" => ["BrowseNodes"] }

        rep = request.get

         url = "#{rep.find('MoreSearchResultsUrl')}"
         new_url = url[2, url.length-4]


         agent = Mechanize.new
         agent.get(new_url)

i = (0..47)

    i.each do |i|

        b = "#{i}"
        item = "#result_" + b
        doc = agent.page.search(item)
        link = doc.css("a")[0]["href"]
        asin = link[-10,10]
        request2 = Sucker.new(
                        :associate_tag => 'thenewoutpro-20',  
                        :key    => 'KEY',
                        :secret => 'SECRET',
                        :locale => :us)     
        request2 << {
                    "Operation"     => "ItemLookup",
                    "IdType"        => "ASIN",
                    "ItemId"        => asin,
                    "ResponseGroup" => ["Large"] }

            response = request2.get
            images = response.find('LargeImage').first.to_a
            image_new = images[0].to_s
            image = image_new[8, image_new.length-9]
            color_string = response.find('Color')
            color = color_string[6, color_string.length]
            brand_string = response.find('Manufacturer')
            brand = brand_string[5, brand_string.length]
            content = response.find('Content')
            title = response.find('Title')
            combined = content + title
            f = %w{ polyester rayon nylon cotton silk chiffon wool knit jersey viscose corduroy velvet lace }
            s = %w{ pencil A-line mini maxi long pleated panel }
            p = %w{ pettite 'plus size' maternity }             

            f.each do |f|
                if combined[/#{f}/]
                    fabric = f
                    else
                    fabric = ""
                end
            end
            s.each do |s|
                a = combined[/#{s}/]
                if a > 0
                skirt_type = s              
                else
                skirt_type = ""
                end
            end
            p.each do |p|
                if combined[/#{p}/]
                    size = p
                else
                    size = "Regular"    
                end
            end

            quality = classifier.classify(combined)             


            Bottom.create!(          
                                        :asin => asin,
                                        :title => response.find('Title'),
                                        :price => response.find('FormattedPrice'),
                                :manufacturer => brand,
                                :content => response.find('Content'),
                                :color => color,
                                :fabric => fabric,
                                :size => size,
                                :skirt_type => skirt_type, 
                                :images => image,
                                :link => link)


    end
       end
     end

I get the following error when I try to run the rake: rake aborted!
can’t convert Regexp into Integer

The part I don’t understand is that the same portion of the code (using the hash within the Regexp to run over an array) is working just fine on rake task :qualify.

Any ideas?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T08:12:52+00:00Added an answer on June 18, 2026 at 8:12 am

    combined = (content + title).to_s

    in combined[regex], if combined is not a string, Ruby thinks you are accessing an Array and therefore expects regex to be an integer…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two simple rake tasks -- one that works and one that throws
I have a simple rake task which consumes pretty much data via ActiveRecord. (contacts
(I'm not using Rails) I have a rake task that sets the environment that
I have a rake task that pulls and parses JSON data over an SSL
In my rails application I have a rake task that reads emails using imap.
I have this little rake task: namespace :db do namespace :test do task :reset
I have a rake task that sends out the next 'x' invitations to join
I have a Rakefile with a Rake task that I would normally call from
I have a rake task that uploads a list of files via ftp. Copying
I have a rake task that performs a shell command. When I run it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.