Skip to content

Commit

Permalink
feat: enhance NaiveText search
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasleger committed Nov 26, 2024
1 parent 23b2e11 commit 576a196
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 4 additions & 3 deletions lib/quote_reader/naive_text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def read_attributes
NUMBER_REFERENCE_REGEX = /n?[.°]/i
BETWEEN_LABEL_VALUE_REGEX = /\s+(?:#{NUMBER_REFERENCE_REGEX})?\s*(?::\s*)?/i
FRENCH_CHARACTER_REGEX = /[\wÀ-ÖØ-öø-ÿ]/i
PHONE_REGEX = /(?:\(?\+?33\)?)? ?(?:[\s.]*\d\d){5}/i # TODO: find better
PHONE_REGEX = /(?:\(?\+?33\)?)?\s?(?:[\s.]*\d\d){5}/i # TODO: find better

def self.find_adresse(text)
text[/Adresse\s*:\s*(#{FRENCH_CHARACTER_REGEX}+)/i, 1]
Expand All @@ -59,7 +59,7 @@ def self.find_capital(text)
end

def self.find_forme_juridique(text)
text[/Forme juridique\s*:\s*(SAS|SARL|EURL|#{FRENCH_CHARACTER_REGEX}+) ?/i, 1]
text[/\s+(SAS|SARL|EURL)\s+/, 1] || text[/Forme juridique\s*:\s*(#{FRENCH_CHARACTER_REGEX}+) ?/i, 1]
end

def self.find_iban(text)
Expand All @@ -79,7 +79,8 @@ def self.find_numero_devis(text)
end

def self.find_numero_tva(text)
text[/TVA(?:\s+intracommunautaire)?#{BETWEEN_LABEL_VALUE_REGEX}(FR\d{2}\s?\d{9})/i, 1]
text[/(FR\d{2}\s?\d{9})/i, 1]
# text[/TVA(?:\s+intra(?:communautaire)?)?#{BETWEEN_LABEL_VALUE_REGEX}(FR\d{2}\s?\d{9})/i, 1]
end

def self.find_prenom(text)
Expand Down
8 changes: 7 additions & 1 deletion spec/lib/quote_reader/naive_text_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@

describe ".find_forme_juridique" do
it "returns the forme_juridique" do
skip "Add test for find_forme_juridique"
expect(described_class.find_forme_juridique(" SAS ")).to eq("SAS")
expect(described_class.find_forme_juridique(" SARL ")).to eq("SARL")
expect(described_class.find_forme_juridique(" EURL ")).to eq("EURL")
end
end

Expand All @@ -137,6 +139,7 @@
describe ".find_numero_tva" do
it "returns the numero_tva" do
expect(described_class.find_numero_tva("TVA :FR10831861234")).to eq("FR10831861234")
expect(described_class.find_numero_tva("TVA intra FR86504321234")).to eq("FR86504321234")
expect(described_class.find_numero_tva("TVA intracommunautaire : FR86504321234")).to eq("FR86504321234")
end
end
Expand Down Expand Up @@ -169,6 +172,9 @@

describe ".find_telephone" do
it "returns the telephone" do
expect(described_class.find_telephone("01 23 45 67 89")).to eq("01 23 45 67 89")
# expect(described_class.find_telephone("+331 23 45 67 89")).to eq("+331 23 45 67 89") # TODO
# expect(described_class.find_telephone("+33 1 23 45 67 89")).to eq("+33 1 23 45 67 89") # TODO
expect(described_class.find_telephone(" (33) 01 23 45 67 89")).to eq("(33) 01 23 45 67 89")
end
end
Expand Down

0 comments on commit 576a196

Please sign in to comment.