Class: IB::IBSocket
Instance Method Summary collapse
-
#read_array(&block) ⇒ Object
Returns loaded Array or [] if count was 0.
- #read_boolean ⇒ Object
- #read_decimal ⇒ Object
-
#read_decimal_limit(limit = -1) ⇒ Object
(also: #read_decimal_limit_1)
If received decimal is below limit (“not yet computed”), return nil.
- #read_decimal_limit_2 ⇒ Object
- #read_decimal_max ⇒ Object
-
#read_hash ⇒ Object
Returns loaded Hash.
- #read_int ⇒ Object
- #read_int_max ⇒ Object
- #read_string ⇒ Object
-
#write_data(data) ⇒ Object
Sends null terminated data string into socket.
Instance Method Details
#read_array(&block) ⇒ Object
Returns loaded Array or [] if count was 0
68 69 70 71 |
# File 'lib/ib/socket.rb', line 68 def read_array &block count = read_int count > 0 ? Array.new(count, &block) : [] end |
#read_boolean ⇒ Object
32 33 34 35 |
# File 'lib/ib/socket.rb', line 32 def read_boolean str = self.read_string str.nil? ? false : str.to_i != 0 end |
#read_decimal ⇒ Object
37 38 39 40 41 42 |
# File 'lib/ib/socket.rb', line 37 def read_decimal # Floating-point numbers shouldn't be used to store money... # ...but BigDecimals are too unwieldy to use in this case... maybe later # self.read_string.to_d self.read_string.to_f end |
#read_decimal_limit(limit = -1) ⇒ Object Also known as: read_decimal_limit_1
If received decimal is below limit (“not yet computed”), return nil
53 54 55 56 57 |
# File 'lib/ib/socket.rb', line 53 def read_decimal_limit limit = -1 value = self.read_decimal # limit is the "not yet computed" indicator value <= limit ? nil : value end |
#read_decimal_limit_2 ⇒ Object
61 62 63 |
# File 'lib/ib/socket.rb', line 61 def read_decimal_limit_2 read_decimal_limit -2 end |
#read_decimal_max ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/ib/socket.rb', line 44 def read_decimal_max str = self.read_string # Floating-point numbers shouldn't be used to store money... # ...but BigDecimals are too unwieldy to use in this case... maybe later # str.nil? || str.empty? ? nil : str.to_d str.to_f unless str.nil? || str.empty? || str.to_f > 1.797 * 10.0 ** 306 end |
#read_hash ⇒ Object
Returns loaded Hash
74 75 76 77 |
# File 'lib/ib/socket.rb', line 74 def read_hash = read_array { |_| [read_string, read_string] } .empty? ? Hash.new : Hash[*.flatten] end |
#read_int ⇒ Object
23 24 25 |
# File 'lib/ib/socket.rb', line 23 def read_int self.read_string.to_i end |
#read_int_max ⇒ Object
27 28 29 30 |
# File 'lib/ib/socket.rb', line 27 def read_int_max str = self.read_string str.to_i unless str.nil? || str.empty? end |