;csv: refactor: rename JournalFieldName -> HledgerFieldName
This commit is contained in:
		
							parent
							
								
									be5fc09ebb
								
							
						
					
					
						commit
						a87baf4b29
					
				| @ -392,7 +392,7 @@ data CsvRules = CsvRules { | |||||||
|     -- ^ top-level rules, as (keyword, value) pairs |     -- ^ top-level rules, as (keyword, value) pairs | ||||||
|   rcsvfieldindexes   :: [(CsvFieldName, CsvFieldIndex)], |   rcsvfieldindexes   :: [(CsvFieldName, CsvFieldIndex)], | ||||||
|     -- ^ csv field names and their column number, if declared by a fields list |     -- ^ csv field names and their column number, if declared by a fields list | ||||||
|   rassignments       :: [(JournalFieldName, FieldTemplate)], |   rassignments       :: [(HledgerFieldName, FieldTemplate)], | ||||||
|     -- ^ top-level assignments to hledger fields, as (field name, value template) pairs |     -- ^ top-level assignments to hledger fields, as (field name, value template) pairs | ||||||
|   rconditionalblocks :: [ConditionalBlock] |   rconditionalblocks :: [ConditionalBlock] | ||||||
|     -- ^ conditional blocks, which containing additional assignments/rules to apply to matched csv records |     -- ^ conditional blocks, which containing additional assignments/rules to apply to matched csv records | ||||||
| @ -408,8 +408,9 @@ type CsvFieldName     = String | |||||||
| type CsvFieldIndex    = Int | type CsvFieldIndex    = Int | ||||||
| -- | Percent symbol followed by a CSV field name or column number. Eg: %date, %1. | -- | Percent symbol followed by a CSV field name or column number. Eg: %date, %1. | ||||||
| type CsvFieldReference = String | type CsvFieldReference = String | ||||||
| -- | One of the standard hledger field names that can be assigned to. | -- | One of the standard hledger fields or pseudo-fields that can be assigned to. | ||||||
| type JournalFieldName = String  -- XXX rename to HledgerFieldName | -- Eg date, account1, amount, amount1-in, date-format. | ||||||
|  | type HledgerFieldName = String | ||||||
| -- | A text value to be assigned to a hledger field, possibly | -- | A text value to be assigned to a hledger field, possibly | ||||||
| -- containing csv field references to be interpolated. | -- containing csv field references to be interpolated. | ||||||
| type FieldTemplate    = String | type FieldTemplate    = String | ||||||
| @ -433,7 +434,7 @@ data Matcher = | |||||||
| -- a field assignment, and executed in validateCsv. XXX) | -- a field assignment, and executed in validateCsv. XXX) | ||||||
| data ConditionalBlock = CB { | data ConditionalBlock = CB { | ||||||
|    cbMatchers    :: [Matcher] |    cbMatchers    :: [Matcher] | ||||||
|   ,cbAssignments :: [(JournalFieldName, FieldTemplate)] |   ,cbAssignments :: [(HledgerFieldName, FieldTemplate)] | ||||||
|   } deriving (Show, Eq) |   } deriving (Show, Eq) | ||||||
| 
 | 
 | ||||||
