Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. ######### Goal:
  2.  
  3. I need to either:
  4. A) Conditonally check & overwrite cell["c"] with a regex, if it matches a substring, before the record object is set,
  5. or,
  6. B) simply map through the records object after it is setup, and overwrite the "value" (which is cell["c"]) with regex, where value matches a substring.
  7.  
  8. Basically, I want to apply this regex:
  9. [0-9.]+
  10.  
  11. on targeted string: any string (either record["value"] after its set, or cell["c"] before setting it into record) containing the words "as low as", such as:
  12. "as low as 1.98%"
  13.  
  14. in order to yield only integers & a decimal point:
  15. 1.98
  16.  
  17. ########## The "map" statement I am working with
  18.  
  19. row.each_with_index { |cell, i|
  20. unique_id = "#{table_id}-#{cell["cellid"]}"
  21. record = {
  22. table_and_cell_id: unique_id,
  23. table_id: table_id,
  24. cell_id: cell["cellid"],
  25. first_column_description: column_descriptions.first,
  26. row_description: row_description,
  27. this_column_description: column_descriptions[i+1],
  28. value: cell["c"]
  29. }
  30.  
  31. @logger.info "Record: #{record}"
  32. records.push record
  33. }
  34.  
  35. ######## This is what I am attempting, but it isn't working--
  36. This code, between record = {...} and @logger.info "Record: #{record"
  37.  
  38. hashObject.map { |k,v|
  39. if k == "value"
  40. v.include? "as low as"
  41. v = v.match /[0-9.]+/
  42. end }.to_h
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement