mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2025-12-12 12:22:12 +00:00
Add Elixir version
This commit is contained in:
parent
db89751cac
commit
fef23beb31
1
elixir/config/config.exs
Normal file
1
elixir/config/config.exs
Normal file
@ -0,0 +1 @@
|
||||
use Mix.Config
|
||||
48
elixir/lib/gilded_rose.ex
Normal file
48
elixir/lib/gilded_rose.ex
Normal file
@ -0,0 +1,48 @@
|
||||
defmodule GildedRose do
|
||||
# Example
|
||||
# update_quality([%Item{name: "Backstage passes to a TAFKAL80ETC concert", sell_in: 9, quality: 1}])
|
||||
# => [%Item{name: "Backstage passes to a TAFKAL80ETC concert", sell_in: 9, quality: 3}]
|
||||
|
||||
def update_quality(items) do
|
||||
Enum.map(items, &update_item/1)
|
||||
end
|
||||
|
||||
def update_item(item) do
|
||||
cond do
|
||||
item.quality == 0 ->
|
||||
item
|
||||
item.sell_in < 0 && item.name == "Backstage passes to a TAFKAL80ETC concert" ->
|
||||
%{item | quality: 0}
|
||||
item.name == "Aged Brie" || item.name == "Backstage passes to a TAFKAL80ETC concert" ->
|
||||
if item.name == "Backstage passes to a TAFKAL80ETC concert" && item.sell_in > 5 && item.sell_in <= 10 do
|
||||
%{item | quality: item.quality + 2}
|
||||
else
|
||||
if item.name == "Backstage passes to a TAFKAL80ETC concert" && item.sell_in >= 0 && item.sell_in <= 5 do
|
||||
%{item | quality: item.quality + 3}
|
||||
else
|
||||
if item.quality < 50 do
|
||||
%{item | quality: item.quality + 1}
|
||||
else
|
||||
item
|
||||
end
|
||||
end
|
||||
end
|
||||
item.sell_in < 0 ->
|
||||
if item.name == "Backstage passes to a TAFKAL80ETC concert" do
|
||||
%{item | quality: 0}
|
||||
else
|
||||
if item.name == "+5 Dexterity Vest" || item.name == "Elixir of the Mongoose" do
|
||||
%{item | quality: item.quality - 2}
|
||||
else
|
||||
item
|
||||
end
|
||||
end
|
||||
item.name == "+5 Dexterity Vest" || item.name == "Elixir of the Mongoose" ->
|
||||
%{item | quality: item.quality - 1}
|
||||
item.name != "Sulfuras, Hand of Ragnaros" ->
|
||||
%{item | quality: item.quality - 1}
|
||||
true ->
|
||||
item
|
||||
end
|
||||
end
|
||||
end
|
||||
3
elixir/lib/item.ex
Normal file
3
elixir/lib/item.ex
Normal file
@ -0,0 +1,3 @@
|
||||
defmodule Item do
|
||||
defstruct name: nil, sell_in: nil, quality: nil
|
||||
end
|
||||
9
elixir/mix.exs
Normal file
9
elixir/mix.exs
Normal file
@ -0,0 +1,9 @@
|
||||
defmodule GildedRose.Mixfile do
|
||||
use Mix.Project
|
||||
|
||||
def project do
|
||||
[app: :gilded_rose,
|
||||
version: "0.0.1",
|
||||
elixir: "~> 1.0"]
|
||||
end
|
||||
end
|
||||
6
elixir/test/gilded_rose_test.exs
Normal file
6
elixir/test/gilded_rose_test.exs
Normal file
@ -0,0 +1,6 @@
|
||||
defmodule GildedRoseTest do
|
||||
use ExUnit.Case
|
||||
|
||||
test "begin the journey of refactoring" do
|
||||
end
|
||||
end
|
||||
1
elixir/test/test_helper.exs
Normal file
1
elixir/test/test_helper.exs
Normal file
@ -0,0 +1 @@
|
||||
ExUnit.start()
|
||||
Loading…
Reference in New Issue
Block a user