summaryrefslogtreecommitdiff
path: root/pharo-mooc/tiny-chat/src/TinyChat/TCMessage.class.st
blob: 64962a971eaa307a8ed56b40bf191ebd3d939583 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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
]