0

I have a array like this:

["xxxxxxxxx", 448, "2016-08-29", 1, "Trading", 53, "Trading", 2016-06-03 00:00:00 -0500, 2016-06-03 00:00:00 -0500, "RBS", "USD", "United States Dollar", nil, 2016-10-08 00:00:00 -0500, 2016-09-08 00:00:00 -0500, "2016-09-08 00:00:00 -0500","lcz076", nil, 5, 2016-10-08 00:00:00 -0500, 2016-09-08 00:00:00 -0500, "9", 448, "P", nil]

And I need to match a value for this value only "2016-09-08 00:00:00"

How do I do that?

Billal Begueradj
  • 20,717
  • 43
  • 112
  • 130
Kiul Logoto
  • 131
  • 1
  • 8

2 Answers2

0

First convert all the dates into Strings

Then after set it to a variable a

a = ["xxxxxxxxx", 448, "2016-08-29", 1, "Trading", 53, "Trading", "2016-06-03 00:00:00 -0500, 2016-06-03 00:00:00 -0500"...

I noticed all of the dates of the type you wanted to check have -0500 so you can take out that part by looping in the array with this

new_str[i] = str.slice(0..(str.index('-0500')))

Now you can just use .include?("stuff here")

Muntasir Alam
  • 1,777
  • 2
  • 17
  • 26
0

Assuming you have:

a = ["xxxxxxxxx", 448, "2016-08-29", 1, "Trading", 53, "Trading", "2016-06-03 00:00:00 -0500", "2016-06-03 00:00:00 -0500", "RBS", "USD", "United States Dollar", nil, "2016-10-08 00:00:00 -0500", "2016-09-08 00:00:00 -0500", "2016-09-08 00:00:00 -0500", "lcz076", nil, 5, "2016-10-08 00:00:00 -0500", "2016-09-08 00:00:00 -0500", "9", 448, "P", nil] 

RSpec expectation should be:

matches = a.select{ |x| x.to_s.match("2016-09-08 00:00:00") }
expect(matches).not_to be_empty
Tan Nguyen
  • 3,281
  • 1
  • 18
  • 18