Class: Glitch::Type
- Inherits:
-
Object
- Object
- Glitch::Type
- Defined in:
- lib/type.rb
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#initial_price ⇒ Object
readonly
Returns the value of attribute initial_price.
-
#multiplier ⇒ Object
readonly
Returns the value of attribute multiplier.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #available? ⇒ Boolean
- #description ⇒ Object
- #increment ⇒ Object
- #info_string ⇒ Object
-
#initialize(name, options = {}) ⇒ Type
constructor
A new instance of Type.
- #name_with_shortcut ⇒ Object
- #price ⇒ Object
- #shortcut ⇒ Object
- #total_available ⇒ Object
Constructor Details
#initialize(name, options = {}) ⇒ Type
Returns a new instance of Type.
5 6 7 8 9 10 11 12 13 |
# File 'lib/type.rb', line 5 def initialize(name, = {}) @name = name @initial_price = [:initial_price] @multiplier = [:multiplier] @count_available = [:count_available] || :infinite @price_calc = [:price_calc] @description = [:description] @count = 0 end |
Instance Attribute Details
#count ⇒ Object (readonly)
Returns the value of attribute count.
3 4 5 |
# File 'lib/type.rb', line 3 def count @count end |
#initial_price ⇒ Object (readonly)
Returns the value of attribute initial_price.
3 4 5 |
# File 'lib/type.rb', line 3 def initial_price @initial_price end |
#multiplier ⇒ Object (readonly)
Returns the value of attribute multiplier.
3 4 5 |
# File 'lib/type.rb', line 3 def multiplier @multiplier end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/type.rb', line 3 def name @name end |
Instance Method Details
#available? ⇒ Boolean
41 42 43 |
# File 'lib/type.rb', line 41 def available? infinite? || @count_available > 0 end |
#description ⇒ Object
62 63 64 |
# File 'lib/type.rb', line 62 def description @description || '??' end |
#increment ⇒ Object
34 35 36 37 38 39 |
# 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 ⇒ Object
53 54 55 56 57 58 59 60 |
# 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 ⇒ Object
19 20 21 |
# File 'lib/type.rb', line 19 def name_with_shortcut @name.sub(shortcut, "[#{shortcut}]") end |
#price ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# 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 ⇒ Object
15 16 17 |
# File 'lib/type.rb', line 15 def shortcut @name[0] end |
#total_available ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/type.rb', line 45 def total_available if infinite? '??' else @count + @count_available end end |