summaryrefslogtreecommitdiff
path: root/pharo-mooc/tiny-chat/src/TinyChat
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2025-11-23 17:05:53 +0100
committerEugen Wissner <belka@caraus.de>2025-11-23 17:05:53 +0100
commitf3b3d4b1a26eba872c32ad95fc112650011b625c (patch)
tree483c90b08fb640f9f96b83393f64af9b7e752984 /pharo-mooc/tiny-chat/src/TinyChat
parentbf11813e4fa859a4833cab226c4ea560765d6d77 (diff)
downloadbook-exercises-f3b3d4b1a26eba872c32ad95fc112650011b625c.tar.gz
Add the tiny-chat project from the Pharo MOOC
Diffstat (limited to 'pharo-mooc/tiny-chat/src/TinyChat')
-rw-r--r--pharo-mooc/tiny-chat/src/TinyChat/TCMessage.class.st73
-rw-r--r--pharo-mooc/tiny-chat/src/TinyChat/package.st1
2 files changed, 74 insertions, 0 deletions
diff --git a/pharo-mooc/tiny-chat/src/TinyChat/TCMessage.class.st b/pharo-mooc/tiny-chat/src/TinyChat/TCMessage.class.st
new file mode 100644
index 0000000..64962a9
--- /dev/null
+++ b/pharo-mooc/tiny-chat/src/TinyChat/TCMessage.class.st
@@ -0,0 +1,73 @@
+Class {
+ #name : 'TCMessage',
+ #superclass : 'Object',
+ #instVars : [
+ 'sender',
+ 'text',
+ 'separator'
+ ],
+ #category : 'TinyChat',
+ #package : 'TinyChat'
+}
+
+{ #category : 'instance creation' }
+TCMessage class >> from: aSender text: aText [
+
+ ^ self new sender: aSender; text: aText; yourself
+]
+
+{ #category : 'instance creation' }
+TCMessage class >> fromString: aString [
+ ^ self new
+ fromString: aString;
+ yourself
+]
+
+{ #category : 'initialization' }
+TCMessage >> fromString: aString [
+ "Compose a message from a string of this form 'sender>message'."
+
+ | items |
+ items := aString substrings: separator.
+ self sender: items first.
+ self text: items second.
+]
+
+{ #category : 'initialization' }
+TCMessage >> initialize [
+ super initialize.
+ separator := '>'
+]
+
+{ #category : 'printing' }
+TCMessage >> printOn: aStream [
+ "Generate a string representation of the receiver based on its instance variables."
+
+ aStream
+ << self sender; << separator;
+ << self text; << String crlf
+]
+
+{ #category : 'accessing' }
+TCMessage >> sender [
+
+ ^ sender
+]
+
+{ #category : 'accessing' }
+TCMessage >> sender: anObject [
+
+ sender := anObject
+]
+
+{ #category : 'accessing' }
+TCMessage >> text [
+
+ ^ text
+]
+
+{ #category : 'accessing' }
+TCMessage >> text: anObject [
+
+ text := anObject
+]
diff --git a/pharo-mooc/tiny-chat/src/TinyChat/package.st b/pharo-mooc/tiny-chat/src/TinyChat/package.st
new file mode 100644
index 0000000..fe8e725
--- /dev/null
+++ b/pharo-mooc/tiny-chat/src/TinyChat/package.st
@@ -0,0 +1 @@
+Package { #name : 'TinyChat' }