| Class | RS::Converter::RSConverter |
| In: |
rsil/converter/rsconverter.rb
|
| Parent: | Object |
| Class: | RSConverter |
| File: | rsconverter.rb |
| Purpose: | RSConverter represents a manager and delegator for concrete RAbstractConverters. The manager holds uniq values. |
| Created by: | Mario Pehle, 2006/04/28 |
| Required modules: | - |
| Offers functions: | converting objects, managing of converters |
| converters | [R] | is an Array saving each added concrete converter, does not hold removed converters. |
| Description: | Creates a RSConverter. |
| Precondition: | - |
| Postcondition: | @converters is set. |
| Exceptions: | - |
| Uses: | @converters, RSILRMagickConverter, RSILTkConverter |
| Returns: | self |
| Parameters: | Name | i/o/io | default | Meaning |
# File rsil/converter/rsconverter.rb, line 48
48: def initialize
49: @converters = []
50: @converters << RS::Converter::RSILRMagickConverter.new
51: @converters << RS::Converter::RSILTkConverter.new
52: self
53: end
| Description: | Adds a converter. |
| Precondition: | - |
| Postcondition: | @converters is changed |
| Exceptions: | - |
| Uses: | Array#<<, Array#uniq |
| Returns: | value if valid, else nil |
| Parameters: | Name | i/o/io | default | Meaning |
| : | converter | i | - | RSAbstractConverter, the converter to add |
# File rsil/converter/rsconverter.rb, line 68
68: def add converter
69: if converter.kind_of? RS::Converter::RSAbstractConverter
70: @converters << converter
71: @converters.uniq!
72: return converter
73: end
74: nil
75: end
| Description: | Converts an object to an object of specified class. Delegates the job to one of the subscribed converters. |
| Precondition: | - |
| Postcondition: | - |
| Exceptions: | - |
| Uses: | @converters, RS..Converter#converts?, RS..Converer.convert |
| Returns: | Object if converted and nil if no converter can convert |
| Parameters: | Name | i/o/io | default | Meaning |
| : | object | i | - | The object to convert from |
| : | klass | o | - | The class the converted object should be from |
# File rsil/converter/rsconverter.rb, line 91
91: def convert object, klass
92: @converters.each { |converter|
93: return converter.convert(object, klass) if converter.converts?(object, klass)
94: }
95: nil
96: end
| Description: | Checks, whether it is possible to convert a given object to an object of the given class. Delegates the job to one of the subscribed converters. |
| Precondition: | - |
| Postcondition: | - |
| Exceptions: | - |
| Uses: | @converters |
| Returns: | true if object can be converted, else false |
| Parameters: | Name | i/o/io | default | Meaning |
| : | object | i | - | Object, the object to convert |
| : | klass | o | - | Class, the class to convert object |
# File rsil/converter/rsconverter.rb, line 112
112: def converts? object, klass
113: converts = false
114: @converters.each do |converter|
115: converts = converter.converts?(object, klass) unless converts
116: end
117: converts
118: end
| Description: | Yields each converter. |
| Precondition: | - |
| Postcondition: | Depending on the call, @converters is changed. |
| Exceptions: | - |
| Uses: | - |
| Returns: | self |
| Parameters: | Name | i/o/io | default | Meaning |
# File rsil/converter/rsconverter.rb, line 151
151: def each
152: @converters.each { |converter| yield converter }
153: end
| Description: | Removes converter. |
| Precondition: | - |
| Postcondition: | @converters is changed. |
| Exceptions: | - |
| Uses: | Array#delete |
| Returns: | self |
| Parameters: | Name | i/o/io | default | Meaning |
| : | converter | i | - | RSAbstractConverter, the converter to remove |
# File rsil/converter/rsconverter.rb, line 134
134: def remove converter
135: @converters.delete(converter)
136: self
137: end