Skip to content

Commit

Permalink
in string number replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
marcel12bell committed Sep 5, 2013
1 parent b02c331 commit 1eb21b3
Show file tree
Hide file tree
Showing 48 changed files with 67 additions and 2,166 deletions.
120 changes: 61 additions & 59 deletions main/string_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,104 +6,106 @@ class StringObject

def initialize(s)
@content = s
@object_list = [methode, arguments || [] ]
@position = [0..0]
end
end

def append(key)
@content += key.to_s
@object_list = [methode, arguments]
end

def delete #last Char
@content.chop!
@object_list = [methode, arguments]
end

def methode
@content.split.to_a[0]
end

def arguments
array = @content.split.to_a
#splits the string after the methode into arguments array
if (array.count > 2)
update(array)
else
[]
def update_param(x_mouse, y_mouse)
#Try to find beginn of param and set this as the char_position to prevent unintendet param change!!!
char_position = find_char($app.pressed[0])
found_number = find_number(char_position) unless char_position.nil?
if found_number and found_number != [0..0]
new_param_value = -$app.width/2+x_mouse-length($app.initial_param[:string])+$app.initial_param[:value]
begin_of_param = found_number[0].first
current_param_length = @content[found_number[0]].to_s.length
@content[begin_of_param, current_param_length] = new_param_value.to_s
end
end

def update_argument(x_mouse, y_mouse)
update_argument_position
arg = find_argument($app.pressed[0])
if arg
new_arg_value = -$app.width/2+x_mouse+$app.editor_left_margin-length((methode+ " ").to_s)-length(@object_list[1][0..arg].join(" ").to_s)+$app.initial_arg_value
@object_list[1][arg] = new_arg_value
@content = @object_list.first + " " + @object_list[1].join(", ") + "\n" if @object_list.first
end
end

def get_param_value(x,y)
def get_param_values
#get the rigth param of x position and give the value back
arg = find_argument(x)
if arg
value = @object_list[1][arg]
else
value = 0
char_position = find_char($app.pressed[0])
if char_position
found_number = find_number(char_position)[0]
unless found_number == [0..0]
number = @content[found_number].to_i
#return string without begin of number (because it will change):
string = @content[0..found_number.first-1]
return { :value => number, :string => string }
end
end
return value
end

def set_position=(range)
#of the string in the editor
@position = range
end

def get_position
#get the first nuber of an range x..y
#get the first number of an range x..y
@position.to_a.first
end

private

def update(array)
a = array.map do |e|
if /[[:alpha:]]/.match(e)
e
else
e.to_i
end
end
a[1..-1]
end

def length(s)
text_width(s.to_s).to_i unless s.nil?
end

def update_argument_position
start_position = $app.width/2+$app.editor_left_margin+length((methode).to_s)
arg_length_new = 0
space = length(" ")
@argument_position = Hash.new {|this_hash,missing_key| #set always a new hash to keep track of growing numbers
def update_char_position
start_position = $app.width/2
char_length_new = 0
@char_position = Hash.new {|this_hash,missing_key| #set always a new hash to keep track of growing numbers
found_key = this_hash.keys.find {|this_key| this_key.class == Range && this_key.include?(missing_key) }
found_key ? this_hash[missing_key] = this_hash[found_key] : :undefined
} #source: http://www.developwithpurpose.com/ruby-hash-awesomeness-part-2/
arguments.each_with_index do |value, k|
arg_length = length(value)
arg_range = [
start_position+arg_length_new..
start_position+arg_length_new+arg_length
@content.chars.each_with_index do |value, k|
char_length = length(value)
char_range = [
start_position+char_length_new..
start_position+char_length_new+char_length
]
@argument_position[arg_range[0]] = k
arg_length_new = arg_length_new + arg_length + space
end
@char_position[char_range[0]] = k
char_length_new = char_length_new + char_length
end
end

def find_argument(x_position)
#return argument on rigth position
update_argument_position # first initialisation on mouse down
arg = @argument_position[x_position]
arg unless arg == :undefined
def find_char(x_position)
update_char_position
char_position = @char_position[x_position]
char_position unless char_position == :undefined
end

def find_number(start_position)
#returns the range position of the selected number of the String (refr. to recursion--)
left_position, right_position = start_position, start_position
left_search, right_search = true, true
while (left_search) or (right_search) and left_position > 0
if @content[left_position].match(/^-?[0-9]?(\.[0-9]+)?$+/)
left_position -=1
else
left_search = false
end
if !@content[right_position].nil? and @content[right_position].match(/^-?[0-9]?(\.[0-9]+)?$+/)
right_position +=1
else
right_search = false
end
end
if start_position == left_position and right_position
[0..0]
else
[left_position+1..right_position-1]
end
end
end
5 changes: 2 additions & 3 deletions main/watch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ def check_param(x,y)
y_position = @cursor.y_position
string_object = @lines.positiontable(y_position)
if (string_object.position[0]).include?($app.pressed[1])
string_object.update_argument(x,y) unless string_object == :undefined
string_object.update_param(x,y) unless string_object == :undefined
end
end

def get_param(x,y)
y_position = @cursor.y_position
string_object = @lines.positiontable(y_position)
string_object.get_param_value(x,y_position) unless string_object == :undefined
string_object.get_param_values unless string_object == :undefined
end

end
58 changes: 0 additions & 58 deletions simple_live_coding.app/Contents/Info.plist

This file was deleted.

Binary file not shown.
1 change: 0 additions & 1 deletion simple_live_coding.app/Contents/PkgInfo

This file was deleted.

1 change: 0 additions & 1 deletion simple_live_coding.app/Contents/Resources/Java

This file was deleted.

Binary file not shown.
3 changes: 0 additions & 3 deletions simple_live_coding.app/lib/MANIFEST.MF

This file was deleted.

3 changes: 0 additions & 3 deletions simple_live_coding.app/lib/args.txt

This file was deleted.

Binary file removed simple_live_coding.app/lib/core/core.jar
Binary file not shown.
Binary file removed simple_live_coding.app/lib/core/jruby-complete.jar
Binary file not shown.
1 change: 0 additions & 1 deletion simple_live_coding.app/lib/library/library.txt

This file was deleted.

37 changes: 0 additions & 37 deletions simple_live_coding.app/lib/ruby-processing.rb

This file was deleted.

Loading

0 comments on commit 1eb21b3

Please sign in to comment.