oolite 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 29b82b603f54c118604880e334dc641e9ae9d06c
4
- data.tar.gz: 4ca7a991985fc798b3d83814a3074a16edc2737e
3
+ metadata.gz: a0eacc2db825856e9b197799928c07c79d46f48c
4
+ data.tar.gz: 08add855baa60fc715f6d52740fab9c856523aeb
5
5
  SHA512:
6
- metadata.gz: 40dbea1d74449ff19e6669dcf9fa7e96542dc0127a8824885abd0e1d33ee4bb56236e66b232d40dee5d183fd7facb1d2c06e0916a8ec06ec75a26f24b6199711
7
- data.tar.gz: 913d50a5080b2b1f2044f5ea397dd679e0fbc691bc2c1c43c8a18634205a579605aeaa06f9024ae5fc834abf3756e3f8ab696db3f035512cec50cdcacdbf14f6
6
+ metadata.gz: 6e72c5e6b8b21ba44b4d82a5b23792a42bc03071a0da2934299b4694977308d33943b9a9ee9f9e35bb5c1bacdffebe1d86b33b889564256c6ae15517d85561e8
7
+ data.tar.gz: 94cdc383bb4a0e47da8326e861990a9c63b647aca128c156bd293a5a5f50223fd71542b00fa9555a974fe04ccea110faf1cf94b3fd8e3d225528766e2bf829ec
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --require spec_helper
3
+ #--require pry
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Oolite
2
2
 
3
- Utility scripts for monitoring the Oolite game's system markets and
3
+ Utility scripts for monitoring the [Oolite](http://www.oolite.org/) game's system markets and
4
4
  providing trading suggestions based on the market data.
5
5
 
6
6
  ## Installation
@@ -1,4 +1,7 @@
1
1
  require "oolite/version"
2
+ require 'pathname'
3
+ require 'yaml'
4
+ require 'highline/import'
2
5
 
3
6
  if ENV['DEBUG'].nil?
4
7
  $debug = false
@@ -137,25 +140,25 @@ module Oolite
137
140
  ]
138
141
 
139
142
  @economies = [
140
- "Rich Industrial",
143
+ "Average Agricultural",
141
144
  "Average Industrial",
142
- "Poor Industrial",
143
- "Mainly Industrial",
144
145
  "Mainly Agricultural",
146
+ "Mainly Industrial",
147
+ "Poor Agricultural",
148
+ "Poor Industrial",
145
149
  "Rich Agricultural",
146
- "Average Agricultural",
147
- "Poor Agricultural"
150
+ "Rich Industrial",
148
151
  ]
149
152
 
150
153
  @governments = [
151
154
  "Anarchy",
152
- "Feudal",
153
- "Multi-Government",
154
- "Dictatorship",
155
155
  "Communist",
156
156
  "Confederacy",
157
+ "Corporate State",
157
158
  "Democracy",
158
- "Corporate State"
159
+ "Dictatorship",
160
+ "Feudal",
161
+ "Multi-Government",
159
162
  ]
160
163
 
161
164
  @systems = Hash.new
@@ -178,11 +181,13 @@ module Oolite
178
181
  end # Configuration
179
182
  end
180
183
 
181
- require 'yaml'
182
184
 
183
185
  # Initialize the configuration
184
186
  Oolite.configure
185
187
 
188
+ require 'oolite/console'
189
+ require 'oolite/system_data'
190
+ require 'oolite/systems_data'
186
191
  require 'oolite/csv_doc'
187
192
  require 'oolite/save_file'
188
193
  require 'oolite/market_file'
