Created
April 20, 2020 17:42
-
-
Save mchail/ddb0b9addb52135a870875c277502607 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'json' | |
Disc = Struct.new( | |
:plastic, | |
:weight, | |
:color, | |
:quantity, | |
) | |
WIDTH = 16 | |
REKO_MODEL_ID = '16569' | |
curl = %{ | |
curl --silent 'https://infinitediscs.com/Default.aspx/fnLoadPlasticInventory' \ | |
-H 'content-type: application/json; charset=UTF-8' \ | |
--data-binary '{"model_id":"#{REKO_MODEL_ID}","plastic_id":"","sort":"Weight Low-High"}' \ | |
}.strip | |
response = %x[#{curl}] | |
response = JSON.parse(JSON.parse(response)['d']) | |
discs = response['inventory'].map do |item| | |
Disc.new( | |
item['E_PlasticName'], | |
item['E_Weight'].to_i, | |
item['E_Color'], | |
item['E_Available'].to_i, | |
) | |
end | |
discs = discs.sort do |disc, other| | |
[ | |
-(disc.plastic <=> other.plastic), | |
-(disc.weight <=> other.weight), | |
-(disc.quantity <=> other.quantity), | |
(disc.color <=> other.color), | |
].find do |key| | |
key != 0 | |
end || 0 | |
end | |
header = Disc.members.map do |column| | |
column.to_s.upcase.center(WIDTH) | |
end.join('|') | |
puts header | |
puts '-' * header.size | |
discs.each do |disc| | |
disc_row = disc.values.map do |value| | |
value.to_s.center(WIDTH) | |
end.join('|') | |
puts disc_row | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment