Module: Wowecon::CurrencyHelpers

Included in:
Currency
Defined in:
lib/wowecon/currency_helpers.rb

Instance Method Summary collapse

Instance Method Details

#<(other) ⇒ Object



58
59
60
# File 'lib/wowecon/currency_helpers.rb', line 58

def <(other)
  @value < other.to_i
end

#<=(other) ⇒ Object



66
67
68
# File 'lib/wowecon/currency_helpers.rb', line 66

def <=(other)
  @value <= other.to_i
end

#==(other) ⇒ Object



50
51
52
# File 'lib/wowecon/currency_helpers.rb', line 50

def ==(other) 
  @value == other.to_i
end

#>(other) ⇒ Object



54
55
56
# File 'lib/wowecon/currency_helpers.rb', line 54

def >(other)
  @value > other.to_i
end

#>=(other) ⇒ Object



62
63
64
# File 'lib/wowecon/currency_helpers.rb', line 62

def >=(other)
  @value >= other.to_i
end

#inspectObject



46
47
48
# File 'lib/wowecon/currency_helpers.rb', line 46

def inspect
  @value.to_i
end

#nil?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/wowecon/currency_helpers.rb', line 70

def nil?
  @value.nil?
end

#to_fObject



17
18
19
# File 'lib/wowecon/currency_helpers.rb', line 17

def to_f
  @value.to_f / 10000
end

#to_hashObject



10
11
12
13
14
15
# File 'lib/wowecon/currency_helpers.rb', line 10

def to_hash
  copper = @value.to_s[-2..-1].to_i
  silver = @value.to_s[-4..-3].to_i
  gold   = @value.to_s[0..-5].to_i      
  {:gold => gold, :silver => silver, :copper => copper}
end

#to_htmlObject



36
37
38
39
40
41
42
43
44
# File 'lib/wowecon/currency_helpers.rb', line 36

def to_html
  tags  = ""
  self.to_hash.each do |denom, value|
    if value > 0 || tags.length > 0
      tags += "<var class=\"#{denom.to_s}\">#{value.to_s.gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1,")}</var>"
    end
  end
  tags
end

#to_iObject



6
7
8
# File 'lib/wowecon/currency_helpers.rb', line 6

def to_i
  @value
end

#to_sObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/wowecon/currency_helpers.rb', line 21

def to_s
  output = ""
  self.to_hash.each do |denom, value|
    if value > 0 || output.length > 0
      output += "#{value.to_s.gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1,")}#{denom.to_s[0,1]} "
    end
  end
  
  if output == ""
    "0"
  else
    output.strip
  end
end