Class: IbRubyProxy::Server::IbRubyClassSourceGenerator

Inherits:
Object
  • Object
show all
Includes:
Util::StringUtils
Defined in:
lib/ib_ruby_proxy/server/ib_ruby_class_source_generator.rb

Overview

Given a value object class from Interactive Broker API, this generator can build Ruby source code for:

  • A ruby class to manipulate the same class in Ruby

  • An extension to the original Java class for converting instances into Ruby

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util::StringUtils

#to_camel_case, #to_underscore

Constructor Details

#initialize(ib_class, namespace: 'IbRubyProxy::Client::Ib') ⇒ IbRubyClassSourceGenerator



18
19
20
21
# File 'lib/ib_ruby_proxy/server/ib_ruby_class_source_generator.rb', line 18

def initialize(ib_class, namespace: 'IbRubyProxy::Client::Ib')
  @ib_class = Reflection::IbClass.new(ib_class)
  @namespace_list = namespace.split('::')
end

Instance Attribute Details

#ib_classObject (readonly)

Returns the value of attribute ib_class.



11
12
13
# File 'lib/ib_ruby_proxy/server/ib_ruby_class_source_generator.rb', line 11

def ib_class
  @ib_class
end

#namespace_listObject (readonly)

Returns the value of attribute namespace_list.



11
12
13
# File 'lib/ib_ruby_proxy/server/ib_ruby_class_source_generator.rb', line 11

def namespace_list
  @namespace_list
end

Instance Method Details

#ib_class_extension_sourceString

Source for a ruby class that extends the original IB Java class with a to_ruby method, to convert Java Ib objects into their Ruby counterparts generated in #ruby_class_source



43
44
45
46
47
48
49
# File 'lib/ib_ruby_proxy/server/ib_ruby_class_source_generator.rb', line 43

def ib_class_extension_source
  "  \#{header}\n\n  \#{generate_ib_class_extension}\n  RUBY\nend\n"

#ruby_class_sourceString

Source for a ruby class translates into Ruby the Java properties of the target ib class.

It generates a Struct with the list of properties, that admits a keyword-based constructor, and that includes a to_ib method for converting the ruby back into its original Java counterpart.



31
32
33
34
35
36
37
# File 'lib/ib_ruby_proxy/server/ib_ruby_class_source_generator.rb', line 31

def ruby_class_source
  "  \#{header}\n\n  \#{generate_ruby_class}\n  RUBY\nend\n"