Sha256: 2ffa360d64d183e677071a01c015dbdc7339392a96cf8c1bbfc0eebc0f75f12d

Contents?: true

Size: 1.01 KB

Versions: 9

Compression:

Stored size: 1.01 KB

Contents

require 'socket'

module IB
  class IBSocket < TCPSocket

    # send nice null terminated binary data into socket
    def send data
      self.syswrite(data.to_s + EOL)
    end

    def read_string
      self.gets(EOL).chop
    end

    def read_int
      self.read_string.to_i
    end

    def read_int_max
      str = self.read_string
      str.nil? || str.empty? ? nil : str.to_i
    end

    def read_boolean
      self.read_string.to_i != 0
    end

    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

    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.nil? || str.empty? ? nil : str.to_f
    end
  end # class IBSocket

end # module IB

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
ib-ruby-0.5.15 lib/ib-ruby/socket.rb
ib-ruby-0.5.14 lib/ib-ruby/socket.rb
ib-ruby-0.5.13 lib/ib-ruby/socket.rb
ib-ruby-0.5.12 lib/ib-ruby/socket.rb
ib-ruby-0.5.11 lib/ib-ruby/socket.rb
ib-ruby-0.5.10 lib/ib-ruby/socket.rb
ib-ruby-0.5.9 lib/ib-ruby/socket.rb
ib-ruby-0.5.7 lib/ib-ruby/socket.rb
ib-ruby-0.5.2 lib/ib-ruby/socket.rb