Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e36849b
commit 97f4d5c
Showing
6 changed files
with
88 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,55 @@ | ||
import re | ||
|
||
class AbstractField(object): | ||
def __init__(self, line): | ||
self.value = line | ||
def process(self): | ||
raise NotImplementedError("process is not implemented") | ||
|
||
def is_valid(self): | ||
return True | ||
|
||
def error(self): | ||
return "" | ||
|
||
|
||
class AmountField(AbstractField): | ||
name = 'amount' | ||
def __init__(self, amount): | ||
#TODO: this is ugly, will be removed. Dash Yaniv. | ||
self.value = amount | ||
amount = amount.replace(',','') | ||
amount = amount.split('.')[0] | ||
self.amount = amount.strip() | ||
|
||
def is_valid(self): | ||
return None != re.match("^[-+]?[0-9]*$", self.amount) | ||
|
||
def process(self): | ||
if not self.is_valid(): | ||
raise Exception("Amount Field is not valied (%s)" %(self.value, )) | ||
if self.amount == '-' or self.amount == '': | ||
return 0 | ||
|
||
return abs(int(self.amount)) | ||
|
||
|
||
|
||
class CodeField(AbstractField): | ||
name = 'code' | ||
def process(self): | ||
return self.value.replace("-", '').replace(' ','') | ||
def is_valid(self): | ||
return '' != self.process() | ||
|
||
class DescriptionField(AbstractField): | ||
name = 'name' | ||
def process(self): | ||
return self.value | ||
|
||
import re | ||
|
||
class AbstractField(object): | ||
def __init__(self, line): | ||
self.value = line | ||
def process(self): | ||
raise NotImplementedError("process is not implemented") | ||
|
||
def is_valid(self): | ||
return True | ||
|
||
def error(self): | ||
return "" | ||
|
||
|
||
class AmountField(AbstractField): | ||
name = 'amount' | ||
def __init__(self, amount): | ||
#TODO: this is ugly, will be removed. Dash Yaniv. | ||
self.value = amount | ||
amount = amount.replace(',','') | ||
amount = amount.split('.')[0] | ||
self.amount = amount.strip() | ||
|
||
def is_valid(self): | ||
return None != re.match("^[-+]?[0-9]*$", self.amount) | ||
|
||
def process(self): | ||
if not self.is_valid(): | ||
raise Exception("Amount Field is not valid (%s)" %(self.value, )) | ||
if self.amount == '-' or self.amount == '': | ||
return 0 | ||
return abs(int(self.amount)) | ||
|
||
|
||
|
||
class CodeField(AbstractField): | ||
name = 'code' | ||
def process(self): | ||
return self.value.replace("-", '').replace(' ','') | ||
def is_valid(self): | ||
return '' != self.process() | ||
|
||
class CodeFieldAdd1(CodeField): | ||
def process(self): | ||
code = super(CodeFieldAdd1, self).process() | ||
if len(code) > 0: | ||
return '1'+code | ||
else: return '' | ||
|
||
class DescriptionField(AbstractField): | ||
name = 'name' | ||
def process(self): | ||
return self.value | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
from muni import AbstractMuni | ||
from fields import AmountField, CodeField, DescriptionField | ||
|
||
class HertzeliaMuni(AbstractMuni): | ||
MUNI = 'hertzelia' | ||
def __init__(self,**kwargs): | ||
super(HertzeliaMuni, self).__init__(**kwargs) | ||
self.data_fields.add_value({0: CodeField, | ||
5: DescriptionField, | ||
8: AmountField},2014) | ||
self.start_in_row.add_value(4,year=2014) | ||
self.data_fields.add_value({0: CodeField, | ||
5: DescriptionField, | ||
6: AmountField},2015) | ||
self.start_in_row.add_value(4,year=2015) | ||
self.data_fields.add_value({0: CodeField, | ||
5: DescriptionField, | ||
6: AmountField},2016) | ||
self.start_in_row.add_value(2,year=2016) | ||
from muni import AbstractMuni | ||
from fields import AmountField, CodeField, CodeFieldAdd1, DescriptionField | ||
|
||
class HertzeliaMuni(AbstractMuni): | ||
MUNI = 'hertzelia' | ||
def __init__(self,**kwargs): | ||
super(HertzeliaMuni, self).__init__(**kwargs) | ||
self.data_fields.add_value({0: CodeFieldAdd1, | ||
5: DescriptionField, | ||
8: AmountField}, 2014) | ||
self.start_in_row.add_value(4, year=2014) | ||
self.data_fields.add_value({0: CodeField, | ||
5: DescriptionField, | ||
6: AmountField}, 2015) | ||
self.start_in_row.add_value(4, year=2015) | ||
self.data_fields.add_value({0: CodeField, | ||
5: DescriptionField, | ||
6: AmountField}, 2016) | ||
self.start_in_row.add_value(2, year=2016) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters