-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathprice.rb
73 lines (62 loc) · 1.29 KB
/
price.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
require_relative 'gw2spidy'
class Price
attr_accessor :name, :value
def initialize (name, val=0)
@name = name
@value = val
end
end
class SkillPointPrice < Price
attr_accessor :sale, :offer
def initialize (val=0)
super("Skill Point", val)
@sale = @offer = val
end
end
class GoldPrice < Price
include GW2Spidy
attr_accessor :sale, :offer
def initialize (id, val=0, o_val=0)
super("Gold", val)
@o_val = o_val
self.getPrice id
end
def getPrice id
if id == 0
@value == 0 ? @sale = @offer = 0 : (@sale,@offer=@value,@o_val)
else
data = self.getByID(id)
if @value == 0
@sale = data["min_sale_unit_price"]
@offer = data["max_offer_unit_price"]
else
@sale = @value
@offer = @value
end
end
end
def inspect
end
def self.to_g val
r = ""
if val < 0
#val=val.abs
#r="-"
return '0c'
end
s_tmp = val.round.to_s
s = s_tmp.size
if s > 4 then
r += s_tmp[0, s-4] + 'g '
s_tmp=s_tmp[s-4, 4 ]
s = s_tmp.size
end
if s > 2 then
r += s_tmp[0, s-2] + 's '
s_tmp=s_tmp[s-2, 2]
s = s_tmp.size
end
r += s_tmp + 'c'
r
end
end