wowecon 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/wowecon.rb +1 -0
- data/lib/wowecon/currency.rb +3 -32
- data/lib/wowecon/currency_helpers.rb +33 -0
- data/spec/spec_helper.rb +0 -0
- metadata +5 -2
data/lib/wowecon.rb
CHANGED
data/lib/wowecon/currency.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
|
+
require_relative 'currency_helpers.rb'
|
2
|
+
|
1
3
|
module Wowecon
|
2
4
|
class Currency
|
5
|
+
include Wowecon::CurrencyHelpers
|
3
6
|
|
4
7
|
attr_accessor :gold, :silver, :copper
|
5
8
|
|
@@ -16,37 +19,5 @@ module Wowecon
|
|
16
19
|
end
|
17
20
|
end
|
18
21
|
|
19
|
-
def self.from_hash(denoms)
|
20
|
-
(denoms[:gold] + (denoms[:silver].to_f / 100) + (denoms[:copper].to_f / 10000)).to_f
|
21
|
-
end
|
22
|
-
|
23
|
-
def to_hash
|
24
|
-
{:gold => @gold, :silver => @silver, :copper => @copper}
|
25
|
-
end
|
26
|
-
|
27
|
-
def to_f
|
28
|
-
(@gold + (@silver.to_f / 100) + (@copper.to_f / 10000)).to_f
|
29
|
-
end
|
30
|
-
|
31
|
-
def to_s
|
32
|
-
output = ""
|
33
|
-
self.to_hash.each do |denom, value|
|
34
|
-
if value > 0 || output.length > 0
|
35
|
-
output += "#{value.to_s.gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1,")}#{denom.to_s[0,1]} "
|
36
|
-
end
|
37
|
-
end
|
38
|
-
output.strip
|
39
|
-
end
|
40
|
-
|
41
|
-
def to_html
|
42
|
-
tags = ""
|
43
|
-
self.to_hash.each do |denom, value|
|
44
|
-
if value > 0 || tags.length > 0
|
45
|
-
tags += "<var class=\"#{denom.to_s}\">#{value.to_s.gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1,")}</var>"
|
46
|
-
end
|
47
|
-
end
|
48
|
-
tags
|
49
|
-
end
|
50
|
-
|
51
22
|
end
|
52
23
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Wowecon
|
2
|
+
module CurrencyHelpers
|
3
|
+
|
4
|
+
def to_hash
|
5
|
+
{:gold => @gold, :silver => @silver, :copper => @copper}
|
6
|
+
end
|
7
|
+
|
8
|
+
def to_f
|
9
|
+
(@gold + (@silver.to_f / 100) + (@copper.to_f / 10000)).to_f
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_s
|
13
|
+
output = ""
|
14
|
+
self.to_hash.each do |denom, value|
|
15
|
+
if value > 0 || output.length > 0
|
16
|
+
output += "#{value.to_s.gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1,")}#{denom.to_s[0,1]} "
|
17
|
+
end
|
18
|
+
end
|
19
|
+
output.strip
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_html
|
23
|
+
tags = ""
|
24
|
+
self.to_hash.each do |denom, value|
|
25
|
+
if value > 0 || tags.length > 0
|
26
|
+
tags += "<var class=\"#{denom.to_s}\">#{value.to_s.gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1,")}</var>"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
tags
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
data/spec/spec_helper.rb
ADDED
File without changes
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: wowecon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Ben Darlow
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-07-01 00:00:00 +01:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -45,8 +45,10 @@ extra_rdoc_files: []
|
|
45
45
|
|
46
46
|
files:
|
47
47
|
- lib/wowecon/currency.rb
|
48
|
+
- lib/wowecon/currency_helpers.rb
|
48
49
|
- lib/wowecon.rb
|
49
50
|
- spec/currency_spec.rb
|
51
|
+
- spec/spec_helper.rb
|
50
52
|
- spec/wowecon_spec.rb
|
51
53
|
has_rdoc: true
|
52
54
|
homepage: http://github.com/kapowaz/wowecon
|
@@ -78,4 +80,5 @@ specification_version: 3
|
|
78
80
|
summary: wowecon
|
79
81
|
test_files:
|
80
82
|
- spec/currency_spec.rb
|
83
|
+
- spec/spec_helper.rb
|
81
84
|
- spec/wowecon_spec.rb
|