Skip to content

Commit

Permalink
Split BidsSidecar.parseHedStrings for Code Climate reasons
Browse files Browse the repository at this point in the history
  • Loading branch information
happy5214 committed Oct 19, 2023
1 parent cce7d96 commit 3a221c2
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions bids/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,27 +252,34 @@ export class BidsSidecar extends BidsJsonFile {
*/
parseHedStrings(hedSchemas) {
this.parsedHedData = new Map()
let issues = []
for (const [key, strings] of this.hedData) {
if (typeof strings === 'string') {
const [parsedString, parsingIssues] = parseHedString(strings, hedSchemas)
this.parsedHedData.set(key, parsedString)
issues = issues.concat(...Object.values(parsingIssues))
} else if (strings === Object(strings)) {
const keyMap = new Map()
for (const [value, string] of Object.entries(strings)) {
const [parsedString, parsingIssues] = parseHedString(string, hedSchemas)
keyMap.set(value, parsedString)
issues = issues.concat(...Object.values(parsingIssues))
}
this.parsedHedData.set(key, keyMap)
} else {
issues.push(generateIssue('illegalSidecarHedType', { key: key, file: this.name }))
}
const issues = []
for (const [key, value] of this.hedData) {
issues.push(...this._parseSidecarKey(key, value, hedSchemas))
}
return issues
}

_parseSidecarKey(key, data, hedSchemas) {
if (typeof data === 'string') {
return this._parseHedString(this.parsedHedData, key, data, hedSchemas)
} else if (data !== Object(data)) {
return [generateIssue('illegalSidecarHedType', { key: key, file: this.name })]
}
const issues = []
const keyMap = new Map()
for (const [value, string] of Object.entries(data)) {
issues.push(...this._parseHedString(keyMap, value, string, hedSchemas))
}
this.parsedHedData.set(key, keyMap)
return issues
}

_parseHedString(map, key, string, hedSchemas) {
const [parsedString, parsingIssues] = parseHedString(string, hedSchemas)
map.set(key, parsedString)
return Object.values(parsingIssues).flat()
}

/**
* The extracted HED strings.
* @returns {string[]}
Expand Down

0 comments on commit 3a221c2

Please sign in to comment.