Skip to content

Commit

Permalink
Now the RG generator can return all fields present in the document
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel3dartist committed Nov 20, 2023
1 parent 29ad123 commit a3550d3
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 6 deletions.
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,28 @@ print(cpf)
rg = fake.rg()
print(rg)
# MG86103044
# 86103044
rg = fake.rg(is_complete=True)
print(rg)
#{
# 'name':'Lucimara Santos Lemos',
# 'gender': 'F',
# 'birth': {
# 'day': '21/10/1954',
# 'cite':'Pocos de Caldas',
# 'state':'MG'
# },
# 'org': {
# 'name': 'PC',
# 'state': 'MG',
# },
# 'affiliation': {
# 'father': 'Ronaldo Castro Lemos',
# 'mother': 'Sophia Santos Lemos'
# },
# 'rg': MG88103067
# }
crm = fake.crm()
print(crm)
Expand Down
5 changes: 4 additions & 1 deletion pyFBIG/BR_names/name.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ def surname(self):
def gen_name(self, is_complete: bool = False):
rand_list: list = [self.gen_female_name(), self.gen_male_name()]
_index = randrange(0, 2)
gender: str = "M"
_name = rand_list[_index]
if _index < 1:
gender = 'F'
if is_complete == False:
return _name
else:
Expand All @@ -40,7 +43,7 @@ def gen_name(self, is_complete: bool = False):
rand_surname: str = self.gen_surname()
if surnames[0] != rand_surname:
surnames.append(rand_surname)
return _name + ' '+ surnames[0] + ' ' + surnames[1]
return {'name': _name + ' '+ surnames[0] + ' ' + surnames[1], 'gender': gender}

def gen_female_name(self):
female_name = self.female_name()
Expand Down
7 changes: 6 additions & 1 deletion pyFBIG/fake_br_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,13 @@ def crm(self, especial_char: bool = True, return_list: bool = False, is_complete
def rg(self, is_complete: bool= False):
"""
RG (Registro Geral) generation call function:
Args:
is_complete: Defines whether it will return a simple string containing just an RG number or
whether it will return a dictionary containing all information present in an RG
Returns:
Returns the generated RG numbers in string format.
Returns the generated RG fake data. It can return a string format (if is_complete is false) or a dictionary (if is_complete is True).
"""
rg_gen: Type[IGenerator] = RGGenerator()
rg_gen.is_complete = is_complete
Expand Down
26 changes: 26 additions & 0 deletions pyFBIG/igen_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,32 @@ def __init__(self):
def rand_num(self) -> int:
return randrange(0, 9)

def rand_birthday(self) -> str:
year: int = randrange(1920, 2023)
month: int = randrange(0, 12)
month_31days: list = [1,3,5,7,8,10,12]
day_range: int # Variable that determines the maximum number of days the month will have

if month in month_31days: # Determines the maximum number of days the month will have.
day_range = 31
elif month == 2: # Determines if the year is a leap year to adjust the maximum February days
if type(year/4) == float and type(year/400) == float or type(year/100) == int:
day_range = 28
else:
day_range = 29
else:
day_range = 30
day: int = randrange(0, day_range)

birthday: list = [day, month, year]
for i in range(0, 3):
index = i-1
if birthday[index] < 10:
birthday[index] = '0'+str(birthday[index])
else:
birthday[index] = str(birthday[index])
return '/'.join(birthday)

@abstractmethod
def gen(self):
pass
7 changes: 5 additions & 2 deletions pyFBIG/rg_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@ def gen(self):
if self.is_complete == False:
return rg
else:
_name = name.gen_name(is_complete=True)
person = name.gen_name(is_complete=True)
_name= person['name']
_gender = person['gender']
parents = self.parents_creator(_name= _name)
if parents['father'].split(' ')[0] == _name.split(' ')[0]:
_list = _name.split(' ')
_name = _list[0] + ' Junior ' + ' '.join(_list[1:])
rg_doc: dict = {
'name':_name,
'gender': _gender,
'birth': {
'birthday': '10/12/1991',
'day': self.rand_birthday(),
'cite':'Pocos de Caldas',
'state':'MG'
},
Expand Down
5 changes: 5 additions & 0 deletions tests/test_gen_rg.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ def test_product(self):
product.is_complete = True
result = product.gen()
assert type(result) == dict
birthday = result['birth']['day']
assert type(birthday) == str
list_birthday = birthday.split('/')
assert len(list_birthday) == 3
assert len(list_birthday[0]) == 2 and len(list_birthday[1]) == 2 and len(list_birthday[2]) == 4

if __name__ == "__main__":
TestGenRG.test_factory()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def test_gen_name(self):
result = _name.gen_name(is_complete=False)
assert type(result) == str
result = _name.gen_name(is_complete=True)
assert len(result.split(' ')) == 3
assert len(result['name'].split(' ')) == 3

def test_gen_male_name(self):
_name = Name()
Expand Down

0 comments on commit a3550d3

Please sign in to comment.