You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2023/01/25 07:02:54 UTC
[groovy-website] branch asf-site updated: play with star font
This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch asf-site
in repository https://gitbox.apache.org/repos/asf/groovy-website.git
The following commit(s) were added to refs/heads/asf-site by this push:
new 3eba065 play with star font
3eba065 is described below
commit 3eba0655cbc3f32e3f587160b699b4bd7439a549
Author: Paul King <pa...@asert.com.au>
AuthorDate: Wed Jan 25 17:02:47 2023 +1000
play with star font
---
site/src/site/blog/fun-with-rating-stars.adoc | 54 +++++++++++++--------------
1 file changed, 27 insertions(+), 27 deletions(-)
diff --git a/site/src/site/blog/fun-with-rating-stars.adoc b/site/src/site/blog/fun-with-rating-stars.adoc
index 6689972..95fdf6e 100644
--- a/site/src/site/blog/fun-with-rating-stars.adoc
+++ b/site/src/site/blog/fun-with-rating-stars.adoc
@@ -14,36 +14,36 @@ Let's have a look at several ways to do the same thing in Groovy.
```
def rating0(percentage) {
int stars = Math.ceil(percentage * 10)
- ("⬤" * stars).padRight(10, "○")
+ ("🔵" * stars).padRight(10, "⚪")
}
```
```
def rating1(percentage) {
int stars = Math.ceil(percentage * 10)
- "⬤" * stars + "○" * (10-stars)
+ "🔵" * stars + "⚪" * (10-stars)
}
```
```
def rating2(percentage) {
int skip = 10 - Math.ceil(percentage * 10)
- "⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤○○○○○○○○○○"[skip..<10+skip]
+ "🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪"[skip..<10+skip]
}
```
```
def rating3(percentage) {
switch(percentage) {
- case 0 -> "○○○○○○○○○○"
- case { it <= 0.1 } -> "⬤○○○○○○○○○"
- case { it <= 0.2 } -> "⬤⬤○○○○○○○○"
- case { it <= 0.3 } -> "⬤⬤⬤○○○○○○○"
- case { it <= 0.4 } -> "⬤⬤⬤⬤○○○○○○"
- case { it <= 0.5 } -> "⬤⬤⬤⬤⬤○○○○○"
- case { it <= 0.6 } -> "⬤⬤⬤⬤⬤⬤○○○○"
- case { it <= 0.7 } -> "⬤⬤⬤⬤⬤⬤⬤○○○"
- case { it <= 0.8 } -> "⬤⬤⬤⬤⬤⬤⬤⬤○○"
- case { it <= 0.9 } -> "⬤⬤⬤⬤⬤⬤⬤⬤⬤○"
- default -> "⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤"
+ case 0 -> "⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪"
+ case { it <= 0.1 } -> "🔵⚪⚪⚪⚪⚪⚪⚪⚪⚪"
+ case { it <= 0.2 } -> "🔵🔵⚪⚪⚪⚪⚪⚪⚪⚪"
+ case { it <= 0.3 } -> "🔵🔵🔵⚪⚪⚪⚪⚪⚪⚪"
+ case { it <= 0.4 } -> "🔵🔵🔵🔵⚪⚪⚪⚪⚪⚪"
+ case { it <= 0.5 } -> "🔵🔵🔵🔵🔵⚪⚪⚪⚪⚪"
+ case { it <= 0.6 } -> "🔵🔵🔵🔵🔵🔵⚪⚪⚪⚪"
+ case { it <= 0.7 } -> "🔵🔵🔵🔵🔵🔵🔵⚪⚪⚪"
+ case { it <= 0.8 } -> "🔵🔵🔵🔵🔵🔵🔵🔵⚪⚪"
+ case { it <= 0.9 } -> "🔵🔵🔵🔵🔵🔵🔵🔵🔵⚪"
+ default -> "🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵"
}
}
```
@@ -67,7 +67,7 @@ We could simply add an assert, e.g.:
def rating4(percentage) {
assert percentage >= 0 && percentage <= 1
int stars = Math.ceil(percentage * 10)
- ("⬤" * stars).padRight(10, "○")
+ ("🔵" * stars).padRight(10, "⚪")
}
```
@@ -92,17 +92,17 @@ Which means we could tweak the rating method to be:
```
def rating5(Percent p) {
switch(p) {
- case 0.0d -> "○○○○○○○○○○"
- case 0.1d -> "⬤○○○○○○○○○"
- case 0.2d -> "⬤⬤○○○○○○○○"
- case 0.3d -> "⬤⬤⬤○○○○○○○"
- case 0.4d -> "⬤⬤⬤⬤○○○○○○"
- case 0.5d -> "⬤⬤⬤⬤⬤○○○○○"
- case 0.6d -> "⬤⬤⬤⬤⬤⬤○○○○"
- case 0.7d -> "⬤⬤⬤⬤⬤⬤⬤○○○"
- case 0.8d -> "⬤⬤⬤⬤⬤⬤⬤⬤○○"
- case 0.9d -> "⬤⬤⬤⬤⬤⬤⬤⬤⬤○"
- default -> "⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤"
+ case 0.0d -> "⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪"
+ case 0.1d -> "🔵⚪⚪⚪⚪⚪⚪⚪⚪⚪"
+ case 0.2d -> "🔵🔵⚪⚪⚪⚪⚪⚪⚪⚪"
+ case 0.3d -> "🔵🔵🔵⚪⚪⚪⚪⚪⚪⚪"
+ case 0.4d -> "🔵🔵🔵🔵⚪⚪⚪⚪⚪⚪"
+ case 0.5d -> "🔵🔵🔵🔵🔵⚪⚪⚪⚪⚪"
+ case 0.6d -> "🔵🔵🔵🔵🔵🔵⚪⚪⚪⚪"
+ case 0.7d -> "🔵🔵🔵🔵🔵🔵🔵⚪⚪⚪"
+ case 0.8d -> "🔵🔵🔵🔵🔵🔵🔵🔵⚪⚪"
+ case 0.9d -> "🔵🔵🔵🔵🔵🔵🔵🔵🔵⚪"
+ default -> "🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵"
}
}
```
@@ -116,7 +116,7 @@ Alternatively, we could use a design-by-contract approach:
@Requires({ percentage >= 0 && percentage <= 1 })
def rating6(percentage) {
int stars = Math.ceil(percentage * 10)
- ("⬤" * stars).padRight(10, "○")
+ ("🔵" * stars).padRight(10, "⚪")
}
```