@@ -0,0 +1,41 @@
1
+ ##############################################################################
2
+ # File:: console.rb
3
+ # Purpose:: Console Module includes helper methods related to console IO
4
+ #
5
+ # Author:: Jeff McAffee 05/22/2015
6
+ # Copyright:: Copyright (c) 2015, kTech Systems LLC. All rights reserved.
7
+ # Website:: http://ktechsystems.com
8
+ ##############################################################################
9
+
10
+ module Oolite
11
+ module Console
12
+ def select_system systems, header, prompt = "? "
13
+ selected_system = choose do |menu|
14
+ menu.index = :letter
15
+ menu.index_suffix = " - "
16
+ menu.header = header
17
+ menu.prompt = prompt
18
+
19
+ systems.each do |sys|
20
+ info = system_info sys
21
+ menu.choice "#{sys.ljust(14)} #{info.ljust(50)}" do sys end
22
+ end
23
+
24
+ menu.choice :quit do 'q' end
25
+ end
26
+ end
27
+
28
+ def select_from items, header, prompt = "? "
29
+ selected_item = choose do |menu|
30
+ #menu.index = :number
31
+ menu.index_suffix = " - "
32
+ menu.header = header
33
+ menu.prompt = prompt
34
+
35
+ items.each do |item|
36
+ menu.choice item do item end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end # module
@@ -115,9 +115,9 @@ module Oolite
115
115
  config.current_system_name = system
116
116
 
117
117
  unless config.systems.key?(system)
