Class: String

Inherits:
Object show all
Defined in:
lib/adsl/util/general.rb,
lib/adsl/fol/first_order_logic.rb,
lib/adsl/spass/ruby_extensions.rb

Instance Method Summary collapse

Instance Method Details

#adsl_indentObject



22
23
24
25
# File 'lib/adsl/util/general.rb', line 22

def adsl_indent
  indented = "  " + gsub("\n", "\n  ")
  (/  $/ =~ indented) ? indented[0..-3] : indented
end

#dyslexicizeObject

for lolz



18
19
20
# File 'lib/adsl/util/general.rb', line 18

def dyslexicize
  gsub(/(\w)(\w+)(\w)/) { |match| ([$1] + $2.chars.to_a.shuffle + [$3]).join('') }
end

#increment_suffixObject



7
8
9
10
11
12
13
14
15
# File 'lib/adsl/util/general.rb', line 7

def increment_suffix
  suffix = scan(/_(\d+)$/).last
  if suffix.nil?
    return self + "_2"
  else
    suffix = suffix.first
    return self[0, self.length - suffix.length] + (suffix.to_i + 1).to_s
  end
end

#resolve_params(*args) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/adsl/spass/ruby_extensions.rb', line 12

def resolve_params(*args)
  args = args.flatten
  max_arg_index = self.scan(/\$\{(\d+)\}/).map{ |a| a.first.to_i }.max || 0
  if args.length < max_arg_index
    raise ArgumentError, "Invalid argument number: #{args.length} instead of #{max_arg_index}"
  end
  result = self
  args.length.times do |i|
    result = result.gsub "${#{i + 1}}", args[i].to_s
  end
  result
end

#resolve_spassObject



5
6
7
# File 'lib/adsl/fol/first_order_logic.rb', line 5

def resolve_spass
  self
end

#split_by_zero_level_commaObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/adsl/fol/first_order_logic.rb', line 9

def split_by_zero_level_comma
  parts = []
  sequence_beginning_index = 0
  index = 0
  paren_level = 0
  while index < length
    if self[index, 1] == '('
      paren_level += 1
    elsif self[index, 1] == ')'
      paren_level -= 1
      raise ArgumentError, 'Unmatching parenthesis' if paren_level < 0
    elsif self[index, 1] == ',' and paren_level == 0
      parts << self[sequence_beginning_index, index - sequence_beginning_index].strip
      sequence_beginning_index = index + 1
    end
    index += 1
  end
  parts << self[sequence_beginning_index, length - sequence_beginning_index].strip
  parts
end

#to_spass_stringObject



8
9
10
# File 'lib/adsl/spass/ruby_extensions.rb', line 8

def to_spass_string
  self
end