@icarusmx/creta 1.0.18 → 1.0.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/creta.js +6 -6
- package/lessons/lesson1-system-decomposition.js +108 -74
- package/package.json +1 -1
package/bin/creta.js
CHANGED
|
@@ -790,9 +790,9 @@ async function startEnunciadosSelectorInteractive() {
|
|
|
790
790
|
process.stdout.write('\x1b[H')
|
|
791
791
|
|
|
792
792
|
console.log("Los enunciados fundamentales son un conjunto de afirmaciones que tienen el propósito de ejercitar el pensamiento orientado a objetos de los estudiantes de Creta. Escogimos estos enunciados porque creemos que exhaustan los conceptos mínimos necesarios para entender el paradigma de la programación orientada a objetos.")
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
793
|
+
console.log("")
|
|
794
|
+
console.log("Elige qué enunciado te gustaría explorar:")
|
|
795
|
+
console.log("")
|
|
796
796
|
|
|
797
797
|
ENUNCIADOS.forEach((enunciado, index) => {
|
|
798
798
|
const isSelected = index === selectedIndex
|
|
@@ -989,9 +989,9 @@ async function startEnunciadosSelectorFallback() {
|
|
|
989
989
|
|
|
990
990
|
try {
|
|
991
991
|
console.log("Los enunciados fundamentales son un conjunto de afirmaciones que tienen el propósito de ejercitar el pensamiento orientado a objetos de los estudiantes de Creta. Escogimos estos enunciados porque creemos que exhaustan los conceptos mínimos necesarios para entender el paradigma de la programación orientada a objetos.")
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
992
|
+
console.log("")
|
|
993
|
+
console.log("Elige qué enunciado te gustaría explorar:")
|
|
994
|
+
console.log("")
|
|
995
995
|
|
|
996
996
|
ENUNCIADOS.forEach((enunciado, index) => {
|
|
997
997
|
// Format the enunciado text with proper indentation for lists
|
|
@@ -94,86 +94,84 @@ export class Lesson1SystemDecomposition {
|
|
|
94
94
|
console.clear()
|
|
95
95
|
console.log("Descomposición en objetos:")
|
|
96
96
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
console.log("━".repeat(50))
|
|
97
|
+
const bookCode = `class Book {
|
|
98
|
+
constructor(title, author, isbn) {
|
|
99
|
+
this.title = title
|
|
100
|
+
this.author = author
|
|
101
|
+
this.isbn = isbn
|
|
102
|
+
this.isLoaned = false
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
isAvailable() {
|
|
106
|
+
return !this.isLoaned
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
markAsLoaned() {
|
|
110
|
+
this.isLoaned = true
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
markAsReturned() {
|
|
114
|
+
this.isLoaned = false
|
|
115
|
+
}
|
|
116
|
+
}`
|
|
117
|
+
|
|
118
|
+
this.printCodeWithOutline("📄 Clase Book", bookCode)
|
|
120
119
|
|
|
121
120
|
await this.waitForEnter("\nPresiona Enter para ver User...")
|
|
122
121
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
console.log("━".repeat(50))
|
|
122
|
+
const userCode = `class User {
|
|
123
|
+
constructor(name, email, maxLoans = 3) {
|
|
124
|
+
this.name = name
|
|
125
|
+
this.email = email
|
|
126
|
+
this.maxLoans = maxLoans
|
|
127
|
+
this.currentLoans = []
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
canBorrow() {
|
|
131
|
+
return this.currentLoans.length < this.maxLoans
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
addLoan(loan) {
|
|
135
|
+
this.currentLoans.push(loan)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
removeLoan(loan) {
|
|
139
|
+
const index = this.currentLoans.indexOf(loan)
|
|
140
|
+
if (index > -1) this.currentLoans.splice(index, 1)
|
|
141
|
+
}
|
|
142
|
+
}`
|
|
143
|
+
|
|
144
|
+
this.printCodeWithOutline("📄 Clase User", userCode)
|
|
147
145
|
|
|
148
146
|
await this.waitForEnter("\nPresiona Enter para ver Loan...")
|
|
149
147
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
148
|
+
const loanCode = `class Loan {
|
|
149
|
+
constructor(user, book, durationDays = 14) {
|
|
150
|
+
this.user = user
|
|
151
|
+
this.book = book
|
|
152
|
+
this.startDate = new Date()
|
|
153
|
+
this.dueDate = new Date(Date.now() + durationDays * 24 * 60 * 60 * 1000)
|
|
154
|
+
this.returned = false
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
isOverdue() {
|
|
158
|
+
return !this.returned && new Date() > this.dueDate
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
calculateFine() {
|
|
162
|
+
if (!this.isOverdue()) return 0
|
|
163
|
+
const daysLate = Math.ceil((new Date() - this.dueDate) / (24 * 60 * 60 * 1000))
|
|
164
|
+
return daysLate * 5 // $5 por día
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
returnBook() {
|
|
168
|
+
this.returned = true
|
|
169
|
+
this.book.markAsReturned()
|
|
170
|
+
this.user.removeLoan(this)
|
|
171
|
+
}
|
|
172
|
+
}`
|
|
173
|
+
|
|
174
|
+
this.printCodeWithOutline("📄 Clase Loan", loanCode)
|
|
177
175
|
|
|
178
176
|
await this.waitForEnter("\nPresiona Enter para ver Library...")
|
|
179
177
|
|
|
@@ -268,6 +266,42 @@ export class Lesson1SystemDecomposition {
|
|
|
268
266
|
await this.waitForEnter("\n✨ ¡Lección 1 completada! Presiona Enter para continuar...")
|
|
269
267
|
}
|
|
270
268
|
|
|
269
|
+
formatCode(code) {
|
|
270
|
+
// ANSI color codes
|
|
271
|
+
const colors = {
|
|
272
|
+
keyword: '\x1b[35m', // magenta for keywords like class, constructor
|
|
273
|
+
property: '\x1b[32m', // green for this.property
|
|
274
|
+
string: '\x1b[33m', // yellow for strings
|
|
275
|
+
comment: '\x1b[90m', // gray for comments
|
|
276
|
+
reset: '\x1b[0m' // reset color
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
return code
|
|
280
|
+
.replace(/\b(class|constructor|return|if|const|let|new)\b/g, `${colors.keyword}$1${colors.reset}`)
|
|
281
|
+
.replace(/\bthis\./g, `${colors.property}this.${colors.reset}`)
|
|
282
|
+
.replace(/'([^']*)'/g, `${colors.string}'$1'${colors.reset}`)
|
|
283
|
+
.replace(/"([^"]*)"/g, `${colors.string}"$1"${colors.reset}`)
|
|
284
|
+
.replace(/\/\/.*$/gm, `${colors.comment}$&${colors.reset}`)
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
printCodeWithOutline(title, code) {
|
|
288
|
+
const border = '┌' + '─'.repeat(60) + '┐'
|
|
289
|
+
const bottomBorder = '└' + '─'.repeat(60) + '┘'
|
|
290
|
+
const titleLine = `│ ${title}${' '.repeat(60 - title.length - 1)}│`
|
|
291
|
+
|
|
292
|
+
console.log(`\n${border}`)
|
|
293
|
+
console.log(titleLine)
|
|
294
|
+
console.log('├' + '─'.repeat(60) + '┤')
|
|
295
|
+
|
|
296
|
+
code.split('\n').forEach(line => {
|
|
297
|
+
const formattedLine = this.formatCode(line)
|
|
298
|
+
const padding = ' '.repeat(Math.max(0, 58 - line.length))
|
|
299
|
+
console.log(`│ ${formattedLine}${padding}│`)
|
|
300
|
+
})
|
|
301
|
+
|
|
302
|
+
console.log(bottomBorder)
|
|
303
|
+
}
|
|
304
|
+
|
|
271
305
|
async waitForEnter(message) {
|
|
272
306
|
return new Promise((resolve) => {
|
|
273
307
|
this.rl.question(message, () => {
|