Module: Wowecon::CurrencyHelpers
- Included in:
- Currency
- Defined in:
- lib/wowecon/currency_helpers.rb
Instance Method Summary collapse
- #==(other) ⇒ Object
- #nil? ⇒ Boolean
- #to_f ⇒ Object
- #to_hash ⇒ Object
- #to_html ⇒ Object
- #to_i ⇒ Object
- #to_s ⇒ Object
Instance Method Details
#==(other) ⇒ Object
46 47 48 |
# File 'lib/wowecon/currency_helpers.rb', line 46 def ==(other) @value == other.to_i end |
#nil? ⇒ Boolean
50 51 52 |
# File 'lib/wowecon/currency_helpers.rb', line 50 def nil? @value.nil? end |
#to_f ⇒ Object
17 18 19 |
# File 'lib/wowecon/currency_helpers.rb', line 17 def to_f @value.to_f / 10000 end |
#to_hash ⇒ Object
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_html ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/wowecon/currency_helpers.rb', line 36 def to_html = "" self.to_hash.each do |denom, value| if value > 0 || .length > 0 += "<var class=\"#{denom.to_s}\">#{value.to_s.gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1,")}</var>" end end end |
#to_i ⇒ Object
6 7 8 |
# File 'lib/wowecon/currency_helpers.rb', line 6 def to_i @value end |
#to_s ⇒ Object
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 |