Sha256: 57cd6787071ba0682306b7de06e4d57e244ec956598c427bf28a1708267ed318

Contents?: true

Size: 813 Bytes

Versions: 2

Compression:

Stored size: 813 Bytes

Contents

def compact_paranthesis(input_string)

  string_extract = input_string.reverse

  paranthesis_extract = [""]

  two_paranthesis = ""

  open_paran_index = nil

  offset_value = nil

  while string_extract.include?("(")

    open_paran_index = string_extract.index("(")

    test_extract = string_extract[0..open_paran_index].reverse

    two_paranthesis = test_extract[0..test_extract.index(")")]

    previous_value = paranthesis_extract[-1]

    if previous_value.length > two_paranthesis.length-(two_paranthesis.count("$@"))/2

      offset_value = previous_value

    end

    paranthesis_extract << two_paranthesis.sub("$@"*previous_value.length,previous_value)

    string_extract = string_extract.sub(two_paranthesis.reverse,"@$"*paranthesis_extract[-1].length)

  end

  return string_extract.reverse

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
nilac-0.0.4.3.9.7.1 lib/nilac/paranthesis_compactor.rb
nilac-0.0.4.3.9.7 lib/nilac/paranthesis_compactor.rb