WSWSANE 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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/WSWSANE.rb +114 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b21144c7ceadf658158ef04b1b438752d960dcea9b2bb3799e49bbac7c813882
4
+ data.tar.gz: a4aa032dabb191b691a0c5ddeaf5a1369b5143604249640568d8921098c11ffd
5
+ SHA512:
6
+ metadata.gz: 4a816efb694ca9c124949ad7f77df89a1672b775acd356bfdcbbd6720c5214ce4efea2f5635b681ac3656fd1910579640ae0469c4f97757b1bba5cf9385199ae
7
+ data.tar.gz: 83ae4b1b1c3d4cbc63d3849519cc9b8d95f254ae3bf2feb79fcd4d31091f58a60bf7949353cb303af5d7325c490acb98d127e33c8b3abec08b0cb51188a3d503
data/lib/WSWSANE.rb ADDED
@@ -0,0 +1,114 @@
1
+ require 'net/http'
2
+ require 'json'
3
+ class WSWSANE
4
+ @@reference={:cis=>[
5
+ ["The Malevolence", 4845],
6
+ ["Lucrehulk-class Battleship", 3356.9],
7
+ ["Providence-class Destroyer", 1088],
8
+ ["Munificent-class Frigate", 825],
9
+ ["C-9979 Landing Craft", 210],
10
+ ["Vulture Droid", 6.96],
11
+ ["Tri-fighter ",5.4]
12
+ ],
13
+ :republic=>[
14
+ ["Venator-class Star Destroyer", 1137],
15
+ ["Acclamator-class Assault Ship", 752],
16
+ ["Cosular-class Cruiser", 115],
17
+ ["LAAT Gunship", 28.8],
18
+ ["Z-95 Starfighter", 16.74],
19
+ ["ARC-170 Starfighter", 12.71],
20
+ ["V-wing Starfighter", 7.9]
21
+ ],
22
+ :empire=>[
23
+ ["DS-2 Death Star", 200000],
24
+ ["DS-1 Death Star", 160000],
25
+ ["Executor-class Star Dreadnought", 19000],
26
+ ["Imperial II-class Star Destroyer", 1600],
27
+ ["Interdictor-class Star Destroyer", 1129],
28
+ ["Victory II-class Star Destroyer", 900],
29
+ ["Arquitens-class Light Cruiser", 325],
30
+ ["Lambda-class Shuttle", 20],
31
+ ["TIE Fighter", 7.24]
32
+ ],
33
+ :rebel_alliance=>[
34
+ ["Mon Calamari Star Cruiser", 1200],
35
+ ["Nebulon-B Frigate", 300],
36
+ ["CR90 Corvette", 150],
37
+ ["Alderaan Cruiser", 126.68],
38
+ ["Hammerhead Corvette", 116.7],
39
+ ["GR-75 Transport", 90],
40
+ ["Millenium Falcon", 34.75],
41
+ ["U-Wing Starfighter", 23.99],
42
+ ["Y-wing Starfighter", 23.4],
43
+ ["B-wing Starfighter", 16.9],
44
+ ["X-wing Starfighter", 13.4],
45
+ ["A-wing Starfighter", 9.6]
46
+ ],
47
+ :first_order=>[
48
+ ["Starkiller Base", 660000],
49
+ ["The Supremacy", 60542.68],
50
+ ["Mandator IV-class Siege Dreadnought", 7669.71],
51
+ ["Resurgent-class Star Destroyer", 2915.81],
52
+ ["AAL Transporter", 18.05],
53
+ ["TIE Fighter", 6.69]
54
+ ],
55
+ :resistance=>[
56
+ ["MC85 Star Cruiser", 3438.37],
57
+ ["MC80A Heavy Star Cruiser", 1300],
58
+ ["Free Virgillia-class Bunkerbuster", 316.05],
59
+ ["SF-17 Heavy Bomber", 29.67],
60
+ ["B-wing Starfighter", 16.9],
61
+ ["X-wing Starfighter", 13.4],
62
+ ["A-wing Starfighter", 9.6]
63
+ ]
64
+ }
65
+ def self.getToday(apikey,factions=["cis","republic","empire","rebel_alliance","first_order","resistance"])
66
+ date=Time.new.strftime("%Y-%m-%d")
67
+ return self.get(apikey,date,date,factions)
68
+ end
69
+ def self.get(apikey,startDate,endDate,factions=["cis","republic","empire","rebel_alliance","first_order","resistance"])
70
+ uri=URI("https://api.nasa.gov/neo/rest/v1/feed")
71
+ params={:start_date=>startDate,
72
+ :end_date=>endDate,
73
+ :api_key=>apikey}
74
+ uri.query = URI.encode_www_form(params)
75
+ response=Net::HTTP.get_response(uri)
76
+ if response.is_a?(Net::HTTPSuccess)
77
+ data=JSON.parse(response.body)
78
+ data["near_earth_objects"].each do |date,dateset|
79
+ dateset.each do |neo|
80
+ size=neo["estimated_diameter"]["meters"]
81
+ neo["star_wars_ship"]=self.classify(size["estimated_diameter_min"],size["estimated_diameter_max"],factions)
82
+ end
83
+ end
84
+ return data
85
+ else
86
+ raise response.body
87
+ end
88
+ end
89
+ def self.classify(minSize,maxSize,factions=["cis","republic","empire","rebel_alliance","first_order","resistance"])
90
+ factions.map!(&:downcase)
91
+ possibleShips=[]
92
+ @@reference.each do |faction,ships|
93
+ if factions.include?(faction.to_s)
94
+ ships.each do |ship|
95
+ if ship[1]>minSize and ship[1]<maxSize
96
+ possibleShips.push(ship)
97
+ end
98
+ end
99
+ end
100
+ end
101
+ if possibleShips.length==0
102
+ return "None"
103
+ else
104
+ bestMatch=possibleShips[0]
105
+ estSize=Math.exp((Math.log(minSize)+Math.log(maxSize))/2)
106
+ possibleShips.each do |possibleShip|
107
+ if (possibleShip[1]-estSize).abs()<(bestMatch[1]-estSize).abs()
108
+ bestMatch=possibleShip
109
+ end
110
+ end
111
+ return bestMatch[0]
112
+ end
113
+ end
114
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: WSWSANE
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Marcy Brook
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-05-04 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A simple tool that uses the NASA NEOWS API to find nearby space objects
14
+ and determine which Star Wars ship they are most likely to be.
15
+ email:
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/WSWSANE.rb
21
+ homepage:
22
+ licenses:
23
+ - Unlicense
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubygems_version: 3.0.3
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: What Star Wars Ships are Near Earth?
44
+ test_files: []