Class: Ikra::Translator::EntireInputTranslationResult

Inherits:
Object
  • Object
show all
Defined in:
lib/translator/input_translator.rb

Overview

Instance of this class store the result of translation of multiple input commands. Instance methods can be used to access the values of the translated commands. Most methods support access by index and access by range, in which case values are aggregated, if meaningful.

Instance Method Summary collapse

Constructor Details

#initialize(input_translation_results) ⇒ EntireInputTranslationResult

Returns a new instance of EntireInputTranslationResult.



148
149
150
# File 'lib/translator/input_translator.rb', line 148

def initialize(input_translation_results)
    @input = input_translation_results
end

Instance Method Details

#block_parameters(index = 0..-1)) ⇒ Object



152
153
154
155
156
157
158
159
160
161
162
# File 'lib/translator/input_translator.rb', line 152

def block_parameters(index = 0..-1)
    if index.is_a?(Fixnum)
        return @input[index].parameters
    elsif index.is_a?(Range)
        return @input[index].reduce([]) do |acc, n|
            acc + n.parameters
        end
    else
        raise ArgumentError.new("Expected Fixnum or Range")
    end
end

#command_translation_result(index) ⇒ Object



221
222
223
# File 'lib/translator/input_translator.rb', line 221

def command_translation_result(index)
    return @input[index].command_translation_result
end

#execution(index = 0..-1)) ⇒ Object



197
198
199
200
201
202
203
204
205
206
207
# File 'lib/translator/input_translator.rb', line 197

def execution(index = 0..-1)
    if index.is_a?(Fixnum)
         return @input[index].command_translation_result.execution
    elsif index.is_a?(Range)
        return @input[index].reduce("") do |acc, n|
            acc + n.command_translation_result.execution
        end
    else
        raise ArgumentError.new("Expected Fixnum or Range")
    end
end

#override_block_parameters(index = 0..-1)) ⇒ Object



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/translator/input_translator.rb', line 176

def override_block_parameters(index = 0..-1)
    if index.is_a?(Fixnum)
        if @input[index].override_block_parameters == nil
            # No override specified
            return @input[index].parameters
        else
            return @input[index].override_block_parameters
        end
    elsif index.is_a?(Range)
        return @input[index].reduce([]) do |acc, n|
            if n.override_block_parameters == nil
                acc + n.parameters
            else
                acc + n.override_block_parameters
            end
        end
    else
        raise ArgumentError.new("Expected Fixnum or Range")
    end
end

#pre_execution(index = 0..-1)) ⇒ Object



164
165
166
167
168
169
170
171
172
173
174
# File 'lib/translator/input_translator.rb', line 164

def pre_execution(index = 0..-1)
    if index.is_a?(Fixnum)
        return @input[index].pre_execution
    elsif index.is_a?(Range)
        return @input[index].reduce("") do |acc, n|
            acc + "\n" + n.pre_execution
        end
    else
        raise ArgumentError.new("Expected Fixnum or Range")
    end
end

#result(index = 0..-1)) ⇒ Object



209
210
211
212
213
214
215
216
217
218
219
# File 'lib/translator/input_translator.rb', line 209

def result(index = 0..-1)
    if index.is_a?(Fixnum)
         return @input[index].command_translation_result.result
    elsif index.is_a?(Range)
        return @input[index].map do |n|
            n.command_translation_result.result
        end
    else
        raise ArgumentError.new("Expected Fixnum or Range")
    end
end