Skip to content

Commit

Permalink
feat: 馃幐 Misc codes (Lunch, Prandium, MTID)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanObrink committed Apr 13, 2021
1 parent bf299ea commit 59e350b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
21 changes: 19 additions & 2 deletions src/index.test.ts
@@ -1,6 +1,23 @@
import parse from './'

describe('parse', () => {
it('Diverse', () => {
expect(parse('Lunch')).toEqual({
code: 'Lunch',
category: 'Diverse',
name: 'Lunch',
})
expect(parse('Prandium')).toEqual({
code: 'Prandium',
category: 'Diverse',
name: 'Lunch',
})
expect(parse('MTID')).toEqual({
code: 'MTID',
category: 'Diverse',
name: 'Mentorstid',
})
})
it('脛mnesomr氓den', () => {
expect(parse('BL')).toEqual({ code: 'BL', category: '', name: 'Bild' })
expect(parse('EN')).toEqual({ code: 'EN', category: '', name: 'Engelska' })
Expand Down Expand Up @@ -1054,8 +1071,8 @@ describe('parse', () => {
})
expect(parse('MTID Arbetslagsr氓d 7C')).toEqual({
code: 'MTID',
category: 'Ok盲nd',
name: 'MTID',
category: 'Diverse',
name: 'Mentorstid',
comment: 'Arbetslagsr氓d 7C',
})
})
Expand Down
25 changes: 21 additions & 4 deletions src/index.ts
Expand Up @@ -217,6 +217,12 @@ const languages: Repo = {
SPK: '脰vriga spr氓k',
}

const misc: Repo = {
Lunch: 'Lunch',
Prandium: 'Lunch',
MTID: 'Mentorstid',
}

type Parser = (code: string) => Subject | null
const parseSubject: Parser = (code) => {
if (!subjects[code]) return null
Expand Down Expand Up @@ -273,13 +279,24 @@ const parseNativeLanguage: Parser = (code) => {
}
}

const parseMisc: Parser = (code) => {
if (!misc[code]) return null

return {
code,
category: 'Diverse',
name: misc[code] as string,
}
}

const parse = (code: string): Subject => {
const [subjectCode, ...rest] = code.split(' ')
const result: Subject = parseSubject(subjectCode) ||
parseTrainingSubject(code) ||
parseLanguage(code) ||
parseAltLanguage(code) ||
parseNativeLanguage(code) || {
parseTrainingSubject(subjectCode) ||
parseLanguage(subjectCode) ||
parseAltLanguage(subjectCode) ||
parseNativeLanguage(subjectCode) ||
parseMisc(subjectCode) || {
code: subjectCode,
category: 'Ok盲nd',
name: subjectCode,
Expand Down

0 comments on commit 59e350b

Please sign in to comment.