Skip to content

Commit

Permalink
fix: パースが科目番号が空の行で終了する
Browse files Browse the repository at this point in the history
  • Loading branch information
SIY1121 committed Mar 30, 2021
1 parent 08ac23a commit 38b814b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "twinte-parser",
"version": "2.1.2",
"version": "2.1.3",
"description": "Twinte内部で使用するために開発されたKdBパーサ",
"private": false,
"main": "dist/index.js",
Expand Down
17 changes: 11 additions & 6 deletions src/parser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Course, Day, Module } from './types'
import { read as readXLSX, utils } from 'xlsx'
import {Course, Day, Module} from './types'
import {read as readXLSX, utils} from 'xlsx'
import * as assert from 'assert'

/**
Expand Down Expand Up @@ -63,7 +63,7 @@ const analyzeDayAndPeriod = (str: string): { day: Day; period: number }[] => {

//どのテストにも合格しなかったが空文字でなければ仮にunknownとする
if (str !== '' && result.length === 0)
result.push({ day: Day.Unknown, period: 0 })
result.push({day: Day.Unknown, period: 0})

return result
}
Expand Down Expand Up @@ -142,7 +142,7 @@ const analyzeRow = (columns: string[]) => {
const courseData: Course = {
code: columns[0],
name: columns[1],
credits: Number(columns[3]),
credits: !Number.isNaN(parseInt(columns[3])) ? Number(columns[3]) : 0,
type: Number(columns[2]),
overview: columns[9],
remarks: columns[10],
Expand Down Expand Up @@ -208,10 +208,15 @@ export default (data: Buffer): Course[] => {
const courses: Course[] = []

for (let r = 5; ; r++) {
// sheetの終端で終了
if (typeof sheet[utils.encode_cell({r, c: 0})] === 'undefined') break

const columns: string[] = []
for (let c = 0; c <= 16; c++)
columns.push(sheet[utils.encode_cell({ r, c })].v)
if (columns[0] === '') break
columns.push(sheet[utils.encode_cell({r, c})].v)

// 科目番号が空の行はスキップ
if (columns[0] === '') continue
courses.push(analyzeRow(columns))
}
return courses
Expand Down

0 comments on commit 38b814b

Please sign in to comment.