Slide 151
Slide 151 text
@sandimetz Apr 2014
class
GildedRose
attr_reader
:name,
:quality,
:days_remaining
def
initialize(name,
quality,
days_remaining)
@name,
@quality,
@days_remaining
=
name,
quality,
days_remaining
end
def
tick
case
name
when
'normal'
normal_tick
when
'Aged
Brie'
brie_tick
when
'Sulfuras,
Hand
of
Ragnaros'
sulfuras_tick
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
backstage_tick
end
end
def
normal_tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
def
brie_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
def
sulfuras_tick
end
def
backstage_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
end
class
GildedRose
attr_reader
:name,
:quality,
:days_remaining
def
initialize(name,
quality,
days_remaining)
@name,
@quality,
@days_remaining
=
name,
quality,
days_remaining
end
def
tick
if
@name
!=
'Aged
Brie'
&&
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
if
@quality
<
50
@quality
+=
1
if
@name
==
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@days_remaining
<
11
if
@quality
<
50
@quality
+=
1
end
end
if
@days_remaining
<
6
if
@quality
<
50
@quality
+=
1
end
end
end
end
end
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@days_remaining
-‐=
1
end
if
@days_remaining
<
0
if
@name
!=
"Aged
Brie"
if
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
@quality
=
@quality
-‐
@quality
end
else
if
@quality
<
50
@quality
+=
1
end
end
end
end
end
big conditional small methods
94
Thursday, April 24, 14