mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2025-12-11 20:02:09 +00:00
use foreach for extra indentation
This commit is contained in:
parent
9abe955027
commit
9a2736d267
@ -1,49 +1,54 @@
|
||||
def update_quality:
|
||||
if .name != "Aged Brie" and .name != "Backstage passes to a TAFKAL80ETC concert" then
|
||||
if .quality > 0 then
|
||||
if .name != "Sulfuras, Hand of Ragnaros" then
|
||||
.quality = .quality - 1
|
||||
else . end
|
||||
else . end
|
||||
else
|
||||
if .quality < 50 then
|
||||
.quality = .quality + 1
|
||||
|
|
||||
if .name == "Backstage passes to a TAFKAL80ETC concert" then
|
||||
if .sell_in < 11 then
|
||||
if .quality < 50 then
|
||||
.quality = .quality + 1
|
||||
else . end
|
||||
else . end
|
||||
|
|
||||
if .sell_in < 6 then
|
||||
if .quality < 50 then
|
||||
.quality = .quality + 1
|
||||
else . end
|
||||
else . end
|
||||
else . end
|
||||
else . end
|
||||
end
|
||||
|
|
||||
if .name != "Sulfuras, Hand of Ragnaros" then
|
||||
.sell_in = .sell_in - 1
|
||||
else . end
|
||||
|
|
||||
if .sell_in < 0 then
|
||||
if .name != "Aged Brie" then
|
||||
if .name != "Backstage passes to a TAFKAL80ETC concert" then
|
||||
[
|
||||
foreach .[] as $item (
|
||||
null;
|
||||
$item |
|
||||
if .name != "Aged Brie" and .name != "Backstage passes to a TAFKAL80ETC concert" then
|
||||
if .quality > 0 then
|
||||
if .name != "Sulfuras, Hand of Ragnaros" then
|
||||
.quality = .quality - 1
|
||||
else . end
|
||||
else . end
|
||||
else
|
||||
.quality = .quality - .quality
|
||||
if .quality < 50 then
|
||||
.quality = .quality + 1
|
||||
|
|
||||
if .name == "Backstage passes to a TAFKAL80ETC concert" then
|
||||
if .sell_in < 11 then
|
||||
if .quality < 50 then
|
||||
.quality = .quality + 1
|
||||
else . end
|
||||
else . end
|
||||
|
|
||||
if .sell_in < 6 then
|
||||
if .quality < 50 then
|
||||
.quality = .quality + 1
|
||||
else . end
|
||||
else . end
|
||||
else . end
|
||||
else . end
|
||||
end
|
||||
else
|
||||
if .quality < 50 then
|
||||
.quality = .quality + 1
|
||||
|
|
||||
if .name != "Sulfuras, Hand of Ragnaros" then
|
||||
.sell_in = .sell_in - 1
|
||||
else . end
|
||||
end
|
||||
else . end
|
||||
;
|
||||
|
|
||||
if .sell_in < 0 then
|
||||
if .name != "Aged Brie" then
|
||||
if .name != "Backstage passes to a TAFKAL80ETC concert" then
|
||||
if .quality > 0 then
|
||||
if .name != "Sulfuras, Hand of Ragnaros" then
|
||||
.quality = .quality - 1
|
||||
else . end
|
||||
else . end
|
||||
else
|
||||
.quality = .quality - .quality
|
||||
end
|
||||
else
|
||||
if .quality < 50 then
|
||||
.quality = .quality + 1
|
||||
else . end
|
||||
end
|
||||
else . end
|
||||
)
|
||||
];
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
jaq -en "$(cat gilded-rose.jq)"'{name:"foo",sell_in:0,quality:0} | update_quality | .name == "fixme"'
|
||||
jaq -en "$(cat gilded-rose.jq)"'[{name:"foo",sell_in:0,quality:0}] | update_quality | .[].name == "fixme"'
|
||||
|
||||
@ -12,7 +12,7 @@
|
||||
{ name: "Conjured Mana Cake", sell_in: 3, quality: 6} # <-- :O
|
||||
] |
|
||||
{ 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),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user