Skip to content

Commit

Permalink
redefine properties of fields
Browse files Browse the repository at this point in the history
  • Loading branch information
agrausem committed Nov 11, 2013
1 parent 5df490f commit 57660ac
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions pyromarc/mir.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,31 +69,27 @@ def __init__(self, tag, value='', indicators=None, subfields=None):

@property
def value(self):
if not self.has_subfields():
if self.is_control():
return self[1]
return None

@property
def indicators(self):
return self[2] if not self.is_control() else None

def is_control(self):
return not self.has_subfields() and len(self) == 2
return not isinstance(self[1], list) and len(self) == 2

def has_subfields(self):
return isinstance(self[1], list)

@property
def subfields(self):
if self.has_subfields():
if not self.is_control():
return self[1]
return None

def subfield(self, tag):
try:
if self.subfields:
return self.subfields[self.subfields.index(tag)]
except IndexError:
return None


class SubField(BaseField):
Expand Down

0 comments on commit 57660ac

Please sign in to comment.