mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2025-12-12 12:22:12 +00:00
81 lines
2.3 KiB
Rust
81 lines
2.3 KiB
Rust
use std::string;
|
|
use std::vec;
|
|
|
|
pub struct Item {
|
|
pub name: string::String,
|
|
pub sell_in: i32,
|
|
pub quality: i32
|
|
}
|
|
|
|
impl Item {
|
|
pub fn new(name: String, sell_in: i32, quality: i32) -> Item {
|
|
Item {name: name, sell_in: sell_in, quality: quality}
|
|
}
|
|
}
|
|
|
|
pub struct GildedRose {
|
|
pub items: vec::Vec<Item>
|
|
}
|
|
|
|
impl GildedRose {
|
|
pub fn new(items: vec::Vec<Item>) -> GildedRose {
|
|
GildedRose {items: items}
|
|
}
|
|
|
|
pub fn update_quality(&mut self) {
|
|
for item in &mut self.items {
|
|
if item.name != "Aged Brie" && item.name != "Backstage passes to a TAFKAL80ETC concert" {
|
|
if item.quality > 0 {
|
|
if item.name != "Sulfuras, Hand of Ragnaros" {
|
|
item.quality = item.quality - 1;
|
|
}
|
|
}
|
|
} else {
|
|
if item.quality < 50
|
|
{
|
|
item.quality = item.quality + 1;
|
|
|
|
if item.name == "Backstage passes to a TAFKAL80ETC concert" {
|
|
if item.sell_in < 11 {
|
|
if item.quality < 50 {
|
|
item.quality = item.quality + 1;
|
|
}
|
|
}
|
|
|
|
if item.sell_in < 6 {
|
|
if item.quality < 50 {
|
|
item.quality = item.quality + 1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if item.name != "Sulfuras, Hand of Ragnaros" {
|
|
item.sell_in = item.sell_in - 1;
|
|
}
|
|
|
|
if item.sell_in < 0 {
|
|
if item.name != "Aged Brie" {
|
|
if item.name != "Backstage passes to a TAFKAL80ETC concert" {
|
|
if item.quality > 0 {
|
|
if item.name != "Sulfuras, Hand of Ragnaros" {
|
|
item.quality = item.quality - 1;
|
|
}
|
|
}
|
|
} else {
|
|
item.quality = item.quality - item.quality;
|
|
}
|
|
} else {
|
|
if item.quality < 50 {
|
|
item.quality = item.quality + 1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod test;
|