mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2025-12-12 12:22:12 +00:00
Merge pull request #2 from codecop/topull
add Eclipse and IDEA project settings and do some code formatting
This commit is contained in:
commit
370c77bb6b
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
.idea/workspace.xml
|
||||||
1
.idea/.name
Normal file
1
.idea/.name
Normal file
@ -0,0 +1 @@
|
|||||||
|
GuildedRose
|
||||||
23
.idea/compiler.xml
Normal file
23
.idea/compiler.xml
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="CompilerConfiguration">
|
||||||
|
<option name="DEFAULT_COMPILER" value="Javac" />
|
||||||
|
<resourceExtensions />
|
||||||
|
<wildcardResourcePatterns>
|
||||||
|
<entry name="!?*.java" />
|
||||||
|
<entry name="!?*.form" />
|
||||||
|
<entry name="!?*.class" />
|
||||||
|
<entry name="!?*.groovy" />
|
||||||
|
<entry name="!?*.scala" />
|
||||||
|
<entry name="!?*.flex" />
|
||||||
|
<entry name="!?*.kt" />
|
||||||
|
<entry name="!?*.clj" />
|
||||||
|
</wildcardResourcePatterns>
|
||||||
|
<annotationProcessing>
|
||||||
|
<profile default="true" name="Default" enabled="false">
|
||||||
|
<processorPath useClasspath="true" />
|
||||||
|
</profile>
|
||||||
|
</annotationProcessing>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
|
|
||||||
5
.idea/copyright/profiles_settings.xml
Normal file
5
.idea/copyright/profiles_settings.xml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<component name="CopyrightManager">
|
||||||
|
<settings default="">
|
||||||
|
<module2copyright />
|
||||||
|
</settings>
|
||||||
|
</component>
|
||||||
5
.idea/encodings.xml
Normal file
5
.idea/encodings.xml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" />
|
||||||
|
</project>
|
||||||
|
|
||||||
10
.idea/misc.xml
Normal file
10
.idea/misc.xml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="EntryPointsManager">
|
||||||
|
<entry_points version="2.0" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_5" assert-keyword="true" jdk-15="true" project-jdk-name="1.7" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
|
|
||||||
9
.idea/modules.xml
Normal file
9
.idea/modules.xml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/Java/Java.iml" filepath="$PROJECT_DIR$/Java/Java.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
|
|
||||||
5
.idea/scopes/scope_settings.xml
Normal file
5
.idea/scopes/scope_settings.xml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<component name="DependencyValidationManager">
|
||||||
|
<state>
|
||||||
|
<option name="SKIP_IMPORT_STATEMENTS" value="false" />
|
||||||
|
</state>
|
||||||
|
</component>
|
||||||
8
.idea/vcs.xml
Normal file
8
.idea/vcs.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="" />
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
|
|
||||||
7
Java/.classpath
Normal file
7
Java/.classpath
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="src" path=""/>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
|
||||||
|
<classpathentry kind="output" path=""/>
|
||||||
|
</classpath>
|
||||||
1
Java/.gitignore
vendored
Normal file
1
Java/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
*.class
|
||||||
17
Java/.project
Normal file
17
Java/.project
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>GildedRose.java</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
||||||
22
Java/Java.iml
Normal file
22
Java/Java.iml
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="false">
|
||||||
|
<output url="file://$MODULE_DIR$" />
|
||||||
|
<output-test url="file://$MODULE_DIR$" />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$" isTestSource="true" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
<orderEntry type="module-library">
|
||||||
|
<library>
|
||||||
|
<CLASSES>
|
||||||
|
<root url="jar://$APPLICATION_HOME_DIR$/lib/junit-4.10.jar!/" />
|
||||||
|
</CLASSES>
|
||||||
|
<JAVADOC />
|
||||||
|
<SOURCES />
|
||||||
|
</library>
|
||||||
|
</orderEntry>
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
|
|
||||||
123
Java/com/gildedrose/GildedRose.java
Executable file → Normal file
123
Java/com/gildedrose/GildedRose.java
Executable file → Normal file
@ -1,61 +1,62 @@
|
|||||||
package com.gildedrose;
|
package com.gildedrose;
|
||||||
class GildedRose {
|
|
||||||
Item[] items;
|
class GildedRose {
|
||||||
|
Item[] items;
|
||||||
public GildedRose(Item[] items) {
|
|
||||||
this.items = items;
|
public GildedRose(Item[] items) {
|
||||||
}
|
this.items = items;
|
||||||
|
}
|
||||||
public void updateQuality() {
|
|
||||||
for (int i = 0; i < items.length; i++) {
|
public void updateQuality() {
|
||||||
if (!items[i].name.equals("Aged Brie")
|
for (int i = 0; i < items.length; i++) {
|
||||||
&& !items[i].name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
if (!items[i].name.equals("Aged Brie")
|
||||||
if (items[i].quality > 0) {
|
&& !items[i].name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
||||||
if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) {
|
if (items[i].quality > 0) {
|
||||||
items[i].quality = items[i].quality - 1;
|
if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) {
|
||||||
}
|
items[i].quality = items[i].quality - 1;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
if (items[i].quality < 50) {
|
} else {
|
||||||
items[i].quality = items[i].quality + 1;
|
if (items[i].quality < 50) {
|
||||||
|
items[i].quality = items[i].quality + 1;
|
||||||
if (items[i].name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
|
||||||
if (items[i].sellIn < 11) {
|
if (items[i].name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
||||||
if (items[i].quality < 50) {
|
if (items[i].sellIn < 11) {
|
||||||
items[i].quality = items[i].quality + 1;
|
if (items[i].quality < 50) {
|
||||||
}
|
items[i].quality = items[i].quality + 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (items[i].sellIn < 6) {
|
|
||||||
if (items[i].quality < 50) {
|
if (items[i].sellIn < 6) {
|
||||||
items[i].quality = items[i].quality + 1;
|
if (items[i].quality < 50) {
|
||||||
}
|
items[i].quality = items[i].quality + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) {
|
|
||||||
items[i].sellIn = items[i].sellIn - 1;
|
if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) {
|
||||||
}
|
items[i].sellIn = items[i].sellIn - 1;
|
||||||
|
}
|
||||||
if (items[i].sellIn < 0) {
|
|
||||||
if (!items[i].name.equals("Aged Brie")) {
|
if (items[i].sellIn < 0) {
|
||||||
if (!items[i].name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
if (!items[i].name.equals("Aged Brie")) {
|
||||||
if (items[i].quality > 0) {
|
if (!items[i].name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
||||||
if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) {
|
if (items[i].quality > 0) {
|
||||||
items[i].quality = items[i].quality - 1;
|
if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) {
|
||||||
}
|
items[i].quality = items[i].quality - 1;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
items[i].quality = items[i].quality - items[i].quality;
|
} else {
|
||||||
}
|
items[i].quality = items[i].quality - items[i].quality;
|
||||||
} else {
|
}
|
||||||
if (items[i].quality < 50) {
|
} else {
|
||||||
items[i].quality = items[i].quality + 1;
|
if (items[i].quality < 50) {
|
||||||
}
|
items[i].quality = items[i].quality + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -1,15 +1,17 @@
|
|||||||
package com.gildedrose;
|
package com.gildedrose;
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
import org.junit.Test;
|
|
||||||
|
import org.junit.Test;
|
||||||
public class GildedRoseTest {
|
|
||||||
|
public class GildedRoseTest {
|
||||||
@Test
|
|
||||||
public void foo() {
|
@Test
|
||||||
Item[] items = new Item[] { new Item("foo", 0, 0) };
|
public void foo() {
|
||||||
GildedRose app = new GildedRose(items);
|
Item[] items = new Item[] { new Item("foo", 0, 0) };
|
||||||
app.updateQuality();
|
GildedRose app = new GildedRose(items);
|
||||||
assertEquals("fixme", app.items[0].name);
|
app.updateQuality();
|
||||||
}
|
assertEquals("fixme", app.items[0].name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
39
Java/com/gildedrose/Item.java
Executable file → Normal file
39
Java/com/gildedrose/Item.java
Executable file → Normal file
@ -1,19 +1,20 @@
|
|||||||
package com.gildedrose;
|
package com.gildedrose;
|
||||||
public class Item {
|
|
||||||
|
public class Item {
|
||||||
public String name;
|
|
||||||
|
public String name;
|
||||||
public int sellIn;
|
|
||||||
|
public int sellIn;
|
||||||
public int quality;
|
|
||||||
|
public int quality;
|
||||||
public Item(String name, int sellIn, int quality) {
|
|
||||||
this.name = name;
|
public Item(String name, int sellIn, int quality) {
|
||||||
this.sellIn = sellIn;
|
this.name = name;
|
||||||
this.quality = quality;
|
this.sellIn = sellIn;
|
||||||
}
|
this.quality = quality;
|
||||||
|
}
|
||||||
public String toString() {
|
|
||||||
return this.name + ", " + this.sellIn + ", " + this.quality;
|
public String toString() {
|
||||||
}
|
return this.name + ", " + this.sellIn + ", " + this.quality;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
73
Java/com/gildedrose/TexttestFixture.java
Executable file → Normal file
73
Java/com/gildedrose/TexttestFixture.java
Executable file → Normal file
@ -1,36 +1,37 @@
|
|||||||
package com.gildedrose;
|
package com.gildedrose;
|
||||||
|
|
||||||
public class TexttestFixture {
|
public class TexttestFixture {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
System.out.println("OMGHAI!");
|
System.out.println("OMGHAI!");
|
||||||
|
|
||||||
Item[] items = new Item[] { new Item("+5 Dexterity Vest", 10, 20),
|
Item[] items = new Item[] {
|
||||||
new Item("Aged Brie", 2, 0),
|
new Item("+5 Dexterity Vest", 10, 20), //
|
||||||
new Item("Elixir of the Mongoose", 5, 7),
|
new Item("Aged Brie", 2, 0), //
|
||||||
new Item("Sulfuras, Hand of Ragnaros", 0, 80),
|
new Item("Elixir of the Mongoose", 5, 7), //
|
||||||
new Item("Sulfuras, Hand of Ragnaros", -1, 80),
|
new Item("Sulfuras, Hand of Ragnaros", 0, 80), //
|
||||||
new Item("Backstage passes to a TAFKAL80ETC concert", 15, 20),
|
new Item("Sulfuras, Hand of Ragnaros", -1, 80),
|
||||||
new Item("Backstage passes to a TAFKAL80ETC concert", 10, 49),
|
new Item("Backstage passes to a TAFKAL80ETC concert", 15, 20),
|
||||||
new Item("Backstage passes to a TAFKAL80ETC concert", 5, 49),
|
new Item("Backstage passes to a TAFKAL80ETC concert", 10, 49),
|
||||||
// this conjured item does not work properly yet
|
new Item("Backstage passes to a TAFKAL80ETC concert", 5, 49),
|
||||||
new Item("Conjured Mana Cake", 3, 6) };
|
// this conjured item does not work properly yet
|
||||||
|
new Item("Conjured Mana Cake", 3, 6) };
|
||||||
GildedRose app = new GildedRose(items);
|
|
||||||
|
GildedRose app = new GildedRose(items);
|
||||||
int days = 2;
|
|
||||||
if (args.length > 0) {
|
int days = 2;
|
||||||
days = Integer.parseInt(args[0]) + 1;
|
if (args.length > 0) {
|
||||||
}
|
days = Integer.parseInt(args[0]) + 1;
|
||||||
|
}
|
||||||
for (int i = 0; i < days; i++) {
|
|
||||||
System.out.println("-------- day " + i + " --------");
|
for (int i = 0; i < days; i++) {
|
||||||
System.out.println("name, sellIn, quality");
|
System.out.println("-------- day " + i + " --------");
|
||||||
for (Item item : items) {
|
System.out.println("name, sellIn, quality");
|
||||||
System.out.println(item);
|
for (Item item : items) {
|
||||||
}
|
System.out.println(item);
|
||||||
System.out.println();
|
}
|
||||||
app.updateQuality();
|
System.out.println();
|
||||||
}
|
app.updateQuality();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
|
|||||||
3
js/.gitignore
vendored
3
js/.gitignore
vendored
@ -1,3 +0,0 @@
|
|||||||
*.swp
|
|
||||||
*~
|
|
||||||
*.bak
|
|
||||||
61
js/README.md
61
js/README.md
@ -1,61 +0,0 @@
|
|||||||
If you want to get cracking on the JavaScript source then do this:
|
|
||||||
|
|
||||||
git clone git@github.com:guyroyse/gilded-rose-javascript.git
|
|
||||||
|
|
||||||
Hi and welcome to team Gilded Rose.
|
|
||||||
|
|
||||||
As you know, we are a small inn with a prime location in a prominent city ran
|
|
||||||
by a friendly innkeeper named Allison. We also buy and sell only the finest
|
|
||||||
goods. Unfortunately, our goods are constantly degrading in quality as they
|
|
||||||
approach their sell by date.
|
|
||||||
|
|
||||||
We have a system in place that updates our inventory for us. It was developed
|
|
||||||
by a no-nonsense type named Leeroy, who has moved on to new adventures. Your
|
|
||||||
task is to add the new feature to our system so that we can begin selling a
|
|
||||||
new category of items.
|
|
||||||
|
|
||||||
First an introduction to our system:
|
|
||||||
|
|
||||||
- All items have a *sell_in* value which denotes the number of days we have to
|
|
||||||
sell the item
|
|
||||||
|
|
||||||
- All items have a *quality* value which denotes how valuable the item is
|
|
||||||
|
|
||||||
- At the end of each day our system lowers both values for every item
|
|
||||||
|
|
||||||
Pretty simple, right? Well this is where it gets interesting:
|
|
||||||
|
|
||||||
- Once the *sell_in* days is less then zero, *quality* degrades twice as fast
|
|
||||||
|
|
||||||
- The *quality* of an item is never negative
|
|
||||||
|
|
||||||
- "Aged Brie" actually increases in *quality* the older it gets
|
|
||||||
|
|
||||||
- The *quality* of an item is never more than 50
|
|
||||||
|
|
||||||
- "Sulfuras", being a legendary item, never has to be sold nor does it
|
|
||||||
decrease in *quality*
|
|
||||||
|
|
||||||
- "Backstage passes", like aged brie, increases in *quality* as it's *sell_in*
|
|
||||||
value decreases; *quality* increases by 2 when there are 10 days or less
|
|
||||||
and by 3 when there are 5 days or less but *quality* drops to 0 after the
|
|
||||||
concert
|
|
||||||
|
|
||||||
We have recently signed a supplier of conjured items. This requires an update
|
|
||||||
to our system:
|
|
||||||
|
|
||||||
- "Conjured" items degrade in *quality* twice as fast as normal items
|
|
||||||
|
|
||||||
Feel free to make any changes to the *update_quality* method and add any new
|
|
||||||
code as long as everything still works correctly. However, do not alter the
|
|
||||||
*Item* class or *items* property as those belong to the goblin in the corner
|
|
||||||
who will insta-rage and one-shot you as he doesn't believe in shared code
|
|
||||||
ownership.
|
|
||||||
|
|
||||||
Just for clarification, an item can never have its *quality* increase above 50,
|
|
||||||
however "Sulfuras" is a legendary item and as such its *quality* is 80 and it
|
|
||||||
never alters.
|
|
||||||
|
|
||||||
Sources:
|
|
||||||
<http://www.iamnotmyself.com/2011/02/13/RefactorThisTheGildedRoseKata.aspx>
|
|
||||||
<https://github.com/professor/GildedRose>
|
|
||||||
@ -1,7 +1,9 @@
|
|||||||
describe("Gilded Rose", function() {
|
describe("Gilded Rose", function() {
|
||||||
|
|
||||||
it("should do something", function() {
|
it("should foo", function() {
|
||||||
update_quality
|
items = [ new Item("foo", 0, 0) ];
|
||||||
|
update_quality();
|
||||||
|
expect(items[0].name).toEqual("fixme");
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@ -3,7 +3,6 @@ import unittest
|
|||||||
|
|
||||||
from gilded_rose import Item, GildedRose
|
from gilded_rose import Item, GildedRose
|
||||||
|
|
||||||
|
|
||||||
class GildedRoseTest(unittest.TestCase):
|
class GildedRoseTest(unittest.TestCase):
|
||||||
def test_foo(self):
|
def test_foo(self):
|
||||||
items = [Item("foo", 0, 0)]
|
items = [Item("foo", 0, 0)]
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
from gilded_rose import *
|
from gilded_rose import *
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
5
ruby/.buildpath
Normal file
5
ruby/.buildpath
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<buildpath>
|
||||||
|
<buildpathentry kind="src" path=""/>
|
||||||
|
<buildpathentry kind="con" path="org.eclipse.dltk.launching.INTERPRETER_CONTAINER"/>
|
||||||
|
</buildpath>
|
||||||
5
ruby/.loadpath
Normal file
5
ruby/.loadpath
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<loadpath>
|
||||||
|
<pathentry path="" type="src" />
|
||||||
|
<pathentry path="org.rubypeople.rdt.launching.RUBY_CONTAINER" type="con" />
|
||||||
|
</loadpath>
|
||||||
23
ruby/.project
Normal file
23
ruby/.project
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>GildedRose.rb</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.rubypeople.rdt.core.rubybuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.dltk.core.scriptbuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.rubypeople.rdt.core.rubynature</nature>
|
||||||
|
<nature>org.eclipse.dltk.ruby.core.nature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
||||||
134
ruby/gilded_rose.rb
Executable file → Normal file
134
ruby/gilded_rose.rb
Executable file → Normal file
@ -1,68 +1,68 @@
|
|||||||
|
class GildedRose
|
||||||
class GildedRose
|
|
||||||
def initialize(items)
|
def initialize(items)
|
||||||
@items = items
|
@items = items
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_quality()
|
def update_quality()
|
||||||
@items.each do |item|
|
@items.each do |item|
|
||||||
if item.name != "Aged Brie" and item.name != "Backstage passes to a TAFKAL80ETC concert"
|
if item.name != "Aged Brie" and item.name != "Backstage passes to a TAFKAL80ETC concert"
|
||||||
if item.quality > 0
|
if item.quality > 0
|
||||||
if item.name != "Sulfuras, Hand of Ragnaros"
|
if item.name != "Sulfuras, Hand of Ragnaros"
|
||||||
item.quality = item.quality - 1
|
item.quality = item.quality - 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if item.quality < 50
|
if item.quality < 50
|
||||||
item.quality = item.quality + 1
|
item.quality = item.quality + 1
|
||||||
if item.name == "Backstage passes to a TAFKAL80ETC concert"
|
if item.name == "Backstage passes to a TAFKAL80ETC concert"
|
||||||
if item.sell_in < 11
|
if item.sell_in < 11
|
||||||
if item.quality < 50
|
if item.quality < 50
|
||||||
item.quality = item.quality + 1
|
item.quality = item.quality + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if item.sell_in < 6
|
if item.sell_in < 6
|
||||||
if item.quality < 50
|
if item.quality < 50
|
||||||
item.quality = item.quality + 1
|
item.quality = item.quality + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if item.name != "Sulfuras, Hand of Ragnaros"
|
if item.name != "Sulfuras, Hand of Ragnaros"
|
||||||
item.sell_in = item.sell_in - 1
|
item.sell_in = item.sell_in - 1
|
||||||
end
|
end
|
||||||
if item.sell_in < 0
|
if item.sell_in < 0
|
||||||
if item.name != "Aged Brie"
|
if item.name != "Aged Brie"
|
||||||
if item.name != "Backstage passes to a TAFKAL80ETC concert"
|
if item.name != "Backstage passes to a TAFKAL80ETC concert"
|
||||||
if item.quality > 0
|
if item.quality > 0
|
||||||
if item.name != "Sulfuras, Hand of Ragnaros"
|
if item.name != "Sulfuras, Hand of Ragnaros"
|
||||||
item.quality = item.quality - 1
|
item.quality = item.quality - 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
item.quality = item.quality - item.quality
|
item.quality = item.quality - item.quality
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if item.quality < 50
|
if item.quality < 50
|
||||||
item.quality = item.quality + 1
|
item.quality = item.quality + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Item
|
class Item
|
||||||
attr_accessor :name, :sell_in, :quality
|
attr_accessor :name, :sell_in, :quality
|
||||||
|
|
||||||
def initialize(name, sell_in, quality)
|
def initialize(name, sell_in, quality)
|
||||||
@name = name
|
@name = name
|
||||||
@sell_in = sell_in
|
@sell_in = sell_in
|
||||||
@quality = quality
|
@quality = quality
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s()
|
def to_s()
|
||||||
"#{@name}, #{@sell_in}, #{@quality}"
|
"#{@name}, #{@sell_in}, #{@quality}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -1,33 +1,33 @@
|
|||||||
#!/usr/bin/ruby -w
|
#!/usr/bin/ruby -w
|
||||||
|
|
||||||
require File.join(File.dirname(__FILE__), 'gilded_rose')
|
require File.join(File.dirname(__FILE__), 'gilded_rose')
|
||||||
|
|
||||||
puts "OMGHAI!"
|
puts "OMGHAI!"
|
||||||
items = [
|
items = [
|
||||||
Item.new(name="+5 Dexterity Vest", sell_in=10, quality=20),
|
Item.new(name="+5 Dexterity Vest", sell_in=10, quality=20),
|
||||||
Item.new(name="Aged Brie", sell_in=2, quality=0),
|
Item.new(name="Aged Brie", sell_in=2, quality=0),
|
||||||
Item.new(name="Elixir of the Mongoose", sell_in=5, quality=7),
|
Item.new(name="Elixir of the Mongoose", sell_in=5, quality=7),
|
||||||
Item.new(name="Sulfuras, Hand of Ragnaros", sell_in=0, quality=80),
|
Item.new(name="Sulfuras, Hand of Ragnaros", sell_in=0, quality=80),
|
||||||
Item.new(name="Sulfuras, Hand of Ragnaros", sell_in=-1, quality=80),
|
Item.new(name="Sulfuras, Hand of Ragnaros", sell_in=-1, quality=80),
|
||||||
Item.new(name="Backstage passes to a TAFKAL80ETC concert", sell_in=15, quality=20),
|
Item.new(name="Backstage passes to a TAFKAL80ETC concert", sell_in=15, quality=20),
|
||||||
Item.new(name="Backstage passes to a TAFKAL80ETC concert", sell_in=10, quality=49),
|
Item.new(name="Backstage passes to a TAFKAL80ETC concert", sell_in=10, quality=49),
|
||||||
Item.new(name="Backstage passes to a TAFKAL80ETC concert", sell_in=5, quality=49),
|
Item.new(name="Backstage passes to a TAFKAL80ETC concert", sell_in=5, quality=49),
|
||||||
# This Conjured item does not work properly yet
|
# This Conjured item does not work properly yet
|
||||||
Item.new(name="Conjured Mana Cake", sell_in=3, quality=6), # <-- :O
|
Item.new(name="Conjured Mana Cake", sell_in=3, quality=6), # <-- :O
|
||||||
]
|
]
|
||||||
|
|
||||||
days = 2
|
days = 2
|
||||||
if ARGV.size > 0
|
if ARGV.size > 0
|
||||||
days = ARGV[0].to_i + 1
|
days = ARGV[0].to_i + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
gilded_rose = GildedRose.new items
|
gilded_rose = GildedRose.new items
|
||||||
(0...days).each do |day|
|
(0...days).each do |day|
|
||||||
puts "-------- day #{day} --------"
|
puts "-------- day #{day} --------"
|
||||||
puts "name, sellIn, quality"
|
puts "name, sellIn, quality"
|
||||||
items.each do |item|
|
items.each do |item|
|
||||||
puts item
|
puts item
|
||||||
end
|
end
|
||||||
puts ""
|
puts ""
|
||||||
gilded_rose.update_quality
|
gilded_rose.update_quality
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user