alch 0.0.2 → 1.0.0
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.
- checksums.yaml +4 -4
- data/README.md +6 -7
- data/lib/alch.rb +1 -1
- data/lib/alch/item.rb +18 -24
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd3b7a3bd27afaf7c06e66161ceacfb90422ca0a
|
4
|
+
data.tar.gz: b6da70617e798c4ed9d8ee355d9f7285d9571ec0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9fd3042b517f31681f9d9143e87168c099aceb40831c46c10ae92c1368ccc5801e74f2028283d5914fbfbaba0f266521f5b96136965e1be1bc3ab96b73e6c64
|
7
|
+
data.tar.gz: 3ad58144391253b2c54bd18270d4c05bcd3d0476b58de8cc5f56a1e363180a6af85dd38c15277ff175934cc8e97cb364b024123d0dbc8987da745672712796ca
|
data/README.md
CHANGED
@@ -1,24 +1,25 @@
|
|
1
1
|
# Alch.rb
|
2
|
-
A
|
2
|
+
A simplistic Runescape Alchemy API that can help you get alch prices of certain items.
|
3
3
|
|
4
4
|
## Installation
|
5
|
-
You can
|
5
|
+
You can get the newest gem of Alch.rb. Just enter the following in your command line:
|
6
6
|
|
7
7
|
`$ gem install alch`
|
8
8
|
|
9
9
|
That's it! You are now able to include the API into your projects.
|
10
10
|
|
11
|
-
|
11
|
+
If you plan on using alch in a class or file, you have to require it at the top of your Ruby file, like so:
|
12
12
|
|
13
13
|
```ruby
|
14
14
|
require 'alch'
|
15
15
|
```
|
16
16
|
|
17
17
|
### Dependencies
|
18
|
-
|
18
|
+
Ruby 2.0 and up
|
19
19
|
|
20
20
|
## Usage Examples
|
21
21
|
A very basic use case:
|
22
|
+
|
22
23
|
```ruby
|
23
24
|
require 'alch'
|
24
25
|
|
@@ -46,6 +47,4 @@ puts item.high_alch - (item.price + nature_rune.price)
|
|
46
47
|
```
|
47
48
|
|
48
49
|
# Full Documentation
|
49
|
-
|
50
|
-
* **[Item.rb](https://github.com/RubySometimes/alchrb/blob/master/docs/classes/Item.md)**
|
51
|
-
|
50
|
+
[View the Full Documentation](http://www.rubydoc.info/gems/alch/)
|
data/lib/alch.rb
CHANGED
data/lib/alch/item.rb
CHANGED
@@ -5,19 +5,13 @@ require('net/http')
|
|
5
5
|
|
6
6
|
# Items are anything that can be in your inventory.
|
7
7
|
#
|
8
|
-
# @author
|
8
|
+
# @author Marcello A. Sabino
|
9
9
|
class Item
|
10
|
-
|
11
|
-
|
12
|
-
attr_reader :name
|
13
|
-
attr_reader :price
|
14
|
-
attr_reader :store_price
|
15
|
-
attr_reader :low_alch
|
16
|
-
attr_reader :high_alch
|
17
|
-
attr_reader :image
|
10
|
+
attr_reader :id, :name, :price, :store_price,
|
11
|
+
:low_price, :high_alch, :image
|
18
12
|
|
19
13
|
# Creates a new Item object
|
20
|
-
# @param id - the id of the Item
|
14
|
+
# @param [Integer] id - the id of the Item
|
21
15
|
# @raise RunTimeError if the id is not an integer
|
22
16
|
def initialize(id)
|
23
17
|
raise 'Parameter id must be an Integer' unless id.instance_of? Integer
|
@@ -31,9 +25,9 @@ class Item
|
|
31
25
|
end
|
32
26
|
|
33
27
|
# Class method to get the item's id by name
|
34
|
-
# @param item_name - the name of the item to search for
|
28
|
+
# @param [String] item_name - the name of the item to search for
|
35
29
|
# the item_name gets capitalized for search.
|
36
|
-
# @return the item's id
|
30
|
+
# @return [Integer] the item's id
|
37
31
|
# @raise RunTimeError if the item doesn't exist
|
38
32
|
def self.id_by_name(item_name)
|
39
33
|
item_name = item_name.capitalize
|
@@ -46,29 +40,29 @@ class Item
|
|
46
40
|
end
|
47
41
|
|
48
42
|
# Checks if this item's GE price is less than another item's
|
49
|
-
# @param other - the other item to compare to
|
50
|
-
# @return true if this item is worth less than the other_item.
|
43
|
+
# @param [Item] other - the other item to compare to
|
44
|
+
# @return [Boolean] true if this item is worth less than the other_item.
|
51
45
|
def <(other)
|
52
46
|
price < other.price
|
53
47
|
end
|
54
48
|
|
55
49
|
# Checks if this item's GE price is greater than another item's
|
56
|
-
# @param
|
57
|
-
# @return true if this item is worth less than the other_item.
|
50
|
+
# @param [Item] other - the other item to compare to
|
51
|
+
# @return [Boolean] true if this item is worth less than the other_item.
|
58
52
|
def >(other)
|
59
53
|
price > other.price
|
60
54
|
end
|
61
55
|
|
62
56
|
# Take another item's price and subtract it from this item
|
63
|
-
# @param other - the other item, which price we will subtract from
|
64
|
-
# @return self.price - other.price
|
57
|
+
# @param [Item] other - the other item, which price we will subtract from
|
58
|
+
# @return [Integer] self.price - other.price
|
65
59
|
def -(other)
|
66
60
|
price - other.price
|
67
61
|
end
|
68
62
|
|
69
63
|
# Take another item's price and add it with this item's price
|
70
|
-
# @param other - the other item, which price we will subtract from
|
71
|
-
# @return self.price - other.price
|
64
|
+
# @param [Item] other - the other item, which price we will subtract from
|
65
|
+
# @return [Integer] self.price - other.price
|
72
66
|
def +(other)
|
73
67
|
price + other.price
|
74
68
|
end
|
@@ -84,7 +78,7 @@ class Item
|
|
84
78
|
end
|
85
79
|
|
86
80
|
# Gets the store price of the Item
|
87
|
-
# @return the store price of the Item
|
81
|
+
# @return [Integer] the store price of the Item
|
88
82
|
def generate_store
|
89
83
|
uri = URI(OSRS::SHOP_DATA)
|
90
84
|
json = JSON.parse(Net::HTTP.get(uri))
|
@@ -92,7 +86,7 @@ class Item
|
|
92
86
|
end
|
93
87
|
|
94
88
|
# Gets the average price of the Item on the GE
|
95
|
-
# @return the average price on the GE
|
89
|
+
# @return [Integer] the average price on the GE
|
96
90
|
def generate_price
|
97
91
|
uri = URI(OSRS::GE_JSON + @id.to_s)
|
98
92
|
json = JSON.parse(Net::HTTP.get(uri))
|
@@ -109,7 +103,7 @@ class Item
|
|
109
103
|
|
110
104
|
# Turns a price, like 1.9m and converts to an Integer.
|
111
105
|
# @param price - the price of an item in string form
|
112
|
-
# @return the integer form of a price.
|
106
|
+
# @return [Integer] the integer form of a price.
|
113
107
|
def price_to_int(price)
|
114
108
|
price_float = clean_price(price.to_s)
|
115
109
|
price_float *= 1_000_000 if price[-1] == 'm'
|
@@ -118,7 +112,7 @@ class Item
|
|
118
112
|
end
|
119
113
|
|
120
114
|
# Takes a price as a string, and removes any commas.
|
121
|
-
# @param price - the price from the JSON in string form.
|
115
|
+
# @param [Float] price - the price from the JSON in string form.
|
122
116
|
def clean_price(price)
|
123
117
|
price.sub(/,/, '').to_f
|
124
118
|
end
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcello A. Sabino
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: A simple way to determine alch prices on Oldschool Runescape
|
13
|
+
description: A simple way to determine alch prices on Oldschool Runescape
|
14
14
|
email: march@marchy.me
|
15
15
|
executables: []
|
16
16
|
extensions: []
|