Class: Rubidium::Converter
- Inherits:
-
Object
- Object
- Rubidium::Converter
- Defined in:
- lib/rubidium/lang.rb
Overview
Instance Attribute Summary collapse
-
#in_format ⇒ Object
readonly
Returns the value of attribute in_format.
-
#molecule ⇒ Object
Returns the value of attribute molecule.
-
#out_format ⇒ Object
readonly
Returns the value of attribute out_format.
-
#toolkit ⇒ Object
readonly
Returns the value of attribute toolkit.
Instance Method Summary collapse
-
#convert(input) ⇒ Object
Converts given input based on the formats defined in #set_formats.
-
#initialize(toolkit = 'CDK') ⇒ Converter
constructor
Constructs a CDK converter by default.
-
#read(input) ⇒ Object
Reads the molecule encoded by
input
in the format defined by #in_format. -
#set_formats(in_format, out_format) ⇒ Object
Sets the input and output formats for this Converter.
-
#set_in_format(format) ⇒ Object
Sets the input format to one of the formats defined in #set_formats.
-
#set_out_format(format) ⇒ Object
Sets the output format to one of the formats defined in #set_formats.
-
#write ⇒ Object
Writes the molecule encoded by the previous call to #read in the format defined by #out_format.
Constructor Details
#initialize(toolkit = 'CDK') ⇒ Converter
Constructs a CDK converter by default.
39 40 41 42 43 |
# File 'lib/rubidium/lang.rb', line 39 def initialize(toolkit = 'CDK') @toolkit = toolkit @readers = create_readers @writers = create_writers end |
Instance Attribute Details
#in_format ⇒ Object (readonly)
Returns the value of attribute in_format.
34 35 36 |
# File 'lib/rubidium/lang.rb', line 34 def in_format @in_format end |
#molecule ⇒ Object
Returns the value of attribute molecule.
33 34 35 |
# File 'lib/rubidium/lang.rb', line 33 def molecule @molecule end |
#out_format ⇒ Object (readonly)
Returns the value of attribute out_format.
35 36 37 |
# File 'lib/rubidium/lang.rb', line 35 def out_format @out_format end |
#toolkit ⇒ Object (readonly)
Returns the value of attribute toolkit.
36 37 38 |
# File 'lib/rubidium/lang.rb', line 36 def toolkit @toolkit end |
Instance Method Details
#convert(input) ⇒ Object
Converts given input based on the formats defined in #set_formats.
call-seq:
convert(input) => string
63 64 65 66 |
# File 'lib/rubidium/lang.rb', line 63 def convert input read input write end |
#read(input) ⇒ Object
Reads the molecule encoded by input
in the format defined by #in_format.
call-seq:
input(input) => boolean
90 91 92 93 94 95 96 |
# File 'lib/rubidium/lang.rb', line 90 def read input raise "No input format" unless @in_format @molecule = @readers[@in_format].read input @molecule != nil end |
#set_formats(in_format, out_format) ⇒ Object
Sets the input and output formats for this Converter. CDK converters recognize the input formats: ‘mol’ (MDL V2000 molfile); ‘inchi’, and ‘smi’ (SMILES). Recognized output formats are: ‘mol’, ‘inchi’, and ‘smi’.
50 51 52 53 54 55 |
# File 'lib/rubidium/lang.rb', line 50 def set_formats in_format, out_format set_in_format in_format set_out_format out_format true end |
#set_in_format(format) ⇒ Object
Sets the input format to one of the formats defined in #set_formats.
70 71 72 73 74 |
# File 'lib/rubidium/lang.rb', line 70 def set_in_format format raise "No input format matching #{format}" unless @readers[format] @in_format = format end |
#set_out_format(format) ⇒ Object
Sets the output format to one of the formats defined in #set_formats.
78 79 80 81 82 |
# File 'lib/rubidium/lang.rb', line 78 def set_out_format format raise "No output format matching #{format}" unless @writers[format] @out_format = format end |
#write ⇒ Object
Writes the molecule encoded by the previous call to #read in the format defined by #out_format.
call-seq:
write => string
104 105 106 107 108 |
# File 'lib/rubidium/lang.rb', line 104 def write raise "No output format" unless @out_format @writers[@out_format].write @molecule end |