Method: Aspose::Cloud::Words::Builder#replace_text

Defined in:
lib/Words/builder.rb

#replace_text(old_value, new_value, is_match_case, is_match_whole_word) ⇒ Object

Replace a text with the new value in the document

@param string old_value
@param string new_value
@param string is_match_case
@param string is_match_whole_word


114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/Words/builder.rb', line 114

def replace_text old_value, new_value, is_match_case, is_match_whole_word
      
  begin

    if @filename == ''
      raise 'Base file not specified.'
    end

    if old_value == ''
      raise 'Old value not specified.'
    end

    if new_value == ''
      raise 'New Value not specified.'
    end

    post_hash = { 'OldValue' => old_value, 'NewValue'=>new_value,'IsMatchCase' => is_match_case,'IsMatchWholeWord' => is_match_whole_word }
    json_data = post_hash.to_json
    str_uri = $product_uri + '/words/' + @filename + '/replaceText'
    signed_str_uri = Aspose::Cloud::Common::Utils.sign(str_uri)                
    response_stream = RestClient.post signed_str_uri, json_data, {:content_type => :json}

    valid_output = Aspose::Cloud::Common::Utils.validate_output(response_stream)

    if valid_output == ''                              
      folder = Aspose::Cloud::AsposeStorage::Folder.new
      output_stream = folder.get_file(@filename)                   
      output_path = $out_put_location + @filename
      Aspose::Cloud::Common::Utils.save_file(output_stream,output_path)
      return ''
    else
      return valid_output
    end        


  rescue Exception=>e
    print e
  end
      
end