Class: Clienteer::Digester::IdealProteinCrossReference
- Inherits:
-
Object
- Object
- Clienteer::Digester::IdealProteinCrossReference
- Defined in:
- lib/clienteer/digesters/ideal_protein_cross_reference.rb
Instance Method Summary collapse
- #ask_for_verification(row) ⇒ Object
- #find_by_email(email) ⇒ Object
- #find_by_name(first:, last:) ⇒ Object
- #find_ideal_protein_client(row) ⇒ Object
-
#initialize ⇒ IdealProteinCrossReference
constructor
A new instance of IdealProteinCrossReference.
- #optimized_data ⇒ Object
- #process(row) ⇒ Object
Constructor Details
#initialize ⇒ IdealProteinCrossReference
Returns a new instance of IdealProteinCrossReference.
5 6 7 8 |
# File 'lib/clienteer/digesters/ideal_protein_cross_reference.rb', line 5 def initialize @data = JSON.parse File.read("data/ideal_protein.clean.json") optimized_data end |
Instance Method Details
#ask_for_verification(row) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/clienteer/digesters/ideal_protein_cross_reference.rb', line 50 def ask_for_verification(row) # text = [] # text << "\tVerification\t\t".underline.light_red.bold # text << "There was a problem matching #{row['full_name']} with an ideal protein client.".light_black # text << "" # text << "The client's data is:" + "#{row.inspect}".cyan # text << "Should I skip this person or not?".magenta.bold # print text.join("\n") # bool = IO.gets.chomp!.include?("y") nil end |
#find_by_email(email) ⇒ Object
46 47 48 |
# File 'lib/clienteer/digesters/ideal_protein_cross_reference.rb', line 46 def find_by_email(email) @data.find { |c| c["email"].downcase == email.downcase } end |
#find_by_name(first:, last:) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/clienteer/digesters/ideal_protein_cross_reference.rb', line 37 def find_by_name(first:, last:) first_letter = last[0] if @optimized_data[first_letter].nil? @data.find { |r| r["first_name"].downcase == first.downcase && r["last_name"].downcase == last.downcase } else @optimized_data.find { |r| r["first_name"].downcase == first.downcase && r["last_name"].downcase == last.downcase } end end |
#find_ideal_protein_client(row) ⇒ Object
33 34 35 |
# File 'lib/clienteer/digesters/ideal_protein_cross_reference.rb', line 33 def find_ideal_protein_client(row) person = find_by_email(row[:raw].email) || find_by_name(last: row[:raw].last_name, first: row[:raw].first_name) || ask_for_verification(row) end |
#optimized_data ⇒ Object
10 11 12 13 14 |
# File 'lib/clienteer/digesters/ideal_protein_cross_reference.rb', line 10 def optimized_data @optimized_data ||= @data.group_by do |c| ln = c["last_name"] end end |
#process(row) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/clienteer/digesters/ideal_protein_cross_reference.rb', line 16 def process(row) person = find_ideal_protein_client(row) if person.nil? row[:reason] = "ideal protein subscription not found" $skipped_people << row return nil end row.tap do |r| r["ideal_subscription_id"] = person["ideal_subscription_id"].to_i r["phase"] = person["phase"].to_i r["ideal_protein_birthday"] = person["birthday"] end rescue $stderr.puts(row.inspect) raise end |