class Glitch::Type
Attributes
count[R]
initial_price[R]
multiplier[R]
name[R]
Public Class Methods
new(name, options = {})
click to toggle source
# File lib/type.rb, line 5 def initialize(name, options = {}) @name = name @initial_price = options[:initial_price] @multiplier = options[:multiplier] @count_available = options[:count_available] || :infinite @price_calc = options[:price_calc] @description = options[:description] @count = 0 end
Public Instance Methods
available?()
click to toggle source
# File lib/type.rb, line 41 def available? infinite? || @count_available > 0 end
description()
click to toggle source
# File lib/type.rb, line 62 def description @description || '??' end
increment()
click to toggle source
# File lib/type.rb, line 34 def increment @count = @count + 1 if @count_available.is_a? Integer @count_available = @count_available - 1 end end
info_string()
click to toggle source
# File lib/type.rb, line 53 def info_string string = [] string << name_with_shortcut string << "[#{price} bits]" string << "(#{@count}/#{total_available})" if @count > 0 string << "*#{@multiplier}" string.join ' ' end
name_with_shortcut()
click to toggle source
# File lib/type.rb, line 19 def name_with_shortcut @name.sub(shortcut, "[#{shortcut}]") end
price()
click to toggle source
# File lib/type.rb, line 23 def price if @price_calc @price_calc.call(self) else [ @initial_price, @initial_price * @count * (@count >= 10 ? 10 : 1) + @count ].max end end
shortcut()
click to toggle source
# File lib/type.rb, line 15 def shortcut @name[0] end
total_available()
click to toggle source
# File lib/type.rb, line 45 def total_available if infinite? '??' else @count + @count_available end end
Private Instance Methods
infinite?()
click to toggle source
# File lib/type.rb, line 68 def infinite? @count_available == :infinite end