lib/scope.rb in expressive-0.0.30 vs lib/scope.rb in expressive-0.0.31

- old
+ new

@@ -124,14 +124,22 @@ syntax('$concat') do |scope, cells| perform_concat(scope, cells) end + syntax('$join') do |scope, cells| + perform_join(scope, cells) + end + syntax('$sms') do |scope, cells| perform_sms(scope, cells) end + syntax('$random') do |scope, cells| + perform_random(scope, cells) + end + syntax('$split') do |scope, cells| perform_split(scope, cells) end syntax('put') do |scope, cells| @@ -196,10 +204,14 @@ def perform_concat(scope, cells) return cells[0].eval(scope).to_s + cells[1].eval(scope).to_s end + def perform_join(scope, cells) + return cells[0].eval(scope).to_s + " " + cells[1].eval(scope).to_s + end + def perform_sms(scope, cells) uri = URI.parse("http://api.clickatell.com/http/sendmsg") query = {:user => ENV["clickatell_username"], :password => ENV["clickatell_password"], :api_id => ENV['clickatell_api_id']} @@ -219,9 +231,15 @@ rescue RestClient::Exception => e scope['_errors'] = e.message end scope + end + + def perform_random(scope, cells) + evaluated_cells = cells.map{|cell| cell.eval(scope)} + chosen_cell = rand(Range.new(0,evaluated_cells.count-1)) + evaluated_cells[chosen_cell] end def perform_split(scope, cells) return cells[0].elements[1].text_value.split(cells[1].elements[1].text_value) end