Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ######### Goal:
- I need to either:
- A) Conditonally check & overwrite cell["c"] with a regex, if it matches a substring, before the record object is set,
- or,
- 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.
- Basically, I want to apply this regex:
- [0-9.]+
- 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:
- "as low as 1.98%"
- in order to yield only integers & a decimal point:
- 1.98
- ########## The "map" statement I am working with
- row.each_with_index { |cell, i|
- unique_id = "#{table_id}-#{cell["cellid"]}"
- record = {
- table_and_cell_id: unique_id,
- table_id: table_id,
- cell_id: cell["cellid"],
- first_column_description: column_descriptions.first,
- row_description: row_description,
- this_column_description: column_descriptions[i+1],
- value: cell["c"]
- }
- @logger.info "Record: #{record}"
- records.push record
- }
- ######## This is what I am attempting, but it isn't working--
- This code, between record = {...} and @logger.info "Record: #{record"
- hashObject.map { |k,v|
- if k == "value"
- v.include? "as low as"
- v = v.match /[0-9.]+/
- end }.to_h
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement