Merge pull request #184 from ag4ta/change-line-separator

Unify line separator in ruby example
This commit is contained in:
Emily Bache 2020-09-27 08:50:29 +02:00 committed by GitHub
commit e2c5826e71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 101 additions and 101 deletions

View 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

View File

@ -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