Merge pull request #15 from Maikon/elixir-version

Add Elixir version
This commit is contained in:
Emily Bache 2015-09-20 20:44:26 +02:00
commit 3cb8ec5871
6 changed files with 68 additions and 0 deletions

1
elixir/config/config.exs Normal file
View File

@ -0,0 +1 @@
use Mix.Config

48
elixir/lib/gilded_rose.ex Normal file
View 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
View File

@ -0,0 +1,3 @@
defmodule Item do
defstruct name: nil, sell_in: nil, quality: nil
end

9
elixir/mix.exs Normal file
View 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

View File

@ -0,0 +1,6 @@
defmodule GildedRoseTest do
use ExUnit.Case
test "begin the journey of refactoring" do
end
end

View File

@ -0,0 +1 @@
ExUnit.start()