-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from ba-st/CollectionFormatter
Added CollectionFormatter
- Loading branch information
Showing
25 changed files
with
155 additions
and
23 deletions.
There are no files selected for viewing
9 changes: 0 additions & 9 deletions
9
source/Buoy-Collections-Tests.package/CircularIteratorTest.class/methodProperties.json
This file was deleted.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
source/Buoy-Collections-Tests.package/CollectionFormatterTest.class/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
I'm a CollectionFormatterTest, a test class for testing the behavior of CollectionFormatter |
6 changes: 6 additions & 0 deletions
6
source/Buoy-Collections-Tests.package/CollectionFormatterTest.class/instance/testFormat.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
tests | ||
testFormat | ||
|
||
| formatter | | ||
formatter := CollectionFormatter separatingWith: $,. | ||
self assert: (formatter format: #(1 2 3)) equals: '1, 2, 3' |
6 changes: 6 additions & 0 deletions
6
...ections-Tests.package/CollectionFormatterTest.class/instance/testFormatEmptyCollection.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
tests | ||
testFormatEmptyCollection | ||
|
||
| formatter | | ||
formatter := CollectionFormatter separatingWith: $, andLastWith: $y. | ||
self assert: (formatter format: #()) equals: String new |
8 changes: 8 additions & 0 deletions
8
source/Buoy-Collections-Tests.package/CollectionFormatterTest.class/instance/testFormatOn.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
tests | ||
testFormatOn | ||
|
||
| formatter stream | | ||
stream := WriteStream on: String new. | ||
formatter := CollectionFormatter separatingWith: $,. | ||
formatter format: #(1 2 3) on: stream. | ||
self assert: stream contents equals: '1, 2, 3' |
6 changes: 6 additions & 0 deletions
6
...ns-Tests.package/CollectionFormatterTest.class/instance/testFormatOneElementCollection.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
tests | ||
testFormatOneElementCollection | ||
|
||
| formatter | | ||
formatter := CollectionFormatter separatingWith: $, andLastWith: $y. | ||
self assert: (formatter format: #(1)) equals: '1' |
6 changes: 6 additions & 0 deletions
6
...CollectionFormatterTest.class/instance/testFormatTwoElementCollectionWithLastSeparator.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
tests | ||
testFormatTwoElementCollectionWithLastSeparator | ||
|
||
| formatter | | ||
formatter := CollectionFormatter separatingWith: $, andLastWith: $y. | ||
self assert: (formatter format: #(1 2)) equals: '1 y 2' |
9 changes: 9 additions & 0 deletions
9
...ons-Tests.package/CollectionFormatterTest.class/instance/testFormatWithElementFormater.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
tests | ||
testFormatWithElementFormater | ||
|
||
| formatter | | ||
|
||
formatter := CollectionFormatter | ||
separatingWith: $, | ||
applyingToEach: [ :element | '/<1p>/' expandMacrosWith: element ]. | ||
self assert: (formatter format: #(1 2 3)) equals: '/1/, /2/, /3/' |
6 changes: 6 additions & 0 deletions
6
...tions-Tests.package/CollectionFormatterTest.class/instance/testFormatWithLastSeparator.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
tests | ||
testFormatWithLastSeparator | ||
|
||
| formatter | | ||
formatter := CollectionFormatter separatingWith: $, andLastWith: $y. | ||
self assert: (formatter format: #(1 2 3)) equals: '1, 2 y 3' |
11 changes: 11 additions & 0 deletions
11
source/Buoy-Collections-Tests.package/CollectionFormatterTest.class/properties.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"commentStamp" : "fortizpenaloza 1/5/2018 14:55", | ||
"super" : "TestCase", | ||
"category" : "Buoy-Collections-Tests", | ||
"classinstvars" : [ ], | ||
"pools" : [ ], | ||
"classvars" : [ ], | ||
"instvars" : [ ], | ||
"name" : "CollectionFormatterTest", | ||
"type" : "normal" | ||
} |
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
source/Buoy-Collections.package/CircularIterator.class/methodProperties.json
This file was deleted.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
source/Buoy-Collections.package/CollectionFormatter.class/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
I'm a collection formatter allowing format a collection separating its elements with a provided separator. I allow to use a diferent separator for the last element and also a block to perform a element specific formatting. | ||
|
||
Implementation Notes: | ||
I use a index to detect the last element and use the specific separator if present. |
7 changes: 7 additions & 0 deletions
7
source/Buoy-Collections.package/CollectionFormatter.class/class/separatingWith..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
instance creation | ||
separatingWith: aSeparator | ||
|
||
^ self | ||
separatingWith: aSeparator | ||
andOptionallyLastWith: Optional unused | ||
applyingToEach: [ :element | element asString ] |
7 changes: 7 additions & 0 deletions
7
...e/Buoy-Collections.package/CollectionFormatter.class/class/separatingWith.andLastWith..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
instance creation | ||
separatingWith: aSeparator andLastWith: aLastSeparator | ||
|
||
^ self | ||
separatingWith: aSeparator | ||
andOptionallyLastWith: (Optional containing: aLastSeparator) | ||
applyingToEach: [ :element | element asString ] |
7 changes: 7 additions & 0 deletions
7
...ons.package/CollectionFormatter.class/class/separatingWith.andLastWith.applyingToEach..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
instance creation | ||
separatingWith: aSeparator andLastWith: aLastSeparator applyingToEach: anElementFormatter | ||
|
||
^ self | ||
separatingWith: aSeparator | ||
andOptionallyLastWith: (Optional containing: aLastSeparator) | ||
applyingToEach: anElementFormatter |
7 changes: 7 additions & 0 deletions
7
...e/CollectionFormatter.class/class/separatingWith.andOptionallyLastWith.applyingToEach..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
instance creation | ||
separatingWith: aSeparator andOptionallyLastWith: anOptionalSeparator applyingToEach: anElementFormatter | ||
|
||
^ self new | ||
initializeSeparatingEachWith: aSeparator | ||
andOptionallyLastWith: anOptionalSeparator | ||
applyingToEach: anElementFormatter |
7 changes: 7 additions & 0 deletions
7
...uoy-Collections.package/CollectionFormatter.class/class/separatingWith.applyingToEach..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
instance creation | ||
separatingWith: aSeparator applyingToEach: anElementFormatter | ||
|
||
^ self | ||
separatingWith: aSeparator | ||
andOptionallyLastWith: Optional unused | ||
applyingToEach: anElementFormatter |
4 changes: 4 additions & 0 deletions
4
source/Buoy-Collections.package/CollectionFormatter.class/instance/format..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
formatting | ||
format: aCollection | ||
|
||
^ self format: aCollection on: (WriteStream on: String new) |
19 changes: 19 additions & 0 deletions
19
source/Buoy-Collections.package/CollectionFormatter.class/instance/format.on..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
formatting | ||
format: aCollection on: aStream | ||
|
||
| index size | | ||
|
||
index := 1. | ||
size := aCollection size. | ||
|
||
aCollection | ||
do: [ :element | | ||
index := index + 1. | ||
aStream nextPutAll: (elementFormatter value: element) ] | ||
separatedBy: [ index = size | ||
ifTrue: [ lastSeparator | ||
withContentDo: [ :content | self put: content on: aStream ] | ||
ifUnused: [ self putSeparatorOn: aStream ] ] | ||
ifFalse: [ self putSeparatorOn: aStream ] ]. | ||
|
||
^aStream contents |
6 changes: 6 additions & 0 deletions
6
...tter.class/instance/initializeSeparatingEachWith.andOptionallyLastWith.applyingToEach..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
initialization | ||
initializeSeparatingEachWith: aSeparator andOptionallyLastWith: anOptional applyingToEach: aBlock | ||
|
||
separator := aSeparator. | ||
lastSeparator := anOptional. | ||
elementFormatter := aBlock |
7 changes: 7 additions & 0 deletions
7
source/Buoy-Collections.package/CollectionFormatter.class/instance/put.on..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
formatting | ||
put: aSeparator on: aStream | ||
|
||
^ aStream | ||
nextPut: Character space; | ||
nextPut: aSeparator; | ||
nextPut: Character space |
6 changes: 6 additions & 0 deletions
6
source/Buoy-Collections.package/CollectionFormatter.class/instance/putSeparatorOn..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
formatting | ||
putSeparatorOn: aStream | ||
|
||
^ aStream | ||
nextPut: separator; | ||
nextPut: Character space |
15 changes: 15 additions & 0 deletions
15
source/Buoy-Collections.package/CollectionFormatter.class/properties.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"commentStamp" : "fortizpenaloza 1/5/2018 14:55", | ||
"super" : "Object", | ||
"category" : "Buoy-Collections", | ||
"classinstvars" : [ ], | ||
"pools" : [ ], | ||
"classvars" : [ ], | ||
"instvars" : [ | ||
"separator", | ||
"elementFormatter", | ||
"lastSeparator" | ||
], | ||
"name" : "CollectionFormatter", | ||
"type" : "normal" | ||
} |
This file was deleted.
Oops, something went wrong.