dim_wishlist 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/dim_wishlist/item.rb +56 -0
- data/lib/dim_wishlist/roll.rb +25 -0
- data/lib/dim_wishlist.rb +69 -0
- metadata +47 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f123644e17f9f423febd0d9e965d5ef592461594dd316d9c17910b67b2b58f55
|
4
|
+
data.tar.gz: 9a62796312e58e0fa8bbc2944eae1251c96e1c5db893d7e0b10d7d228b952840
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 49bb4cf0e8412696cd719bf74aefdbf29d405cb80b44910f242a104031255b9f1195112db1d31061bf44c6d176ac9b16f412f18b230fa3ae52a506035bee4899
|
7
|
+
data.tar.gz: 44247d15eefc75faa03db355cbe1ed51f933de09faaf689cfe055b671eee07a7dd5d3b0692ead57913b8f43b83958abdd21dd1e3b285e7f05bce8387f6713ce6
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'dim_wishlist/roll'
|
2
|
+
|
3
|
+
class WishlistItem
|
4
|
+
attr_accessor :info, :notes, :rolls
|
5
|
+
|
6
|
+
# rolls schema
|
7
|
+
# { Roll.key(item_id, perks) => [roll...] }
|
8
|
+
|
9
|
+
def initialize(lines)
|
10
|
+
@info = []
|
11
|
+
@notes = []
|
12
|
+
@rolls = {}
|
13
|
+
lines.each { |line| process(line) }
|
14
|
+
end
|
15
|
+
|
16
|
+
def item_ids
|
17
|
+
@rolls.values.map(&:item_id).uniq
|
18
|
+
end
|
19
|
+
|
20
|
+
def has_roll?(item_id, perks)
|
21
|
+
!@rolls[Roll.key(item_id, perks)].nil?
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_s
|
25
|
+
["// #{@info.join('. ')}", "// #{@notes.join('. ')}", @rolls.values.map(&:to_s), "\n"].flatten.join("\n")
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def process(line)
|
31
|
+
case line
|
32
|
+
when %r{^// .*} then handle_info_line(line)
|
33
|
+
when %r{^//notes:} then handle_notes_line(line)
|
34
|
+
when /^dimwishlist:/ then handle_wishlist_line(line)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def handle_info_line(line)
|
39
|
+
@info << line.split('// ').last
|
40
|
+
end
|
41
|
+
|
42
|
+
def handle_notes_line(line)
|
43
|
+
@notes << line.split('//notes:').last
|
44
|
+
end
|
45
|
+
|
46
|
+
def handle_wishlist_line(line)
|
47
|
+
params = line.split('dimwishlist:').last.split('&')
|
48
|
+
note_params = params.last.split('#notes')
|
49
|
+
notes = note_params.last if note_params.length > 1
|
50
|
+
item_id = params.first.split('=').last
|
51
|
+
perks = params[1].split('=').last.split(',')
|
52
|
+
|
53
|
+
roll = Roll.new(item_id: item_id, perks: perks, notes: notes)
|
54
|
+
@rolls[roll.key] = roll
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'digest'
|
2
|
+
|
3
|
+
class Roll
|
4
|
+
attr_accessor :perks, :item_id, :notes
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def key(item_id, perks)
|
8
|
+
Digest::SHA2.new(512).hexdigest "#{item_id},#{perks.join(',')}"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(item_id:, perks:, notes: nil)
|
13
|
+
@item_id = item_id
|
14
|
+
@perks = perks
|
15
|
+
@notes = notes
|
16
|
+
end
|
17
|
+
|
18
|
+
def key
|
19
|
+
self.class.key(@item_id, @perks)
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_s
|
23
|
+
"dimwishlist:item=#{@item_id}&perks=#{perks.join(',')}#{!@notes.nil? ? "#notes:#{notes}" : ''}"
|
24
|
+
end
|
25
|
+
end
|
data/lib/dim_wishlist.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
|
5
|
+
require 'dim_wishlist/item'
|
6
|
+
require 'dim_wishlist/roll'
|
7
|
+
|
8
|
+
class Wishlist
|
9
|
+
attr_accessor :items
|
10
|
+
|
11
|
+
WISHLIST_URI = 'https://raw.githubusercontent.com/48klocs/dim-wish-list-sources/master/choosy_voltron.txt'
|
12
|
+
|
13
|
+
class << self
|
14
|
+
def parse(wishlist_uri = WISHLIST_URI)
|
15
|
+
instance = self.new
|
16
|
+
body = get_wishlist_text(wishlist_uri)
|
17
|
+
|
18
|
+
return if body.nil?
|
19
|
+
|
20
|
+
lines = []
|
21
|
+
body.split("\n").each do |line|
|
22
|
+
if line =~ %r{// [a-zA-Z(]|//notes:|dimwishlist:}
|
23
|
+
lines << line
|
24
|
+
elsif lines.length.positive?
|
25
|
+
instance.add_item(WishlistItem.new(lines)) rescue nil
|
26
|
+
lines.clear
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
instance
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def get_wishlist_text(wishlist_uri)
|
36
|
+
uri = URI(wishlist_uri)
|
37
|
+
res = Net::HTTP.get_response(uri)
|
38
|
+
|
39
|
+
res.body if res.is_a?(Net::HTTPSuccess)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def initialize(wishlist_items = [])
|
44
|
+
@items = {}
|
45
|
+
wishlist_items.each(&:add_item)
|
46
|
+
end
|
47
|
+
|
48
|
+
def add_item(wishlist_item)
|
49
|
+
wishlist_item.item_ids.each do |id|
|
50
|
+
@items[id] ||= []
|
51
|
+
@items[id] << wishlist_item
|
52
|
+
@items[id].uniq!
|
53
|
+
end
|
54
|
+
|
55
|
+
wishlist_item
|
56
|
+
end
|
57
|
+
|
58
|
+
def items_with_id(id)
|
59
|
+
@items[id] || []
|
60
|
+
end
|
61
|
+
|
62
|
+
def wishlist_item?(id, perks)
|
63
|
+
items_with_id(id).any? { |item| item.has_roll?(id, perks) }
|
64
|
+
end
|
65
|
+
|
66
|
+
def to_s
|
67
|
+
@items.values.flatten.map(&:to_s).join
|
68
|
+
end
|
69
|
+
end
|
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dim_wishlist
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tyler McClellan
|
8
|
+
- Wesley Carter
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2022-02-03 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: A tool for parsing, modifying, and creating Destiny Item Manager wishlists!
|
15
|
+
email:
|
16
|
+
- the8bitgamer11@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/dim_wishlist.rb
|
22
|
+
- lib/dim_wishlist/item.rb
|
23
|
+
- lib/dim_wishlist/roll.rb
|
24
|
+
homepage: https://github.com/tkmcclellan/dim_wishlist
|
25
|
+
licenses:
|
26
|
+
- MIT
|
27
|
+
metadata: {}
|
28
|
+
post_install_message:
|
29
|
+
rdoc_options: []
|
30
|
+
require_paths:
|
31
|
+
- lib
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubygems_version: 3.2.15
|
44
|
+
signing_key:
|
45
|
+
specification_version: 4
|
46
|
+
summary: Destiny Item Manager Wishlist Parser
|
47
|
+
test_files: []
|