Class: Wowecon::Currency

Inherits:
Object
  • Object
show all
Includes:
CurrencyHelpers
Defined in:
lib/wowecon/currency.rb

Instance Method Summary collapse

Methods included from CurrencyHelpers

#<, #<=, #==, #>, #>=, #inspect, #nil?, #to_f, #to_hash, #to_html, #to_i, #to_s

Constructor Details

#initialize(value) ⇒ Currency

Returns a new instance of Currency.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/wowecon/currency.rb', line 7

def initialize(value)
  @value = case
  when value.kind_of?(Fixnum)
    value
  when value.kind_of?(Float)
    sprintf("%.4f", value).split(".").join("").to_i
  when value.kind_of?(Hash)
    if value.key?(:gold) and value.key?(:silver) and value.key?(:copper)
      "#{value[:gold]}#{sprintf("%02d", value[:silver])}#{sprintf("%02d", value[:copper])}".to_i
    else
      nil
    end
  else
    nil
  end
end