alch 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/alch.rb +1 -1
- data/lib/item.rb +49 -56
- data/lib/osrs.rb +7 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0421dd1fabbd36b971e6828a591e9c554d95fec9
|
4
|
+
data.tar.gz: c123074c01000c9baa261464c56ec1f6578fb50e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ce6b1c8257fc877390039b1c6de64d5a2161be73e63bf296e86bec2986c6812b441d30529873276e4e47b331d3c0fceff29a8b46934539a47d6107097830d7b
|
7
|
+
data.tar.gz: bb050fe0c9dace8e2038a4370d1204f18aaa733ab585d4849054902e13de31ff9ae403257eb486c40b2e8e058332a50a1d523e3ebcf9cdd2b03ccfbfa27d0280
|
data/README.md
CHANGED
data/lib/alch.rb
CHANGED
data/lib/item.rb
CHANGED
@@ -15,7 +15,7 @@ class Item
|
|
15
15
|
# @return [Integer] the price based on the Grand Exchange
|
16
16
|
attr_reader :price
|
17
17
|
# @return [Integer] the price based on the store
|
18
|
-
attr_reader :
|
18
|
+
attr_reader :store
|
19
19
|
# @return [Integer] the amount of GP from low alching
|
20
20
|
attr_reader :low_alch
|
21
21
|
# @return [Integer] the amount of GP from high alching
|
@@ -25,49 +25,35 @@ class Item
|
|
25
25
|
|
26
26
|
# Creates a new Item object
|
27
27
|
#
|
28
|
-
# You
|
28
|
+
# You can create a new Item by specifying the Item's name or
|
29
|
+
# the Item's id number as an integer.
|
29
30
|
#
|
30
|
-
# @note
|
31
|
-
# @
|
31
|
+
# @note when passing the id number as the parameter, it must be an Integer
|
32
|
+
# @note when passing the Item's name as the parameter, it's case INSENSITIVE
|
33
|
+
# @param item - either the Item's name as a String or Item's id as an Integer
|
32
34
|
# @return [Item] a new Item object
|
33
35
|
# @example Create a new Item
|
34
36
|
# Item.new(1603) #=> Item
|
35
|
-
# Item.new(
|
36
|
-
|
37
|
-
|
38
|
-
@
|
39
|
-
@
|
40
|
-
@
|
41
|
-
@
|
42
|
-
@
|
43
|
-
@
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
# @note The `item_name` gets capitalized for search!
|
48
|
-
# So this is case insensitive.
|
49
|
-
# @param item_name [String] the name of the Item to search
|
50
|
-
# @return [Integer] the Item's ID
|
51
|
-
# @raise RunTimeError if the Item doesn't exist
|
52
|
-
# @example Creating an Item object
|
53
|
-
# Item.new(Item.id_by_name('uncut ruby')) #=> Item
|
54
|
-
# Item.new(Item.id_by_name('UNCUT rUby')) #=> Item
|
55
|
-
# Item.new(Item.id_by_name('incit rbuy')) #=> RunTimeError
|
56
|
-
def self.id_by_name(item_name)
|
57
|
-
item_name.capitalize!
|
58
|
-
json = JSON.parse(open(OSRS::SHOP_DATA, &:read))
|
59
|
-
item_id = 0
|
60
|
-
json.each { |id, name| item_id = id if name['name'].eql? item_name }
|
61
|
-
raise "Item (#{item_name}) doesn't exist." if item_id.eql? 0
|
62
|
-
item_id.to_i
|
37
|
+
# Item.new('ruby') #=> Item
|
38
|
+
# Item.new('1603') #=> RunTimeError (Item doesn't exist)
|
39
|
+
def initialize(item)
|
40
|
+
@id = item if item.is_a?(Integer)
|
41
|
+
@id = id_by_name(item) if item.is_a?(String)
|
42
|
+
@grand_exchange = JSON.parse(open(OSRS::GE_JSON + @id.to_s, &:read)).freeze
|
43
|
+
@name = OSRS::STORE_DATA[@id.to_s]['name']
|
44
|
+
@price = price_to_int(@grand_exchange['item']['current']['price'].to_s)
|
45
|
+
@store = OSRS::STORE_DATA[@id.to_s]['store'].to_i
|
46
|
+
@low_alch = (@store * 0.4).to_i
|
47
|
+
@high_alch = (@store * 0.6).to_i
|
48
|
+
@image = @grand_exchange['item']['icon_large']
|
63
49
|
end
|
64
50
|
|
65
51
|
# Checks if this item's GE price is less than another item's
|
66
52
|
# @param [Item] other - the other item to compare to
|
67
53
|
# @return [Boolean] true if this item is worth less than the other item.
|
68
54
|
# @example Example
|
69
|
-
# abyssal_whip = Item.new(
|
70
|
-
# ruby = Item.new(
|
55
|
+
# abyssal_whip = Item.new('abyssal whip')
|
56
|
+
# ruby = Item.new('ruby')
|
71
57
|
# price = abyssal_whip < ruby #=> false
|
72
58
|
def <(other)
|
73
59
|
price < other.price
|
@@ -77,8 +63,8 @@ class Item
|
|
77
63
|
# @param [Item] other - the other item to compare to
|
78
64
|
# @return [Boolean] true if this item is worth less than the other item.
|
79
65
|
# @example Example
|
80
|
-
# abyssal_whip = Item.new(
|
81
|
-
# ruby = Item.new(
|
66
|
+
# abyssal_whip = Item.new('abyssal whip')
|
67
|
+
# ruby = Item.new('ruby')
|
82
68
|
# price = abyssal_whip > ruby #=> true
|
83
69
|
def >(other)
|
84
70
|
price > other.price
|
@@ -88,8 +74,8 @@ class Item
|
|
88
74
|
# @param [Item] other - the other item, which price we will subtract from
|
89
75
|
# @return [Integer] self.price - other.price
|
90
76
|
# @example Example
|
91
|
-
# abyssal_whip = Item.new(
|
92
|
-
# santa_hat = Item.new(
|
77
|
+
# abyssal_whip = Item.new('abyssal whip')
|
78
|
+
# santa_hat = Item.new('santa hat')
|
93
79
|
# price = abyssal_whip - santa_hat #=> 1788200
|
94
80
|
def -(other)
|
95
81
|
price - other.price
|
@@ -99,34 +85,41 @@ class Item
|
|
99
85
|
# @param [Item] other - the other item, which price we will subtract from
|
100
86
|
# @return [Integer] self.price - other.price
|
101
87
|
# @example Example
|
102
|
-
# abyssal_whip = Item.new(
|
103
|
-
# santa_hat = Item.new(
|
88
|
+
# abyssal_whip = Item.new('abyssal whip')
|
89
|
+
# santa_hat = Item.new('santa hat')
|
104
90
|
# price = abyssal_whip + santa_hat #=> 1811800
|
105
91
|
def +(other)
|
106
92
|
price + other.price
|
107
93
|
end
|
108
94
|
|
109
|
-
|
110
|
-
|
111
|
-
# @return
|
112
|
-
def
|
113
|
-
|
95
|
+
# @example Profit from high alching a Rune Dagger
|
96
|
+
# Item.new('rune dagger').high_alch #=> 26
|
97
|
+
# @return the total profit from high alching this Item
|
98
|
+
def high_profit
|
99
|
+
high_alch - (self + Item.new(561))
|
114
100
|
end
|
115
101
|
|
116
|
-
# @
|
117
|
-
|
118
|
-
|
119
|
-
|
102
|
+
# @example Profit from low alching a Rune Dagger
|
103
|
+
# Item.new('rune dagger').low_price #=> -1574
|
104
|
+
# @return the total profit from low alching this Item
|
105
|
+
def low_profit
|
106
|
+
low_alch - (self + Item.new(561))
|
120
107
|
end
|
121
108
|
|
122
|
-
|
123
|
-
def generate_store
|
124
|
-
JSON.parse(open(OSRS::SHOP_DATA, &:read))[@id]['store'].to_i
|
125
|
-
end
|
109
|
+
private
|
126
110
|
|
127
|
-
#
|
128
|
-
|
129
|
-
|
111
|
+
# Gets the id of the item based on it's name
|
112
|
+
# @param [String] item_name - the name of the Item
|
113
|
+
# @return [Integer] Item's id
|
114
|
+
# @raise RunTimeError - if the Item doesn't exist in the database
|
115
|
+
def id_by_name(item_name)
|
116
|
+
item_name.capitalize!.freeze
|
117
|
+
item_id = 0
|
118
|
+
OSRS::STORE_DATA.each do |id, name|
|
119
|
+
item_id = id if name['name'] == item_name
|
120
|
+
end
|
121
|
+
raise "Item (#{item_name}) doesn't exist." if item_id.eql? 0
|
122
|
+
item_id.to_i
|
130
123
|
end
|
131
124
|
|
132
125
|
# Turns a price, like 1.9m and converts it to an Integer.
|
data/lib/osrs.rb
CHANGED
@@ -1,8 +1,13 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'open-uri'
|
3
|
+
|
1
4
|
# Old School Runescape Module
|
2
5
|
# @since 0.0.2
|
3
6
|
module OSRS
|
4
7
|
# Links to GE specific data
|
5
8
|
GE_JSON = 'http://services.runescape.com/m=itemdb_oldschool/api/catalogue/detail.json?item='.freeze
|
6
|
-
# Link to
|
7
|
-
|
9
|
+
# Link to Store JSON
|
10
|
+
STORE_JSON = 'http://marchy.me/data/shop.json'.freeze
|
11
|
+
# Store data
|
12
|
+
STORE_DATA = JSON.parse(open(STORE_JSON, &:read)).freeze
|
8
13
|
end
|