I have a CLI App that scraps 5 different deals page and save it into @@all class variable. I want all of them to have a new variable which should start from 1 to 100(because there are total 100 deals). I tried a lot but it just shows number 1 for all the deals.
def deals_listing
all_deals = PopularDeals::NewDeals.all
@deals = []
all_deals.collect do |deal_info|
i = 1
deal_info.number = i
@deals << deal_info
i = i + 1
end
@deals
binding.pry
end
The sample of output that I am getting is..
pry(#<PopularDeals::CLI>)> @deals
=> [#<PopularDeals::NewDeals:0x00000001aaf220
@deal_rating="+7",
@number=1,
@posted="Posted Today",
@price="$7.64",
@title=
"Back Again at Amazon Campbell's Slow Cooker Sauces, Apple Bourbon Pulled Pork, 13 Ounce (Pack of 6) as low as $7.64 w/ Subscribe and Save S&S w/ Free Shipping",
@url=
"https://slickdeals.net/f/10033448-back-again-at-amazon-campbell-s-slow-cooker-sauces-apple-bourbon-pulled-pork-13-ounce-pack-of-6-as-low-as-7-64-w-subscribe-and-save-s-
s-w-free-shipping">,
#<PopularDeals::NewDeals:0x00000001a876f8
@deal_rating="+6",
@number=1,
@posted="Posted Today",
@price="$5.33",
@title=
"LUCKLED 20 LED Solar Powered Dragonfly String Lights Multi-color $5.33 AC, FS w/prime @Amazon",
@url=
ing-lights-multi-color-5-33-ac-fs-w-prime-amazon">,
#<PopularDeals::NewDeals:0x00000001a84228
@deal_rating="+6",
@number=1,
@posted="Posted Today",
@price="$339.99",
@title=
ping @ Walmart",
@url=
efurbished-339-99-free-shipping-walmart">,
#<PopularDeals::NewDeals:0x00000001a80ad8
@deal_rating="+6",
@number=1,
:
What I would like to have..
pry(#<PopularDeals::CLI>)> @deals
=> [#<PopularDeals::NewDeals:0x00000001aaf220
@deal_rating="+7",
@number=1,
@posted="Posted Today",
@price="$7.64",
@title=
"Back Again at Amazon Campbell's Slow Cooker Sauces, Apple Bourbon Pulled Pork, 13 Ounce (Pack of 6) as low as $7.64 w/ Subscribe and Save S&S w/ Free Shipping",
@url=
"https://slickdeals.net/f/10033448-back-again-at-amazon-campbell-s-slow-cooker-sauces-apple-bourbon-pulled-pork-13-ounce-pack-of-6-as-low-as-7-64-w-subscribe-and-save-s-
s-w-free-shipping">,
#<PopularDeals::NewDeals:0x00000001a876f8
@deal_rating="+6",
@number=2,
@posted="Posted Today",
@price="$5.33",
@title=
"LUCKLED 20 LED Solar Powered Dragonfly String Lights Multi-color $5.33 AC, FS w/prime @Amazon",
@url=
ing-lights-multi-color-5-33-ac-fs-w-prime-amazon">,
#<PopularDeals::NewDeals:0x00000001a84228
@deal_rating="+6",
@number=3,
@posted="Posted Today",
@price="$339.99",
@title=
ping @ Walmart",
@url=
efurbished-339-99-free-shipping-walmart">,
#<PopularDeals::NewDeals:0x00000001a80ad8
@deal_rating="+6",
@number=4,
:
Any suggestions to make it work? Thank you so much in advance.