order_book 0.0.1
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.
- data/.gitignore +24 -0
- data/HISTORY +7 -0
- data/LICENSE +20 -0
- data/README.rdoc +25 -0
- data/Rakefile +25 -0
- data/VERSION +1 -0
- data/bin/order_book +13 -0
- data/features/order_book.feature +9 -0
- data/features/step_definitions/order_book_steps.rb +0 -0
- data/features/support/env.rb +10 -0
- data/features/support/world.rb +12 -0
- data/lib/legacy.rb +442 -0
- data/lib/order_book.rb +10 -0
- data/lib/order_book/order_book.rb +0 -0
- data/lib/order_book/order_book_item.rb +0 -0
- data/lib/order_book/order_book_list.rb +0 -0
- data/lib/order_book/order_list.rb +0 -0
- data/lib/order_book/sorted_list.rb +8 -0
- data/lib/version.rb +8 -0
- data/spec/order_book/order_book_item_spec.rb +7 -0
- data/spec/order_book/order_book_list_spec.rb +7 -0
- data/spec/order_book/order_book_spec.rb +7 -0
- data/spec/order_book/order_list_spec.rb +7 -0
- data/spec/order_book/sorted_list_spec.rb +6 -0
- data/spec/spec_helper.rb +17 -0
- data/tasks/common.rake +18 -0
- data/tasks/doc.rake +14 -0
- data/tasks/gem.rake +40 -0
- data/tasks/git.rake +34 -0
- data/tasks/spec.rake +16 -0
- data/tasks/version.rake +71 -0
- metadata +130 -0
data/.gitignore
ADDED
data/HISTORY
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Arvicco
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
= order_book
|
2
|
+
by: Arvicco
|
3
|
+
url: http://github.com/arvicco/order_book
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
Basic structures used to create DOM models.
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
OrderBook structures are used to accumulate, analyse and visualize streams of market
|
12
|
+
order data (either in aggregated or full order log form). They are required by the
|
13
|
+
client and gateway modules that deal with market order data streams/artefacts.
|
14
|
+
|
15
|
+
OrderBook data structures need to be:
|
16
|
+
1) memory-efficient
|
17
|
+
2) thread-safe (without too much synchronization penalty)
|
18
|
+
3) iteration-safe (adding new element while iterating should not raise exception)
|
19
|
+
|
20
|
+
== INSTALL:
|
21
|
+
|
22
|
+
$ sudo gem install order_book
|
23
|
+
|
24
|
+
== LICENSE:
|
25
|
+
Copyright (c) 2011 Arvicco. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
begin
|
2
|
+
require 'rake'
|
3
|
+
rescue LoadError
|
4
|
+
require 'rubygems'
|
5
|
+
gem 'rake', '~> 0.8.3.1'
|
6
|
+
require 'rake'
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
|
11
|
+
BASE_PATH = Pathname.new(__FILE__).dirname
|
12
|
+
LIB_PATH = BASE_PATH + 'lib'
|
13
|
+
PKG_PATH = BASE_PATH + 'pkg'
|
14
|
+
DOC_PATH = BASE_PATH + 'rdoc'
|
15
|
+
|
16
|
+
$LOAD_PATH.unshift LIB_PATH.to_s
|
17
|
+
require 'version'
|
18
|
+
|
19
|
+
NAME = 'order_book'
|
20
|
+
CLASS_NAME = OrderBook
|
21
|
+
|
22
|
+
# Load rakefile tasks
|
23
|
+
Dir['tasks/*.rake'].sort.each { |file| load file }
|
24
|
+
|
25
|
+
# Project-specific tasks
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/bin/order_book
ADDED
File without changes
|
data/lib/legacy.rb
ADDED
@@ -0,0 +1,442 @@
|
|
1
|
+
# Legacy VCL-based code to be converted into new efficient Ruby code
|
2
|
+
|
3
|
+
module VCL
|
4
|
+
|
5
|
+
#type
|
6
|
+
# tDuplicates = [:dup_accept, :dup_ignore, :dup_replace]
|
7
|
+
# // ������� ����� "������" � ���������� ��������������� ������������ ���������
|
8
|
+
#type CustomList = class(tList)
|
9
|
+
# procedure clear; override;
|
10
|
+
# procedure freeitem(item: pointer); virtual; abstract;
|
11
|
+
# procedure freeall; virtual;
|
12
|
+
# procedure delete(index: longint); virtual;
|
13
|
+
# procedure remove(item: pointer); virtual;
|
14
|
+
# end;
|
15
|
+
class CustomList < Array
|
16
|
+
|
17
|
+
def clear
|
18
|
+
(0...size).each { freeitem(self[i]) }
|
19
|
+
super
|
20
|
+
end
|
21
|
+
|
22
|
+
def freeall
|
23
|
+
clear
|
24
|
+
end
|
25
|
+
|
26
|
+
def freeitem item
|
27
|
+
end
|
28
|
+
|
29
|
+
# Standard #delete_at instead of #delete
|
30
|
+
|
31
|
+
# Deletes ALL items from arr that are equal to obj.?
|
32
|
+
# No, we need to remove ONE item by "pointer"
|
33
|
+
def remove item #(item: pointer)
|
34
|
+
freeitem item
|
35
|
+
delete item
|
36
|
+
end
|
37
|
+
end # class CustomList
|
38
|
+
|
39
|
+
# // ������� ����� "������������� ������"
|
40
|
+
#type tSortedList = class(CustomList)
|
41
|
+
# fDuplicates : tDuplicates;
|
42
|
+
# constructor create;
|
43
|
+
# function checkitem(item: pointer): boolean; virtual; abstract;
|
44
|
+
# function compare(item1, item2: pointer): longint; virtual; abstract;
|
45
|
+
# function search(item: pointer; var index: longint): boolean; virtual;
|
46
|
+
# procedure add(item: pointer); virtual;
|
47
|
+
# procedure insert(index: longint; item: pointer); virtual;
|
48
|
+
# end;
|
49
|
+
class SortedList < CustomList
|
50
|
+
|
51
|
+
attr_accessor :duplicates
|
52
|
+
|
53
|
+
def initialize
|
54
|
+
@duplicates = :dup_accept
|
55
|
+
super
|
56
|
+
end
|
57
|
+
|
58
|
+
# Returns true and item's index if item is in the List
|
59
|
+
# Returns false and item's index if item not found
|
60
|
+
def search item #(item: pointer; var index: longint): boolean
|
61
|
+
result = false
|
62
|
+
l = 0
|
63
|
+
h = size - 1
|
64
|
+
while (l <= h) do
|
65
|
+
i = (l + h) >> 1
|
66
|
+
case compare(self[i], item)
|
67
|
+
when -1
|
68
|
+
l = i + 1
|
69
|
+
when 1
|
70
|
+
h = i - 1
|
71
|
+
when 0
|
72
|
+
h = i - 1
|
73
|
+
result = true
|
74
|
+
l = i if @duplicates == :dup_ignore || @duplicates == :dup_replace
|
75
|
+
end
|
76
|
+
end
|
77
|
+
index = l
|
78
|
+
[result, index]
|
79
|
+
end
|
80
|
+
|
81
|
+
def add item #(item: pointer)
|
82
|
+
if checkitem(item)
|
83
|
+
result, index = search(item)
|
84
|
+
if result
|
85
|
+
case @duplicates
|
86
|
+
when :dup_accept
|
87
|
+
insert(index, item)
|
88
|
+
when :dup_ignore
|
89
|
+
freeitem(item)
|
90
|
+
when :dup_replace
|
91
|
+
freeitem(self[index])
|
92
|
+
self[index] = item
|
93
|
+
end
|
94
|
+
else
|
95
|
+
insert(index, item)
|
96
|
+
end
|
97
|
+
else
|
98
|
+
freeitem(item)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def insert index, item #(index: longint; item: pointer)
|
103
|
+
if checkitem(item)
|
104
|
+
super index, item
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end # class SortedList
|
108
|
+
|
109
|
+
# // ������ ������� �� ����
|
110
|
+
#type tOrderBook = class(tSortedList)
|
111
|
+
# private
|
112
|
+
# fisin_id : longint;
|
113
|
+
# fchanged : boolean;
|
114
|
+
# public
|
115
|
+
# procedure freeitem(item: pointer); override;
|
116
|
+
# function checkitem(item: pointer): boolean; override;
|
117
|
+
# function compare(item1, item2: pointer): longint; override;
|
118
|
+
#
|
119
|
+
# procedure add(item: pointer); override;
|
120
|
+
# procedure remove(item: pointer); override;
|
121
|
+
#
|
122
|
+
# property isin_id: longint read fisin_id;
|
123
|
+
# property changed: boolean read fchanged write fchanged;
|
124
|
+
# end;
|
125
|
+
class OrderBook < SortedList
|
126
|
+
attr_accessor :isin_id, :changed
|
127
|
+
|
128
|
+
def initialize isin_id
|
129
|
+
@isin_id = isin_id
|
130
|
+
super()
|
131
|
+
end
|
132
|
+
|
133
|
+
def checkitem item #(item: pointer): boolean
|
134
|
+
item.price > 0
|
135
|
+
end
|
136
|
+
|
137
|
+
def compare item1, item2 #(item1, item2: pointer): longint
|
138
|
+
item1.price <=> item2.price
|
139
|
+
end
|
140
|
+
|
141
|
+
def add item #(item: pointer)
|
142
|
+
super item
|
143
|
+
@changed = true
|
144
|
+
end
|
145
|
+
|
146
|
+
def remove item #(item: pointer)
|
147
|
+
super item
|
148
|
+
@changed = true
|
149
|
+
end
|
150
|
+
end # class OrderBook
|
151
|
+
|
152
|
+
# // ������ ��������
|
153
|
+
#type tPriceLists = class(tSortedList)
|
154
|
+
# private
|
155
|
+
# tmp_ordbook : tOrderBook;
|
156
|
+
# public
|
157
|
+
# destructor destroy; override;
|
158
|
+
# procedure freeitem(item: pointer); override;
|
159
|
+
# function checkitem(item: pointer): boolean; override;
|
160
|
+
# function compare(item1, item2: pointer): longint; override;
|
161
|
+
# function searchadditem(isin_id: longint): tOrderBook;
|
162
|
+
# end;
|
163
|
+
#
|
164
|
+
class OrderBookList < SortedList
|
165
|
+
|
166
|
+
def checkitem item #(item: pointer): boolean
|
167
|
+
item
|
168
|
+
end
|
169
|
+
|
170
|
+
def compare(item1, item2) #(item1, item2: pointer): longint
|
171
|
+
item1.isin_id <=> item2.isin_id;
|
172
|
+
end
|
173
|
+
|
174
|
+
def searchadditem(isin_id) #(isin_id: longint): OrderBook
|
175
|
+
order_book = OrderBook.new(isin_id)
|
176
|
+
exists, idx = search(order_book)
|
177
|
+
if exists
|
178
|
+
result = self[idx]
|
179
|
+
else
|
180
|
+
result = order_book
|
181
|
+
insert(idx, result)
|
182
|
+
end
|
183
|
+
result
|
184
|
+
end
|
185
|
+
|
186
|
+
end # class OrderBook
|
187
|
+
|
188
|
+
# // ����� ������� ���������
|
189
|
+
#type OrderList = class(tSortedList)
|
190
|
+
# fOrderBooks : tPriceLists;
|
191
|
+
# constructor create;
|
192
|
+
# destructor destroy; override;
|
193
|
+
# procedure freeitem(item: pointer); override;
|
194
|
+
# function checkitem(item: pointer): boolean; override;
|
195
|
+
# function compare(item1, item2: pointer): longint; override;
|
196
|
+
# function searchadditem(isin_id: longint): tOrderBook;
|
197
|
+
# function addrecord(isin_id: longint; const id, rev: int64; const price, volume: double; buysell: longint): boolean;
|
198
|
+
# function delrecord(const id: int64): boolean;
|
199
|
+
# procedure clearbyrev(const rev: int64);
|
200
|
+
# end;
|
201
|
+
class OrderList < SortedList
|
202
|
+
attr_accessor :order_books
|
203
|
+
|
204
|
+
def initialize
|
205
|
+
super
|
206
|
+
@order_books = OrderBookList.new
|
207
|
+
end
|
208
|
+
|
209
|
+
def freeitem item #(item: pointer)
|
210
|
+
item.order_book.remove(item) if item.order_book
|
211
|
+
end
|
212
|
+
|
213
|
+
def checkitem item #(item: pointer): boolean
|
214
|
+
item
|
215
|
+
end
|
216
|
+
|
217
|
+
def compare(item1, item2) #: pointer): longint
|
218
|
+
item1.id <=> item2.id
|
219
|
+
end
|
220
|
+
|
221
|
+
def searchadditem isin_id #(isin_id: longint): OrderBook
|
222
|
+
@order_books.searchadditem(isin_id)
|
223
|
+
end
|
224
|
+
|
225
|
+
def addrecord isin_id, id, rev, price, volume, buysell #(isin_id: longint; const id, rev: int64; const price, volume: double; buysell: longint): boolean
|
226
|
+
item = OrderBookItem.new
|
227
|
+
item.id = id
|
228
|
+
result, idx = search(item)
|
229
|
+
if result
|
230
|
+
item = self[idx]
|
231
|
+
|
232
|
+
if item.price != price # �������, ��� ���� ����������
|
233
|
+
item.order_book.remove(item) if item.order_book # ������� �� �������
|
234
|
+
if price > 0
|
235
|
+
item.order_book = searchadditem(isin_id) unless item.order_book
|
236
|
+
item.order_book.add(item) if item.order_book # ��������� � ������
|
237
|
+
else
|
238
|
+
item.order_book = nil;
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
item.rev = rev
|
243
|
+
item.price = price
|
244
|
+
item.volume = volume
|
245
|
+
item.buysell = buysell
|
246
|
+
else
|
247
|
+
item.rev = rev
|
248
|
+
item.price = price
|
249
|
+
item.volume = volume
|
250
|
+
item.buysell = buysell
|
251
|
+
|
252
|
+
if (item.price > 0)
|
253
|
+
item.order_book = searchadditem(isin_id)
|
254
|
+
item.order_book.add(item) if item.order_book # ��������� � ������
|
255
|
+
else
|
256
|
+
item.order_book = nil
|
257
|
+
end
|
258
|
+
insert(idx, item) # ��������� � ����� �������
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
def delrecord id #(const id: int64): boolean
|
263
|
+
item = OrderBookItem.new
|
264
|
+
item.id = id
|
265
|
+
result, idx = search(item)
|
266
|
+
delete_at(idx) if result # ������� �� ����� �������
|
267
|
+
end
|
268
|
+
|
269
|
+
# Delete all records with rev less than given
|
270
|
+
def clearbyrev rev #(const rev: int64)
|
271
|
+
(size-1).downto(0) do |i|
|
272
|
+
delete_at(i) if self[i].rev < rev # ������� �� ����� �������
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
end #class OrderList
|
277
|
+
|
278
|
+
# // ������� "������ � �������"
|
279
|
+
#type pOrderBookItem = ^tOrderBookItem;
|
280
|
+
# tOrderBookItem = record
|
281
|
+
# id : int64;
|
282
|
+
# rev : int64;
|
283
|
+
# price : double; // ����
|
284
|
+
# volume : double; // ���-��
|
285
|
+
# buysell : longint; // �������(1)/�������(2)
|
286
|
+
# order_book : tOrderBook;
|
287
|
+
# end;
|
288
|
+
class OrderBookItem
|
289
|
+
attr_accessor :id, :rev, :price, :volume, :buysell, :order_book
|
290
|
+
|
291
|
+
def inspect
|
292
|
+
"#{id}:#{price}>#{volume}#{buysell == 1 ? '+' : '-'}"
|
293
|
+
end
|
294
|
+
|
295
|
+
alias to_s inspect
|
296
|
+
end
|
297
|
+
|
298
|
+
#######################
|
299
|
+
# New hierarchy:
|
300
|
+
#######################
|
301
|
+
|
302
|
+
# Abstract (equivalent of SortedList)
|
303
|
+
# ������� ����� "������������� ������"
|
304
|
+
class SortedHash < Hash
|
305
|
+
|
306
|
+
def free item
|
307
|
+
end
|
308
|
+
|
309
|
+
def check item
|
310
|
+
true
|
311
|
+
end
|
312
|
+
|
313
|
+
def index item
|
314
|
+
item.object_id
|
315
|
+
end
|
316
|
+
|
317
|
+
# Adds new item only if it passes check...
|
318
|
+
# TODO: What to do with the item it should have replaced?!
|
319
|
+
def add item
|
320
|
+
self[index item] = item if check item
|
321
|
+
# check item ? super : free key # delete key
|
322
|
+
end
|
323
|
+
|
324
|
+
def remove item
|
325
|
+
free item
|
326
|
+
delete index item
|
327
|
+
end
|
328
|
+
|
329
|
+
def clear
|
330
|
+
each_value { |item| free item }
|
331
|
+
super
|
332
|
+
end
|
333
|
+
end # SortedHash
|
334
|
+
|
335
|
+
# Represents DOM (OrderBook) for one security
|
336
|
+
# ������ ������� �� ����
|
337
|
+
class DOM < SortedHash
|
338
|
+
attr_accessor :isin_id, :changed
|
339
|
+
|
340
|
+
def initialize isin_id
|
341
|
+
@isin_id = isin_id
|
342
|
+
@changed = false
|
343
|
+
super
|
344
|
+
end
|
345
|
+
|
346
|
+
def index item
|
347
|
+
item.price
|
348
|
+
end
|
349
|
+
|
350
|
+
def check item
|
351
|
+
item.price > 0
|
352
|
+
end
|
353
|
+
|
354
|
+
def add item
|
355
|
+
@changed = true # Marking DOM as changed
|
356
|
+
super
|
357
|
+
end
|
358
|
+
|
359
|
+
def remove item
|
360
|
+
@changed = true # Marking DOM as changed
|
361
|
+
super
|
362
|
+
end
|
363
|
+
end # class DOM
|
364
|
+
|
365
|
+
|
366
|
+
# Represents Hash of DOMs (OrderBooks) indexed by isin_id
|
367
|
+
# ������ ��������
|
368
|
+
class DOMHash < SortedHash
|
369
|
+
|
370
|
+
def index item
|
371
|
+
item.isin_id
|
372
|
+
end
|
373
|
+
|
374
|
+
# Always return DOM for isin_id, create one on spot if need be
|
375
|
+
def [] isin_id
|
376
|
+
super || add(DOM.new isin_id)
|
377
|
+
end
|
378
|
+
end # class DOMHash
|
379
|
+
|
380
|
+
# Represents Hash of all aggregated orders by (repl) id
|
381
|
+
# ����� ������� ���������
|
382
|
+
class OrderHash < SortedHash
|
383
|
+
attr_accessor :order_books
|
384
|
+
|
385
|
+
def index item
|
386
|
+
item.id
|
387
|
+
end
|
388
|
+
|
389
|
+
def initialize
|
390
|
+
super
|
391
|
+
@order_books = DOMHash.new
|
392
|
+
end
|
393
|
+
|
394
|
+
# We need to clear item from its order book before scrapping it
|
395
|
+
def free item
|
396
|
+
item.order_book.remove item if item.order_book
|
397
|
+
end
|
398
|
+
|
399
|
+
# Rebooks item to a correct order book, given its price
|
400
|
+
def rebook item, book
|
401
|
+
if (item.price > 0)
|
402
|
+
# item represents new aggr_order with price
|
403
|
+
item.order_book = book unless item.order_book
|
404
|
+
book.add item # ��������� � ������
|
405
|
+
else
|
406
|
+
# item clears previous aggr_order for given price
|
407
|
+
item.order_book = nil
|
408
|
+
end
|
409
|
+
end
|
410
|
+
|
411
|
+
def addrecord isin_id, id, rev, price, volume, buysell
|
412
|
+
item = self[id] || OrderBookItem.new
|
413
|
+
|
414
|
+
price_changed = item.price != price # �������, ��� ���� ����������
|
415
|
+
|
416
|
+
item.id = id
|
417
|
+
item.rev = rev
|
418
|
+
item.price = price
|
419
|
+
item.volume = volume
|
420
|
+
item.buysell = buysell
|
421
|
+
|
422
|
+
if price_changed
|
423
|
+
if self[id] # item is already here
|
424
|
+
item.order_book.remove item if item.order_book # free item - ������� �� �������
|
425
|
+
else # new item
|
426
|
+
add item
|
427
|
+
end
|
428
|
+
rebook item, @order_books[isin_id]
|
429
|
+
end
|
430
|
+
end
|
431
|
+
|
432
|
+
def delrecord id
|
433
|
+
remove self[id] if self[id]
|
434
|
+
end
|
435
|
+
|
436
|
+
# Clear all records with rev less than given
|
437
|
+
def clearbyrev rev #(const rev: int64)
|
438
|
+
each_value { |item| remove item if item.rev < rev } # ������� �� ����� �������
|
439
|
+
end
|
440
|
+
end # class OrderHash
|
441
|
+
|
442
|
+
end # module
|
data/lib/order_book.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'version'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'bundler/setup'
|
4
|
+
Bundler.require(:default)
|
5
|
+
|
6
|
+
require 'order_book/sorted_list'
|
7
|
+
require 'order_book/order_book_item'
|
8
|
+
require 'order_book/order_book'
|
9
|
+
require 'order_book/order_book_list'
|
10
|
+
require 'order_book/order_list'
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/lib/version.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'order_book'
|
2
|
+
require 'pathname'
|
3
|
+
|
4
|
+
require 'bundler'
|
5
|
+
Bundler.setup
|
6
|
+
Bundler.require :test
|
7
|
+
|
8
|
+
BASE_PATH = Pathname.new(__FILE__).dirname + '..'
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
# config.exclusion_filter = { :slow => true }
|
12
|
+
# config.filter = { :focus => true }
|
13
|
+
# config.include(UserExampleHelpers)
|
14
|
+
# config.mock_with :mocha
|
15
|
+
# config.mock_with :flexmock
|
16
|
+
# config.mock_with :rr
|
17
|
+
end
|
data/tasks/common.rake
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#task :default => 'test:run'
|
2
|
+
#task 'gem:release' => 'test:run'
|
3
|
+
|
4
|
+
task :notes do
|
5
|
+
puts 'Output annotations (TBD)'
|
6
|
+
end
|
7
|
+
|
8
|
+
#Bundler not ready for prime time just yet
|
9
|
+
#desc 'Bundle dependencies'
|
10
|
+
#task :bundle do
|
11
|
+
# output = `bundle check 2>&1`
|
12
|
+
#
|
13
|
+
# unless $?.to_i == 0
|
14
|
+
# puts output
|
15
|
+
# system "bundle install"
|
16
|
+
# puts
|
17
|
+
# end
|
18
|
+
#end
|
data/tasks/doc.rake
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
desc 'Alias to doc:rdoc'
|
2
|
+
task :doc => 'doc:rdoc'
|
3
|
+
|
4
|
+
namespace :doc do
|
5
|
+
require 'rake/rdoctask'
|
6
|
+
Rake::RDocTask.new do |rdoc|
|
7
|
+
# Rake::RDocTask.new(:rdoc => "rdoc", :clobber_rdoc => "clobber", :rerdoc => "rerdoc") do |rdoc|
|
8
|
+
rdoc.rdoc_dir = DOC_PATH.basename.to_s
|
9
|
+
rdoc.title = "#{NAME} #{CLASS_NAME::VERSION} Documentation"
|
10
|
+
rdoc.main = "README.doc"
|
11
|
+
rdoc.rdoc_files.include('README*')
|
12
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
13
|
+
end
|
14
|
+
end
|
data/tasks/gem.rake
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
desc "Alias to gem:release"
|
2
|
+
task :release => 'gem:release'
|
3
|
+
|
4
|
+
desc "Alias to gem:install"
|
5
|
+
task :install => 'gem:install'
|
6
|
+
|
7
|
+
desc "Alias to gem:build"
|
8
|
+
task :gem => 'gem:build'
|
9
|
+
|
10
|
+
namespace :gem do
|
11
|
+
gem_file = "#{NAME}-#{CLASS_NAME::VERSION}.gem"
|
12
|
+
|
13
|
+
desc "(Re-)Build gem"
|
14
|
+
task :build do
|
15
|
+
puts "Remove existing gem package"
|
16
|
+
rm_rf PKG_PATH
|
17
|
+
puts "Build new gem package"
|
18
|
+
system "gem build #{NAME}.gemspec"
|
19
|
+
puts "Move built gem to package dir"
|
20
|
+
mkdir_p PKG_PATH
|
21
|
+
mv gem_file, PKG_PATH
|
22
|
+
end
|
23
|
+
|
24
|
+
desc "Cleanup already installed gem(s)"
|
25
|
+
task :cleanup do
|
26
|
+
puts "Cleaning up installed gem(s)"
|
27
|
+
system "gem cleanup #{NAME}"
|
28
|
+
end
|
29
|
+
|
30
|
+
desc "Build and install gem"
|
31
|
+
task :install => :build do
|
32
|
+
system "gem install #{PKG_PATH}/#{gem_file}"
|
33
|
+
end
|
34
|
+
|
35
|
+
desc "Build and push gem to Gemcutter"
|
36
|
+
task :release => [:build, 'git:tag'] do
|
37
|
+
puts "Pushing gem to Gemcutter"
|
38
|
+
system "gem push #{PKG_PATH}/#{gem_file}"
|
39
|
+
end
|
40
|
+
end
|
data/tasks/git.rake
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
desc "Alias to git:commit"
|
2
|
+
task :git => 'git:commit'
|
3
|
+
|
4
|
+
namespace :git do
|
5
|
+
|
6
|
+
desc "Stage and commit your work [with message]"
|
7
|
+
task :commit, [:message] do |t, args|
|
8
|
+
puts "Staging new (unversioned) files"
|
9
|
+
system "git add --all"
|
10
|
+
if args.message
|
11
|
+
puts "Committing with message: #{args.message}"
|
12
|
+
system %Q[git commit -a -m "#{args.message}" --author arvicco]
|
13
|
+
else
|
14
|
+
puts "Committing"
|
15
|
+
system %Q[git commit -a -m "No message" --author arvicco]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
desc "Push local changes to Github"
|
20
|
+
task :push => :commit do
|
21
|
+
puts "Pushing local changes to remote"
|
22
|
+
system "git push"
|
23
|
+
end
|
24
|
+
|
25
|
+
desc "Create (release) tag on Github"
|
26
|
+
task :tag => :push do
|
27
|
+
tag = CLASS_NAME::VERSION
|
28
|
+
puts "Creating git tag: #{tag}"
|
29
|
+
system %Q{git tag -a -m "Release tag #{tag}" #{tag}}
|
30
|
+
puts "Pushing #{tag} to remote"
|
31
|
+
system "git push origin #{tag}"
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
data/tasks/spec.rake
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
desc 'Alias to spec:spec'
|
2
|
+
task :spec => 'spec:spec'
|
3
|
+
|
4
|
+
namespace :spec do
|
5
|
+
# require 'spec/rake/spectask'
|
6
|
+
require 'rspec/core/rake_task'
|
7
|
+
|
8
|
+
desc "Run all specs"
|
9
|
+
RSpec::Core::RakeTask.new(:spec){|task|}
|
10
|
+
|
11
|
+
desc "Run specs with RCov"
|
12
|
+
RSpec::Core::RakeTask.new(:rcov) do |task|
|
13
|
+
task.rcov = true
|
14
|
+
task.rcov_opts = ['--exclude', 'spec']
|
15
|
+
end
|
16
|
+
end
|
data/tasks/version.rake
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
class Version
|
2
|
+
attr_accessor :major, :minor, :patch, :build
|
3
|
+
|
4
|
+
def initialize(version_string)
|
5
|
+
raise "Invalid version #{version_string}" unless version_string =~ /^(\d+)\.(\d+)\.(\d+)(?:\.(.*?))?$/
|
6
|
+
@major = $1.to_i
|
7
|
+
@minor = $2.to_i
|
8
|
+
@patch = $3.to_i
|
9
|
+
@build = $4
|
10
|
+
end
|
11
|
+
|
12
|
+
def bump_major(x)
|
13
|
+
@major += x.to_i
|
14
|
+
@minor = 0
|
15
|
+
@patch = 0
|
16
|
+
@build = nil
|
17
|
+
end
|
18
|
+
|
19
|
+
def bump_minor(x)
|
20
|
+
@minor += x.to_i
|
21
|
+
@patch = 0
|
22
|
+
@build = nil
|
23
|
+
end
|
24
|
+
|
25
|
+
def bump_patch(x)
|
26
|
+
@patch += x.to_i
|
27
|
+
@build = nil
|
28
|
+
end
|
29
|
+
|
30
|
+
def update(major, minor, patch, build=nil)
|
31
|
+
@major = major
|
32
|
+
@minor = minor
|
33
|
+
@patch = patch
|
34
|
+
@build = build
|
35
|
+
end
|
36
|
+
|
37
|
+
def write(desc = nil)
|
38
|
+
CLASS_NAME::VERSION_FILE.open('w') {|file| file.puts to_s }
|
39
|
+
(BASE_PATH + 'HISTORY').open('a') do |file|
|
40
|
+
file.puts "\n== #{to_s} / #{Time.now.strftime '%Y-%m-%d'}\n"
|
41
|
+
file.puts "\n* #{desc}\n" if desc
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def to_s
|
46
|
+
[major, minor, patch, build].compact.join('.')
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
desc 'Set version: [x.y.z] - explicitly, [1/10/100] - bump major/minor/patch, [.build] - build'
|
51
|
+
task :version, [:command, :desc] do |t, args|
|
52
|
+
version = Version.new(CLASS_NAME::VERSION)
|
53
|
+
case args.command
|
54
|
+
when /^(\d+)\.(\d+)\.(\d+)(?:\.(.*?))?$/ # Set version explicitly
|
55
|
+
version.update($1, $2, $3, $4)
|
56
|
+
when /^\.(.*?)$/ # Set build
|
57
|
+
version.build = $1
|
58
|
+
when /^(\d{1})$/ # Bump patch
|
59
|
+
version.bump_patch $1
|
60
|
+
when /^(\d{1})0$/ # Bump minor
|
61
|
+
version.bump_minor $1
|
62
|
+
when /^(\d{1})00$/ # Bump major
|
63
|
+
version.bump_major $1
|
64
|
+
else # Unknown command, just display VERSION
|
65
|
+
puts "#{NAME} #{version}"
|
66
|
+
next
|
67
|
+
end
|
68
|
+
|
69
|
+
puts "Writing version #{version} to VERSION file"
|
70
|
+
version.write args.desc
|
71
|
+
end
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: order_book
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- arvicco
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-03-18 00:00:00 +03:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: rspec
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 2.0.0
|
25
|
+
type: :development
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: cucumber
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: "0"
|
36
|
+
type: :development
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: bundler
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 1.0.0
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id003
|
49
|
+
description: Basic structures used to create DOM models
|
50
|
+
email: arvitallian@gmail.com
|
51
|
+
executables:
|
52
|
+
- order_book
|
53
|
+
extensions: []
|
54
|
+
|
55
|
+
extra_rdoc_files:
|
56
|
+
- LICENSE
|
57
|
+
- HISTORY
|
58
|
+
- README.rdoc
|
59
|
+
files:
|
60
|
+
- bin/order_book
|
61
|
+
- lib/legacy.rb
|
62
|
+
- lib/order_book/order_book.rb
|
63
|
+
- lib/order_book/order_book_item.rb
|
64
|
+
- lib/order_book/order_book_list.rb
|
65
|
+
- lib/order_book/order_list.rb
|
66
|
+
- lib/order_book/sorted_list.rb
|
67
|
+
- lib/order_book.rb
|
68
|
+
- lib/version.rb
|
69
|
+
- spec/order_book/order_book_item_spec.rb
|
70
|
+
- spec/order_book/order_book_list_spec.rb
|
71
|
+
- spec/order_book/order_book_spec.rb
|
72
|
+
- spec/order_book/order_list_spec.rb
|
73
|
+
- spec/order_book/sorted_list_spec.rb
|
74
|
+
- spec/spec_helper.rb
|
75
|
+
- features/order_book.feature
|
76
|
+
- features/step_definitions/order_book_steps.rb
|
77
|
+
- features/support/env.rb
|
78
|
+
- features/support/world.rb
|
79
|
+
- tasks/common.rake
|
80
|
+
- tasks/doc.rake
|
81
|
+
- tasks/gem.rake
|
82
|
+
- tasks/git.rake
|
83
|
+
- tasks/spec.rake
|
84
|
+
- tasks/version.rake
|
85
|
+
- Rakefile
|
86
|
+
- README.rdoc
|
87
|
+
- LICENSE
|
88
|
+
- VERSION
|
89
|
+
- HISTORY
|
90
|
+
- .gitignore
|
91
|
+
has_rdoc: true
|
92
|
+
homepage: http://github.com/arvicco/order_book
|
93
|
+
licenses: []
|
94
|
+
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options:
|
97
|
+
- --charset
|
98
|
+
- UTF-8
|
99
|
+
- --main
|
100
|
+
- README.rdoc
|
101
|
+
- --title
|
102
|
+
- order_book
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: "0"
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
none: false
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: "0"
|
117
|
+
requirements: []
|
118
|
+
|
119
|
+
rubyforge_project:
|
120
|
+
rubygems_version: 1.5.0
|
121
|
+
signing_key:
|
122
|
+
specification_version: 3
|
123
|
+
summary: Basic structures for DOM models
|
124
|
+
test_files:
|
125
|
+
- spec/order_book/order_book_item_spec.rb
|
126
|
+
- spec/order_book/order_book_list_spec.rb
|
127
|
+
- spec/order_book/order_book_spec.rb
|
128
|
+
- spec/order_book/order_list_spec.rb
|
129
|
+
- spec/order_book/sorted_list_spec.rb
|
130
|
+
- spec/spec_helper.rb
|