118
- details = { economy: nil,
119
- government: nil,
120
- tech_level: nil,
118
+ details = { economy: '',
119
+ government: '',
120
+ tech_level: '',
121
121
  }
122
122
  config.systems[system] = details
123
123
  end
@@ -0,0 +1,73 @@
1
+ ##############################################################################
2
+ # File:: system_data.rb
3
+ # Purpose:: SystemData stores info about a single system
4
+ # (ie. economy, government, etc)
5
+ #
6
+ # Author:: Jeff McAffee 05/22/2015
7
+ # Copyright:: Copyright (c) 2015, kTech Systems LLC. All rights reserved.
8
+ # Website:: http://ktechsystems.com
9
+ ##############################################################################
10
+
11
+ module Oolite
12
+ class SystemData
13
+ attr_reader :name, :economy, :government, :tech_level
14
+
15
+ def initialize name, data
16
+ data = Hash(data)
17
+
18
+ self.name = name
19
+ self.economy = data[:economy]
20
+ self.government = data[:government]
21
+ self.tech_level = data[:tech_level]
22
+ end
23
+
24
+ def name= val
25
+ fail "SystemData#name= name is nil" if val.nil?
26
+ fail "SystemData#name= name is empty" if val.empty?
27
+ @name = val
28
+ end
29
+
30
+ def economy= val
31
+ if val.nil?
32
+ @economy = ''
33
+ else
34
+ @economy = val
35
+ end
36
+ end
37
+
38
+ def government= val
39
+ if val.nil?
40
+ @government = ''
41
+ else
42
+ @government = val
43
+ end
44
+ end
45
+
46
+ def tech_level= val
47
+ if val.nil?
48
+ @tech_level = ''
49
+ else
50
+ @tech_level = val
51
+ end
52
+ end
53
+
54
+ #
55
+ # When emitting as YAML, emit as a hash
56
+ #
57
+
58
+ def to_yaml
59
+ {
60
+ economy: @economy,
61
+ government: @government,
62
+ tech_level: @tech_level,
63
+ }
64
+ end
65
+
66
+ def all_data_present?
67
+ return false if economy.nil? || economy.empty?
68
+ return false if government.nil? || government.empty?
69
+ return false if tech_level.nil? || tech_level.empty?
70
+ return true
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,49 @@
1
+ ##############################################################################
2
+ # File:: systems_data.rb
3
+ # Purpose:: SystemsData stores info about systems
4
+ # (ie. economy, government, etc)
5
+ #
6
+ # Author:: Jeff McAffee 05/22/2015
7
+ # Copyright:: Copyright (c) 2015, kTech Systems LLC. All rights reserved.
8
+ # Website:: http://ktechsystems.com
9
+ ##############################################################################
10
+
11
+ module Oolite
12
+ class SystemsData
13
+ def self.systems
14
+ @systems ||= read_config
15
+ end
16
+
17
+ def self.names
18
+ systems.keys
19
+ end
20
+
21
+ def self.add sys_data
22
+ systems[sys_data.name] = sys_data
23
+ write_config
24
+ end
25
+
26
+ private
27
+
28
+ def self.read_config
29
+ data = Oolite.configuration.systems
30
+ sys_objs = Hash.new
31
+
32
+ data.each do |name, sys_data|
33
+ sys_objs[name] = SystemData.new name, sys_data
34
+ end
35
+
36
+ sys_objs
37
+ end
38
+
39
+ def self.write_config
40
+ Oolite.configure do |config|
41
+ systems.each do |name, sys|
42
+ config.systems[name] = sys.to_yaml
43
+ end
44
+ end
45
+
46
+ Oolite.save_configuration
47
+ end
48
+ end
49
+ end
@@ -13,28 +13,23 @@ require 'yaml'
13
13
 
14
14
  module Oolite
15
15
  class Trade
16
+ include Console
17
+
16
18
  def display
17
19
  puts "= Oolite Trader ="
18
20
  puts
19
- puts " Current Location: #{current_system_name}"
20
- puts
21
- puts " Available destinations:"
22
- puts
21
+ ask_user_to_update_system_data(current_system_name)
23
22
 
24
- systems = market.systems
25
- systems.delete current_system_name
26
- systems.each_with_index do |sys,i|
27
- puts " #{i} - #{sys}"
28
- end
29
23
  puts
30
- choice = ask " Choose your destination (q to abort): "
31
-
32
- return if choice.downcase == 'q'
24
+ puts " Current Location: #{current_system_name} #{system_info(current_system_name)}"
33
25
  puts
34
26
 
35
- dest_system = systems[choice.to_i]
27
+ dest_system = get_destination
28
+
29
+ return if dest_system == 'q'
36
30
 
37
- puts " -- Suggested Trades (best to worst) for #{dest_system} --"
31
+ puts
32
+ puts " -- Profitable Trades for #{dest_system} --"
38
33
  puts
39
34
  puts " #{'Item'.ljust(14)} #{'Amt Avail'.to_s.ljust(10)} #{'PricePerUnit'.to_s.rjust(8)} #{'ProfitPerUnit'.to_s.rjust(12)}"
40
35
  puts
@@ -46,7 +41,7 @@ module Oolite
46
41
 
47
42
  puts
48
43
 
49
- puts " -- Suggested Transactions for #{dest_system} --"
44
+ puts " -- Suggested Transactions for #{current_system_name} to #{dest_system} Route --"
50
45
  puts
51
46
  puts " #{'Item'.ljust(14)} #{'Purch Amt'.to_s.ljust(10)} #{'Profit'.to_s.rjust(8)}"
52
47
  puts
@@ -69,9 +64,79 @@ module Oolite
69
64
 
70
65
  private
71
66
 
72
- def ask msg
73
- print "#{msg}"
74
- val = STDIN.getc
67
+ def systems_data
68
+ @systems_data ||= SystemsData
69
+ end
70
+
71
+ def system_info sys_name
72
+ info = ''
73
+ if systems_data.names.include? sys_name
74
+ sys_data = systems_data.systems[sys_name]
75
+
76
+ econ = sys_data.economy
77
+ gov = sys_data.government
78
+ tech = sys_data.tech_level
79
+
80
+ info = "(#{econ} - #{gov} - #{tech.to_s})"
81
+ end
82
+ info
83
+ end
84
+
85
+ def ask_user_to_update_system_data sys_name
86
+ need_update = false
87
+ need_update = true if !systems_data.names.include? sys_name
88
+ unless need_update
89
+ sys_data = systems_data.systems[sys_name]
90
+ need_update = true if !sys_data.all_data_present?
91
+ end
92
+
93
+ return unless need_update
94
+
95
+ if need_update
96
+ puts "We need to update our records for #{sys_name}"
97
+ result = ask("Would you like to update now (y/n)? ") { |q| q.default = 'y' }
98
+ return if result.downcase == 'n'
99
+ end
100
+
101
+ collect_system_data sys_name
102
+ end
103
+
104
+ def collect_system_data sys_name
105
+ econs = Oolite.configuration.economies.sort
106
+ govs = Oolite.configuration.governments.sort
107
+ prompt = ' Choice? '
108
+
109
+ puts " #{sys_name}"
110
+
111
+ puts
112
+ econ = select_from econs, 'Economy', prompt
113
+
114
+ puts
115
+ gov = select_from govs, 'Government', prompt
116
+
117
+ puts
118
+ puts "Tech Level:"
119
+ puts
120
+ tech_level = ask " Choice (1-14)? "
121
+
122
+ sys_data = SystemData.new sys_name, {}
123
+ sys_data.economy = econ
124
+ sys_data.government = gov
125
+ sys_data.tech_level = tech_level
126
+
127
+ SystemsData.add sys_data
128
+
129
+ puts
130
+ puts " #{sys_name} has been updated."
131
+ puts
132
+ end
133
+
134
+ def get_destination
135
+ systems = market.systems
136
+ systems.delete current_system_name
137
+ systems.sort!
138
+
139
+ select_system systems, "Available destinations", "Choose your destination: "
75
140
  end
76
141
 
77
142
  def current_system_name
@@ -108,6 +173,12 @@ module Oolite
108
173
  end
109
174
  end
110
175
 
176
+ #
177
+ # Calculate and return all *profitable* trades.
178
+ #
179
+ # Returned trades are sorted most expensive to least
180
+ #
181
+
111
182
  def calculate_all_trades dest_system
112
183
  src = market.data[current_system_name]
113
184
  dest = market.data[dest_system]
@@ -119,7 +190,7 @@ module Oolite
119
190
  end
120
191
  end
121
192
 
122
- positive_trades = Array.new
193
+ profitable_trades = Array.new
123
194
 
124
195
  src.keys.each do |item|
125
196
  sprice = src[item][:price]
@@ -128,18 +199,26 @@ module Oolite
128
199
 
129
200
  revenue = dprice - sprice
130
201
  if revenue > 0.0 && amount > 0
131
- positive_trades << TradeItem.new(item, amount, sprice, revenue)
202
+ profitable_trades << TradeItem.new(item, amount, sprice, revenue)
132
203
  end
133
204
  end
134
205
 
135
- positive_trades.sort { |a,b| b.revenue <=> a.revenue }
206
+ profitable_trades.sort { |a,b| b.revenue <=> a.revenue }
136
207
  end
137
208
 
209
+ #
210
+ # Calculate the most profitable trades.
211
+ #
212
+ # We calculate 2 ways, buying the most expensive (and generally the
213
+ # most profitable) trades, then buying the cheapest first. The most
214
+ # profit determines the suggested trades.
215
+ #
216
+
138
217
  def calc_best_trades trades
139
- avail_cargo = Oolite.configuration.cargo
218
+ max_cargo = Oolite.configuration.cargo
140
219
  credits = Oolite.configuration.current_credits
141
220
 
142
- if avail_cargo <= 0
221
+ if max_cargo <= 0
143
222
  return [[], 0]
144
223
  end
145
224
 
@@ -154,59 +233,61 @@ module Oolite
154
233
  return [[], 0]
155
234
  end
156
235
 
157
- balance = credits
158
- cargo = avail_cargo
159
- suggested_trades_expensive_first = []
160
- affordable_trades.each do |trade|
161
- max_amt_by_price = balance / trade.cost
162
- max_amt_by_cargo = [cargo, trade.amount].min
163
- max_amt = [max_amt_by_price, max_amt_by_cargo].min
236
+ suggested_trades_exp = calc_trades(credits, max_cargo, affordable_trades)
237
+ total_profit_exp = calc_total_profit(suggested_trades_exp)
164
238
 
165
- balance = balance - (max_amt * trade.cost)
166
- cargo = cargo - max_amt
239
+ # Sort the trades in ascending order (cheapest first).
240
+ affordable_trades_asc = affordable_trades.sort { |a,b| a.revenue <=> b.revenue }
167
241
 
168
- if max_amt > 0
169
- transaction = { item: trade, amount: max_amt }
170
- suggested_trades_expensive_first << transaction.dup
171
- end
172
- end
242
+ suggested_trades_cheap = calc_trades(credits, max_cargo, affordable_trades_asc)
243
+ total_profit_cheap = calc_total_profit(suggested_trades_cheap)
173
244
 
174
- expensive_first_total_profit = 0
175
- suggested_trades_expensive_first.each do |transaction|
176
- profit = transaction[:item].revenue * transaction[:amount]
177
- expensive_first_total_profit += profit
245
+ if total_profit_exp > total_profit_cheap
246
+ return [suggested_trades_exp, total_profit_exp]
247
+ else
248
+ return [suggested_trades_cheap, total_profit_cheap]
178
249
  end
250
+ end
251
+
252
+ #
253
+ # Calculate the best trades using available credits, cargo and profitable trades
254
+ #
255
+
256
+ def calc_trades credits, cargo, trades
257
+ suggested_trades = []
179
258
 
180
- balance = credits
181
- cargo = avail_cargo
182
- suggested_trades_cheap_first = []
183
- # Sort the trades in ascending order.
184
- cheap_affordable_trades = affordable_trades.sort { |a,b| a.revenue <=> b.revenue }
185
- cheap_affordable_trades.each do |trade|
186
- max_amt_by_price = balance / trade.cost
259
+ trades.each do |trade|
260
+ # We're limited by how much we can buy,
261
+ max_amt_by_price = credits / trade.cost
262
+ # and cargo space versus amount for sale.
187
263
  max_amt_by_cargo = [cargo, trade.amount].min
188
264
  max_amt = [max_amt_by_price, max_amt_by_cargo].min
189
265
 
190
- balance = balance - (max_amt * trade.cost)
266
+ credits = credits - (max_amt * trade.cost)
191
267
  cargo = cargo - max_amt
192
268
 
193
269
  if max_amt > 0
194
270
  transaction = { item: trade, amount: max_amt }
195
- suggested_trades_cheap_first << transaction.dup
271
+ suggested_trades << transaction.dup
196
272
  end
197
273
  end
198
274
 
199
- cheap_first_total_profit = 0
200
- suggested_trades_cheap_first.each do |transaction|
275
+ suggested_trades
276
+ end
277
+
278
+ #
279
+ # Calculate the total anticipated profit if all trades are transacted.
280
+ #
281
+
282
+ def calc_total_profit trades
283
+ total_profit = 0
284
+
285
+ trades.each do |transaction|
201
286
  profit = transaction[:item].revenue * transaction[:amount]
202
- cheap_first_total_profit += profit
287
+ total_profit += profit
203
288
  end
204
289
 
205
- if expensive_first_total_profit > cheap_first_total_profit
206
- return [suggested_trades_expensive_first, expensive_first_total_profit]
207
- else
208
- return [suggested_trades_cheap_first, cheap_first_total_profit]
209
- end
290
+ total_profit
210
291
  end
211
292
  end
212
293
  end
@@ -1,3 +1,3 @@
1
1
  module Oolite
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -20,6 +20,8 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.7"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.2"
23
24
 
24
25
  spec.add_runtime_dependency "nokogiri", "~> 1.6"
26
+ spec.add_runtime_dependency "highline", "~> 1.7"
25
27
  end
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Oolite::Configuration
2
+ save_file_path: "/home/jeff/Jameson.oolite-save"
3
+ market_data_filename: oolite.market
4
+ current_system_name: Edinso
5
+ current_credits: 39558
6
+ cargo: 35
7
+ trade_contraband: false
8
+ contraband:
9
+ - Slaves
10
+ - Narcotics
11
+ - Firearms
12
+ economies:
13
+ - Rich Industrial
14
+ - Average Industrial
15
+ - Poor Industrial
16
+ - Mainly Industrial
17
+ - Mainly Agricultural
18
+ - Rich Agricultural
19
+ - Average Agricultural
20
+ - Poor Agricultural
21
+ governments:
22
+ - Anarchy
23
+ - Feudal
24
+ - Multi-Government
25
+ - Dictatorship
26
+ - Communist
27
+ - Confederacy
28
+ - Democracy
29
+ - Corporate State
30
+ systems:
31
+ Ensoreus:
32
+ :economy: Rich Industrial
33
+ :government: Corporate State
34
+ :tech_level: '12'
35
+ Isinor:
36
+ :economy: Poor Agricultural
37
+ :government: Confederacy
38
+ :tech_level: '7'
39
+ Qutiri:
40
+ :economy: Rich Industrial
41
+ :government: Multi-Government
42
+ :tech_level: '9'
43
+ Zaonce:
44
+ :economy: Average Industrial
45
+ :government: Corporate State
46
+ :tech_level: '12'
47
+ Tionisla:
48
+ :economy: Average Industrial
49
+ :government: Democracy
50
+ :tech_level: '12'
51
+ Bemaera:
52
+ :economy: Average Agricultural
53
+ :government: Multi-Government
54
+ :tech_level: '4'
55
+ Ontiat:
56
+ :economy: Average Agricultural
57
+ :government: Confederacy
58
+ :tech_level: '6'
59
+ Xeesle:
60
+ :economy: Mainly Industrial
61
+ :government: Feudal
62
+ :tech_level: '7'
63
+ Aronar:
64
+ :economy: Poor Industrial
65
+ :government: Feudal
66
+ :tech_level: '8'
67
+ Aesbion:
68
+ :economy: Mainly Industrial
69
+ :government: Corporate State
70
+ :tech_level: '10'
71
+ Lave:
72
+ :economy: Rich Agricultural
73
+ :government: Dictatorship
74
+ :tech_level: '5'
75
+ Esesla:
76
+ :economy: Average Agricultural
77
+ :government: Multi-Government
78
+ :tech_level: '4'
79
+ Zalela:
80
+ :economy: Average Agricultural
81
+ :government: Feudal
82
+ :tech_level: '5'
83
+ Erlaza:
84
+ :economy: Average Agricultural
85
+ :government: Dictatorship
86
+ :tech_level: '6'
87
+ Leesti:
88
+ :economy: Poor Industrial
89
+ :government: Corporate State
90
+ :tech_level: '11'
91
+ Diso:
92
+ :economy: Average Agricultural
93
+ :government: Democracy
94
+ :tech_level: '8'
95
+ Orerve:
96
+ :economy: Mainly Industrial
97
+ :government: Feudal
98
+ :tech_level: '6'
99
+ Riedquat:
100
+ :economy: Poor Agricultural
101
+ :government: Anarchy
102
+ :tech_level: '4'
103
+ Reorte:
104
+ :economy: Poor Agricultural
105
+ :government: Dictatorship
106
+ :tech_level: '6'
107
+ Quator:
108
+ :economy: Mainly Industrial
109
+ :government: Anarchy
110
+ :tech_level: '7'
111
+ Orrere:
112
+ :economy: Poor Agricultural
113
+ :government: Corporate State
114
+ :tech_level: '7'
115
+ Uszaa:
116
+ :economy: Mainly Industrial
117
+ :government: Anarchy
118
+ :tech_level: '8'
119
+ Ra:
120
+ :economy: Poor Agricultural
121
+ :government: Corporate State
122
+ :tech_level: '5'
123
+ Relaes:
124
+ :economy: Average Industrial
125
+ :government: Communist
126
+ :tech_level: '11'
127
+ Zasoer:
128
+ :economy: Average Agricultural
129
+ :government: Confederacy
130
+ :tech_level: '5'
131
+ Azaqu:
132
+ :economy: Average Agricultural
133
+ :government: Democracy
134
+ :tech_level: '7'
135
+ Begeabi:
136
+ :economy: Poor Agricultural
137
+ :government: Feudal
138
+ :tech_level: '2'
139
+ Edinso:
140
+ :economy: ''
141
+ :government: ''
142
+ :tech_level: ''
@@ -0,0 +1,59 @@
1
+ RSpec.describe SystemData do
2
+
3
+ #let(:test_config_path) { test_data_dir('.oolite') }
4
+ #let(:load_config) { Oolite.load_configuration(test_config_path) }
5
+
6
+ #before do
7
+ # load_config
8
+ #end
9
+
10
+ let(:system_data) do
11
+ data = {
12
+ economy: 'economy',
13
+ government: 'government',
14
+ tech_level: '12'
15
+ }
16
+ end
17
+
18
+ let(:empty_system_data) do
19
+ data = {
20
+ economy: '',
21
+ government: '',
22
+ tech_level: ''
23
+ }
24
+ end
25
+
26
+ it 'can be instantiated' do
27
+ expect(SystemData.new('name', system_data)).to_not be nil
28
+ end
29
+
30
+ it 'stores data' do
31
+ actual = SystemData.new('name', system_data)
32
+
33
+ expect(actual.name).to eq 'name'
34
+ expect(actual.economy).to eq system_data[:economy]
35
+ expect(actual.government).to eq system_data[:government]
36
+ expect(actual.tech_level).to eq system_data[:tech_level]
37
+ end
38
+
39
+ it 'emits a hash for yaml storage' do
40
+ actual = SystemData.new('name', system_data)
41
+
42
+ expect(actual.to_yaml).to eq system_data
43
+ end
44
+
45
+ it 'can tell if all data is present' do
46
+ sysdata = SystemData.new('name', empty_system_data)
47
+
48
+ expect(sysdata.all_data_present?).to eq false
49
+
50
+ sysdata.economy = 'econ'
51
+ expect(sysdata.all_data_present?).to eq false
52
+
53
+ sysdata.government = 'gov'
54
+ expect(sysdata.all_data_present?).to eq false
55
+
56
+ sysdata.tech_level = '12'
57
+ expect(sysdata.all_data_present?).to eq true
58
+ end
59
+ end
@@ -0,0 +1,37 @@
1
+ RSpec.describe SystemsData do
2
+
3
+ let(:test_config_path) { temp_from_data_dir('.oolite') }
4
+ let(:load_config) { Oolite.load_configuration(test_config_path) }
5
+
6
+ before do
7
+ load_config
8
+ end
9
+
10
+ it 'loads systems data from config' do
11
+ expect(SystemsData.systems.count).to be >= 28
12
+ ensoreus = SystemsData.systems['Ensoreus']
13
+
14
+ expect(ensoreus.name).to eq "Ensoreus"
15
+ expect(ensoreus.economy).to eq "Rich Industrial"
16
+ expect(ensoreus.government).to eq "Corporate State"
17
+ expect(ensoreus.tech_level).to eq "12"
18
+ end
19
+
20
+ it 'returns list of system names' do
21
+ names = SystemsData.names
22
+ expect(names).to include 'Ensoreus'
23
+ expect(names).to include 'Lave'
24
+ expect(names).to include 'Diso'
25
+ end
26
+
27
+ it 'adds to the list' do
28
+ expect(SystemsData.names).to_not include 'New System'
29
+ new_sys = SystemData.new('New System', { economy: 'Economy', government: 'Government', tech_level: '12'} )
30
+
31
+ SystemsData.add new_sys
32
+ expect(SystemsData.names).to include 'New System'
33
+ expect(SystemsData.systems['New System']).to eq new_sys
34
+
35
+ expect(file_contains(test_config_path, 'New SysteM'))
36
+ end
37
+ end
@@ -0,0 +1,120 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+ RSpec.configure do |config|
20
+ # rspec-expectations config goes here. You can use an alternate
21
+ # assertion/expectation library such as wrong or the stdlib/minitest
22
+ # assertions if you prefer.
23
+ config.expect_with :rspec do |expectations|
24
+ # This option will default to `true` in RSpec 4. It makes the `description`
25
+ # and `failure_message` of custom matchers include text for helper methods
26
+ # defined using `chain`, e.g.:
27
+ # be_bigger_than(2).and_smaller_than(4).description
28
+ # # => "be bigger than 2 and smaller than 4"
29
+ # ...rather than:
30
+ # # => "be bigger than 2"
31
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
32
+ end
33
+
34
+ # rspec-mocks config goes here. You can use an alternate test double
35
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
36
+ config.mock_with :rspec do |mocks|
37
+ # Prevents you from mocking or stubbing a method that does not exist on
38
+ # a real object. This is generally recommended, and will default to
39
+ # `true` in RSpec 4.
40
+ mocks.verify_partial_doubles = true
41
+ end
42
+
43
+ # The settings below are suggested to provide a good initial experience
44
+ # with RSpec, but feel free to customize to your heart's content.
45
+ #=begin
46
+ # These two settings work together to allow you to limit a spec run
47
+ # to individual examples or groups you care about by tagging them with
48
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
49
+ # get run.
50
+ config.filter_run :focus
51
+ config.run_all_when_everything_filtered = true
52
+
53
+ # Limits the available syntax to the non-monkey patched syntax that is
54
+ # recommended. For more details, see:
55
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
56
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
57
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
58
+ config.disable_monkey_patching!
59
+
60
+ # This setting enables warnings. It's recommended, but in some cases may
61
+ # be too noisy due to issues in dependencies.
62
+ config.warnings = false
63
+
64
+ # Many RSpec users commonly either run the entire suite or an individual
65
+ # file, and it's useful to allow more verbose output when running an
66
+ # individual spec file.
67
+ if config.files_to_run.one?
68
+ # Use the documentation formatter for detailed output,
69
+ # unless a formatter has already been configured
70
+ # (e.g. via a command-line flag).
71
+ config.default_formatter = 'doc'
72
+ end
73
+
74
+ # Print the 10 slowest examples and example groups at the
75
+ # end of the spec run, to help surface which specs are running
76
+ # particularly slow.
77
+ #config.profile_examples = 10
78
+
79
+ # Run specs in random order to surface order dependencies. If you find an
80
+ # order dependency and want to debug it, you can fix the order by providing
81
+ # the seed, which is printed after each run.
82
+ # --seed 1234
83
+ config.order = :random
84
+
85
+ # Seed global randomization in this process using the `--seed` CLI option.
86
+ # Setting this allows you to use `--seed` to deterministically reproduce
87
+ # test failures related to randomization by passing the same `--seed` value
88
+ # as the one that triggered the failure.
89
+ Kernel.srand config.seed
90
+ #=end
91
+ end
92
+
93
+ lib_dir = File.expand_path('../../lib', __FILE__)
94
+ $LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir)
95
+
96
+ require 'fileutils'
97
+ require 'oolite'
98
+ include Oolite
99
+
100
+ def test_data_dir sub_path = nil
101
+ path = File.expand_path('../data', __FILE__)
102
+ path = Pathname(path)
103
+ path = path + sub_path unless sub_path.nil?
104
+ path.to_s
105
+ end
106
+
107
+ def temp_from_data_dir sub_path = nil
108
+ src = test_data_dir sub_path
109
+ dest = Pathname('tmp') + sub_path
110
+ dest.delete if dest.exist?
111
+ FileUtils.cp src, dest
112
+ dest
113
+ end
114
+
115
+ def file_contains file, needle
116
+ File.open(file, 'r').each do |ln|
117
+ return true if ln.include? needle
118
+ end
119
+ return false
120
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oolite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff McAffee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-21 00:00:00.000000000 Z
11
+ date: 2015-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.2'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: nokogiri
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +66,20 @@ dependencies:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
68
  version: '1.6'
