- r jq: jaq -> jq, rm foreach

This commit is contained in:
Nitsan Avni 2024-01-05 09:21:12 +01:00
parent a1e48be19f
commit d5b430fde9
4 changed files with 51 additions and 53 deletions

View File

@ -1,6 +1,6 @@
# Installs # Requirements
[install jaq](https://github.com/01mf02/jaq#installation) (latest development version) jq
# Failing Unit Test # Failing Unit Test
@ -11,11 +11,11 @@
# TextTest Fixture # TextTest Fixture
```shell ```shell
jaq -nr "$(cat gilded-rose.jq) $(cat texttest_fixture.jq)" jq -nr "$(cat gilded-rose.jq) $(cat texttest_fixture.jq)"
``` ```
Specify days (e.g. 10 days): Specify days (e.g. 10 days):
```shell ```shell
jaq --arg days 10 -nr "$(cat gilded-rose.jq) $(cat texttest_fixture.jq)" jq --arg days 10 -nr "$(cat gilded-rose.jq) $(cat texttest_fixture.jq)"
``` ```

View File

@ -1,14 +1,13 @@
def update_quality: def update_quality:
[ [
foreach .[] as $item ( .[]
null; |
$item |
if .name != "Aged Brie" and .name != "Backstage passes to a TAFKAL80ETC concert" then if .name != "Aged Brie" and .name != "Backstage passes to a TAFKAL80ETC concert" then
if .quality > 0 then if .quality > 0 then
if .name != "Sulfuras, Hand of Ragnaros" then if .name != "Sulfuras, Hand of Ragnaros" then
.quality = .quality - 1 .quality = .quality - 1
else . end end
else . end end
else else
if .quality < 50 then if .quality < 50 then
.quality = .quality + 1 .quality = .quality + 1
@ -17,21 +16,21 @@ def update_quality:
if .sell_in < 11 then if .sell_in < 11 then
if .quality < 50 then if .quality < 50 then
.quality = .quality + 1 .quality = .quality + 1
else . end end
else . end end
| |
if .sell_in < 6 then if .sell_in < 6 then
if .quality < 50 then if .quality < 50 then
.quality = .quality + 1 .quality = .quality + 1
else . end end
else . end end
else . end end
else . end end
end end
| |
if .name != "Sulfuras, Hand of Ragnaros" then if .name != "Sulfuras, Hand of Ragnaros" then
.sell_in = .sell_in - 1 .sell_in = .sell_in - 1
else . end end
| |
if .sell_in < 0 then if .sell_in < 0 then
if .name != "Aged Brie" then if .name != "Aged Brie" then
@ -39,16 +38,15 @@ def update_quality:
if .quality > 0 then if .quality > 0 then
if .name != "Sulfuras, Hand of Ragnaros" then if .name != "Sulfuras, Hand of Ragnaros" then
.quality = .quality - 1 .quality = .quality - 1
else . end end
else . end end
else else
.quality = .quality - .quality .quality = .quality - .quality
end end
else else
if .quality < 50 then if .quality < 50 then
.quality = .quality + 1 .quality = .quality + 1
else . end
end end
else . end end
) end
]; ];

View File

@ -1,3 +1,3 @@
#!/usr/bin/env bash #!/usr/bin/env bash
jaq -en "$(cat gilded-rose.jq)"'[{name:"foo",sell_in:0,quality:0}] | update_quality | .[].name == "fixme"' jq -en "$(cat gilded-rose.jq)"'[{name:"foo",sell_in:0,quality:0}] | update_quality | .[].name == "fixme"'

View File

@ -12,7 +12,7 @@
{ name: "Conjured Mana Cake", sell_in: 3, quality: 6} # <-- :O { name: "Conjured Mana Cake", sell_in: 3, quality: 6} # <-- :O
] | ] |
{ items: ., day: 0 } | { items: ., day: 0 } |
recurse(.day += 1 | .items = (.items | update_quality); .day < ($ARGS.named.days // 2 | tonumber)) | recurse(.day += 1 | .items = (.items | update_quality); .day <= ($ARGS.named.days // 2 | tonumber)) |
( (
(["-------- day ", (.day | tostring), " --------"] | add), (["-------- day ", (.day | tostring), " --------"] | add),
("name, sellIn, quality"), ("name, sellIn, quality"),