| defrules = CsvRules { | defrules = CsvRules { | ||||||
| @ -446,7 +447,7 @@ defrules = CsvRules { | |||||||
| addDirective :: (DirectiveName, String) -> CsvRules -> CsvRules | addDirective :: (DirectiveName, String) -> CsvRules -> CsvRules | ||||||
| addDirective d r = r{rdirectives=d:rdirectives r} | addDirective d r = r{rdirectives=d:rdirectives r} | ||||||
| 
 | 
 | ||||||
| addAssignment :: (JournalFieldName, FieldTemplate) -> CsvRules -> CsvRules | addAssignment :: (HledgerFieldName, FieldTemplate) -> CsvRules -> CsvRules | ||||||
| addAssignment a r = r{rassignments=a:rassignments r} | addAssignment a r = r{rassignments=a:rassignments r} | ||||||
| 
 | 
 | ||||||
| setIndexesAndAssignmentsFromList :: [CsvFieldName] -> CsvRules -> CsvRules | setIndexesAndAssignmentsFromList :: [CsvFieldName] -> CsvRules -> CsvRules | ||||||
| @ -602,7 +603,7 @@ quotedfieldnamep = do | |||||||
| barefieldnamep :: CsvRulesParser String | barefieldnamep :: CsvRulesParser String | ||||||
| barefieldnamep = some $ noneOf (" \t\n,;#~" :: [Char]) | barefieldnamep = some $ noneOf (" \t\n,;#~" :: [Char]) | ||||||
| 
 | 
 | ||||||
| fieldassignmentp :: CsvRulesParser (JournalFieldName, FieldTemplate) | fieldassignmentp :: CsvRulesParser (HledgerFieldName, FieldTemplate) | ||||||
| fieldassignmentp = do | fieldassignmentp = do | ||||||
|   lift $ dbgparse 3 "trying fieldassignmentp" |   lift $ dbgparse 3 "trying fieldassignmentp" | ||||||
|   f <- journalfieldnamep |   f <- journalfieldnamep | ||||||
| @ -800,8 +801,8 @@ transactionFromCsvRecord sourcepos rules record = t | |||||||
|     -- Helper to generate posting N, if sufficient fields have been assigned |     -- Helper to generate posting N, if sufficient fields have been assigned | ||||||
|     -- for it. N is provided as a string. |     -- for it. N is provided as a string. | ||||||
|     mkPosting :: |     mkPosting :: | ||||||
|       String -> JournalFieldName -> JournalFieldName -> JournalFieldName -> |       String -> HledgerFieldName -> HledgerFieldName -> HledgerFieldName -> | ||||||
|       JournalFieldName -> JournalFieldName -> JournalFieldName -> |       HledgerFieldName -> HledgerFieldName -> HledgerFieldName -> | ||||||
|       Maybe (Posting, Bool) |       Maybe (Posting, Bool) | ||||||
|     mkPosting number accountFld amountFld amountInFld amountOutFld balanceFld commentFld = |     mkPosting number accountFld amountFld amountInFld amountOutFld balanceFld commentFld = | ||||||
|       let currency = maybe (fromMaybe "" mdefaultcurrency) render $ |       let currency = maybe (fromMaybe "" mdefaultcurrency) render $ | ||||||
| @ -1048,14 +1049,14 @@ negateStr s       = '-':s | |||||||
| showRecord :: CsvRecord -> String | showRecord :: CsvRecord -> String | ||||||
| showRecord r = "the CSV record is:       "++intercalate "," (map show r) | showRecord r = "the CSV record is:       "++intercalate "," (map show r) | ||||||
| 
 | 
 | ||||||
| -- | Given the conversion rules, a CSV record and a journal entry field name, find | -- | Given the conversion rules, a CSV record and a hledger field name, find | ||||||
| -- the template value ultimately assigned to this field, if any, | -- the template value ultimately assigned to this field, if any, by a field | ||||||
| -- by a field assignment at top level or in a conditional block matching this record. | -- assignment at top level or in a conditional block matching this record. | ||||||
| -- | -- | ||||||
| -- Note conditional blocks' patterns are matched against an approximation of the | -- Note conditional blocks' patterns are matched against an approximation of the | ||||||
| -- CSV record: all the field values, without enclosing quotes, comma-separated. | -- CSV record: all the field values, without enclosing quotes, comma-separated. | ||||||
| -- | -- | ||||||
| getEffectiveAssignment :: CsvRules -> CsvRecord -> JournalFieldName -> Maybe FieldTemplate | getEffectiveAssignment :: CsvRules -> CsvRecord -> HledgerFieldName -> Maybe FieldTemplate | ||||||
| getEffectiveAssignment rules record f = lastMay $ map snd $ assignments | getEffectiveAssignment rules record f = lastMay $ map snd $ assignments | ||||||
|   where |   where | ||||||
|     -- all active assignments to field f, in order |     -- all active assignments to field f, in order | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user