Guest User

Untitled

a guest
Feb 20th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. require 'natural_language/log_entry_parsers/standard_parser'
  2.  
  3. class NumberDistanceParser < StandardParser
  4.  
  5. def regex
  6.  
  7. # matching "3 miles", "5k", etc
  8. /
  9. ( \d+ (?:\.\d+)? ) # match integer or float
  10. \s? # optional whitespace
  11. #{DISTANCE_POSSIBLE}
  12. /ix
  13.  
  14. end
  15.  
  16. def handle_match(match_data, curr_log_entry)
  17. le = curr_log_entry
  18.  
  19. unless le
  20. le = LogEntry.new
  21. end
  22.  
  23. le.user_distance = match_data[1]
  24. if match_data[2].upcase.starts_with?("M")
  25. le.user_unit = UserUnit.find_by_ref("MILES")
  26. elsif match_data[2].upcase.starts_with?("K")
  27. le.user_unit = UserUnit.find_by_ref("KILO")
  28. end
  29. le
  30. end
  31.  
  32. end
Add Comment
Please, Sign In to add comment