Module: Wowecon::CurrencyHelpers
- Included in:
- Currency
- Defined in:
- lib/wowecon/currency_helpers.rb
Instance Method Summary collapse
- #<(other) ⇒ Object
- #<=(other) ⇒ Object
- #==(other) ⇒ Object
- #>(other) ⇒ Object
- #>=(other) ⇒ Object
- #inspect ⇒ Object
- #nil? ⇒ Boolean
- #to_f ⇒ Object
- #to_hash ⇒ Object
- #to_html ⇒ Object
- #to_i ⇒ Object
- #to_s ⇒ Object
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 |
#inspect ⇒ Object
41 42 43 |
# File 'lib/wowecon/currency_helpers.rb', line 41 def inspect @value.to_i end |
#nil? ⇒ Boolean
65 66 67 |
# File 'lib/wowecon/currency_helpers.rb', line 65 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
31 32 33 34 35 36 37 38 39 |
# File 'lib/wowecon/currency_helpers.rb', line 31 def to_html = "" self.to_hash.each do |denom, value| if value > 0 || .length > 0 || denom == :copper += "<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 |
# 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 |