Skip to content

Commit

Permalink
Adicionando o suplemento na legenda
Browse files Browse the repository at this point in the history
  • Loading branch information
jamilatta committed Jun 23, 2017
1 parent ecfd1a6 commit ee3a012
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 9 deletions.
14 changes: 11 additions & 3 deletions legendarium/legendarium.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
class Legendarium(object):

def __init__(self, acron_title='', year_pub='', volume='', number='',
fpage='', lpage='', article_id=''):
fpage='', lpage='', article_id='', suppl_number=''):

self.acron_title = acron_title
self.year_pub = str(year_pub)
self.volume = volume
self.number = number
self.suppl_number = suppl_number
self.fpage = fpage
self.lpage = lpage
self.article_id = article_id
Expand Down Expand Up @@ -68,6 +69,12 @@ def _clean_acron_title(self):
"""
return self.acron_title.strip()

def _clean_suppl_number(self):
"""
Clean the suppl_number stripped the beginning and the end of the string.
"""
return self.suppl_number.strip()

def get_journal(self):
"""
Method to build the journal, it can have ``year_pub`` or not.
Expand All @@ -87,9 +94,10 @@ def get_issue(self):
"""
volume = self._clean_volume()
number = self._clean_number()
suppl = self._clean_suppl_number()

if number:
number = u'({0})'.format(number)
if number or suppl:
number = u'({0}{1})'.format(number, '{0}suppl.{1}'.format(' ' if number else '', suppl) if suppl else '')

if volume or number:
return u'{0}{1}{2}'.format(';', volume, number)
Expand Down
41 changes: 35 additions & 6 deletions tests/test_legendarium.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def setUp(self):
'year_pub': u'2011',
'volume': u'67',
'number': u'9',
'suppl_number': u'3',
'fpage': u'154',
'lpage': u'200',
'article_id': u'e00120416'
Expand All @@ -19,7 +20,7 @@ def setUp(self):
def test_build_legend_with_all_param(self):
leg = Legendarium(**self.dict_leg)

self.assertEqual(u'Rev.Mal-Estar Subj 2011;67(9):e00120416', leg.stamp)
self.assertEqual(u'Rev.Mal-Estar Subj 2011;67(9 suppl.3):e00120416', leg.stamp)

def test_build_legend_without_acron_title(self):

Expand All @@ -31,6 +32,7 @@ def test_build_legend_without_acron_title(self):

def test_build_legend_without_year_pub(self):

del(self.dict_leg['suppl_number']) # Remove the suppl_number
del(self.dict_leg['year_pub']) # Remove the publisher year

leg = Legendarium(**self.dict_leg)
Expand All @@ -39,14 +41,16 @@ def test_build_legend_without_year_pub(self):

def test_build_legend_without_volume(self):

del(self.dict_leg['suppl_number']) # Remove the suppl_number
del(self.dict_leg['volume']) # Remove the volume

leg = Legendarium(**self.dict_leg)

self.assertEqual(u'Rev.Mal-Estar Subj 2011;(9):e00120416', leg.stamp)

def test_build_legend_without_number(self):
def test_build_legend_without_number_and_suppl_number(self):

del(self.dict_leg['suppl_number']) # Remove the suppl_number
del(self.dict_leg['number']) # Remove the number

leg = Legendarium(**self.dict_leg)
Expand All @@ -55,15 +59,17 @@ def test_build_legend_without_number(self):

def test_build_legend_without_volume_and_number(self):

del(self.dict_leg['suppl_number']) # Remove the suppl_number
del(self.dict_leg['volume']) # Remove the volume
del(self.dict_leg['number']) # Remove the number

leg = Legendarium(**self.dict_leg)

self.assertEqual(u'Rev.Mal-Estar Subj 2011:e00120416', leg.stamp)

def test_build_legend_without_volume_and_number_and_year_pub(self):
def test_build_legend_without_volume_and_number_and_year_pub_and_suppl_number(self):

del(self.dict_leg['suppl_number']) # Remove the suppl_number
del(self.dict_leg['volume']) # Remove the volume
del(self.dict_leg['number']) # Remove the number
del(self.dict_leg['year_pub']) # Remove the number
Expand All @@ -72,8 +78,19 @@ def test_build_legend_without_volume_and_number_and_year_pub(self):

self.assertEqual(u'Rev.Mal-Estar Subj:e00120416', leg.stamp)

def test_build_legend_without_volume_and_number_and_year_pub_and_pages(self):
def test_build_legend_without_volume_and_number_and_year_pub_(self):

del(self.dict_leg['volume']) # Remove the volume
del(self.dict_leg['number']) # Remove the number
del(self.dict_leg['year_pub']) # Remove the number

leg = Legendarium(**self.dict_leg)

self.assertEqual(u'Rev.Mal-Estar Subj;(suppl.3):e00120416', leg.stamp)

def test_build_legend_without_volume_and_number_and_year_pub_and_suppl_number_and_pages(self):

del(self.dict_leg['suppl_number']) # Remove the suppl_number
del(self.dict_leg['volume']) # Remove the volume
del(self.dict_leg['number']) # Remove the number
del(self.dict_leg['year_pub']) # Remove the publisher year
Expand Down Expand Up @@ -103,6 +120,7 @@ def test_build_legend_with_wrong_value_in_year_more_digits(self):

def test_build_legend_with_wrong_value_volume(self):

del(self.dict_leg['suppl_number']) # Remove the suppl_number
self.dict_leg['volume'] = "903A" # Wrong value in volume

leg = Legendarium(**self.dict_leg)
Expand All @@ -111,6 +129,7 @@ def test_build_legend_with_wrong_value_volume(self):

def test_build_legend_with_wrong_value_fpage(self):

del(self.dict_leg['suppl_number']) # Remove the suppl_number
del(self.dict_leg['article_id'])

self.dict_leg['fpage'] = "oja9sn10" # Wrong value in fpage, return wrong
Expand All @@ -121,6 +140,7 @@ def test_build_legend_with_wrong_value_fpage(self):

def test_build_legend_with_wrong_value_lpage(self):

del(self.dict_leg['suppl_number']) # Remove the suppl_number
del(self.dict_leg['article_id'])

self.dict_leg['lpage'] = "oja9sn10" # Wrong value in lpage, return wrong
Expand All @@ -131,6 +151,7 @@ def test_build_legend_with_wrong_value_lpage(self):

def test_build_legend_with_just_fpage(self):

del(self.dict_leg['suppl_number']) # Remove the suppl_number
del(self.dict_leg['lpage']) # Remove fpage
del(self.dict_leg['article_id']) # Remove elocation that is preference

Expand All @@ -140,6 +161,7 @@ def test_build_legend_with_just_fpage(self):

def test_build_legend_with_just_lpage(self):

del(self.dict_leg['suppl_number']) # Remove the suppl_number
del(self.dict_leg['fpage']) # Remove fpage
del(self.dict_leg['article_id']) # Remove elocation that is preference

Expand All @@ -149,6 +171,7 @@ def test_build_legend_with_just_lpage(self):

def test_build_legend_without_fpage_lpage_elocation(self):

del(self.dict_leg['suppl_number']) # Remove the suppl_number
del(self.dict_leg['fpage']) # Remove fpage
del(self.dict_leg['lpage']) # Remove lpage
del(self.dict_leg['article_id']) # Remove article_id
Expand All @@ -164,10 +187,11 @@ def test_build_legend_without_volume_number(self):

leg = Legendarium(**self.dict_leg)

self.assertEqual(u'Rev.Mal-Estar Subj 2011:e00120416', leg.stamp)
self.assertEqual(u'Rev.Mal-Estar Subj 2011;(suppl.3):e00120416', leg.stamp)

def test_build_legend_with_elocation(self):

del(self.dict_leg['suppl_number']) # Remove the suppl_number
del(self.dict_leg['fpage']) # Remove the fpage
del(self.dict_leg['lpage']) # Remove the lpage

Expand All @@ -181,16 +205,20 @@ def test_build_acron_title_with_diacritics(self):

leg = Legendarium(**self.dict_leg)

self.assertEqual(u'Acta Ortopédica Brasileira 2011;67(9):e00120416', leg.stamp)
self.assertEqual(u'Acta Ortopédica Brasileira 2011;67(9 suppl.3):e00120416', leg.stamp)

def test_build_acron_and_check_if_article_id_is_the_preference(self):

del(self.dict_leg['suppl_number']) # Remove the suppl_number

leg = Legendarium(**self.dict_leg)

self.assertEqual(u'Rev.Mal-Estar Subj 2011;67(9):e00120416', leg.stamp)

def test_build_acron_when_number_is_None(self):

del(self.dict_leg['suppl_number']) # Remove the suppl_number

self.dict_leg['number'] = None

leg = Legendarium(**self.dict_leg)
Expand All @@ -199,6 +227,7 @@ def test_build_acron_when_number_is_None(self):

def test_build_acron_when_volume_is_None(self):

del(self.dict_leg['suppl_number']) # Remove the suppl_number
self.dict_leg['volume'] = None

leg = Legendarium(**self.dict_leg)
Expand Down

0 comments on commit ee3a012

Please sign in to comment.