69
+ - !ruby/object:Gem::Dependency
70
+ name: highline
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.7'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.7'
55
83
  description: Utility scripts for tracking markets and assisting with trading in the
56
84
  Oolite game.
57
85
  email:
@@ -64,6 +92,7 @@ extensions: []
64
92
  extra_rdoc_files: []
65
93
  files:
66
94
  - ".gitignore"
95
+ - ".rspec"
67
96
  - Gemfile
68
97
  - LICENSE.txt
69
98
  - README.md
@@ -72,13 +101,20 @@ files:
72
101
  - bin/ootrader
73
102
  - bin/ooupdatemarket
74
103
  - lib/oolite.rb
104
+ - lib/oolite/console.rb
75
105
  - lib/oolite/csv_doc.rb
76
106
  - lib/oolite/market.rb
77
107
  - lib/oolite/market_file.rb
78
108
  - lib/oolite/save_file.rb
109
+ - lib/oolite/system_data.rb
110
+ - lib/oolite/systems_data.rb
79
111
  - lib/oolite/trade.rb
80
112
  - lib/oolite/version.rb
81
113
  - oolite.gemspec
114
+ - spec/data/.oolite
115
+ - spec/lib/oolite/system_data_spec.rb
116
+ - spec/lib/oolite/systems_data_spec.rb
117
+ - spec/spec_helper.rb
82
118
  homepage: https://github.com/jmcaffee/oolite
83
119
  licenses:
84
120
  - MIT
@@ -103,5 +139,9 @@ rubygems_version: 2.3.0
103
139
  signing_key:
104
140
  specification_version: 4
105
141
  summary: Utility scripts for the Oolite game
106
- test_files: []
142
+ test_files:
143
+ - spec/data/.oolite
144
+ - spec/lib/oolite/system_data_spec.rb
145
+ - spec/lib/oolite/systems_data_spec.rb
146
+ - spec/spec_helper.rb
107
147
  has_rdoc: