Module: Wowecon::CurrencyHelpers

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

Instance Method Summary collapse

Instance Method Details

#<(other) ⇒ Object



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

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

#<=(other) ⇒ Object



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

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

#==(other) ⇒ Object



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

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

#>(other) ⇒ Object



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

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

#>=(other) ⇒ Object



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

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

#inspectObject



41
42
43
# File 'lib/wowecon/currency_helpers.rb', line 41

def inspect
  @value.to_i
end

#nil?Boolean

Returns:

  • (Boolean)


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

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



31
32
33
34
35
36
37
38
39
# File 'lib/wowecon/currency_helpers.rb', line 31

def to_html
  tags  = ""
  self.to_hash.each do |denom, value|
    if value > 0 || tags.length > 0 || denom == :copper
      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
# 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 || denom == :copper
      output += "#{value.to_s.gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1,")}#{denom.to_s[0,1]} "
    end
  end
  output.strip
end