Skip to content

Commit

Permalink
Merge pull request #398 from rokostik/spreadsheet-dump
Browse files Browse the repository at this point in the history
Implement spreadsheet dump
  • Loading branch information
refaktor authored Nov 5, 2024
2 parents e776817 + c93bef6 commit 2c47408
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ dist/
tests/*.html
shell_*.rye
console_*.rye
console_*.rye.enc

buildtemp/main.rye
*.bson
Expand Down
30 changes: 28 additions & 2 deletions env/spreadsheet.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,34 @@ func (s Spreadsheet) Equal(o Object) bool {
}

func (s Spreadsheet) Dump(e Idxs) string {
// TODO
return fmt.Sprintf("\"serlization of %s is not yet supported\" ", s.Inspect(e))
var sb strings.Builder
sb.WriteString("spreadsheet {")

for _, col := range s.Cols {
sb.WriteString(" ")
sb.WriteString("\"")
sb.WriteString(col)
sb.WriteString("\"")
}
sb.WriteString(" } [")

for _, row := range s.Rows {
for _, val := range row.Values {
sb.WriteString(" ")
ryeVal := ToRyeValue(val)
if ryeVal != nil {
sb.WriteString(ryeVal.Dump(e))
} else {
sb.WriteString("_")
}
}
// Fill in missing columns (if they exist) with void (_)
for i := len(row.Values); i < len(s.Cols); i++ {
sb.WriteString(" _")
}
}
sb.WriteString(" ]")
return sb.String()
}

func (s SpreadsheetRow) GetKind() int {
Expand Down

0 comments on commit 2c47408

Please sign in to comment.