class MODL::Parser::StandardMethods

Public Class Methods

extract_params(str) click to toggle source

Extract the method parameter

# File lib/modl/parser/modl_method.rb, line 158
def self.extract_params(str)
  # should be of the form .r(s1,s2)
  Sutil.between(str, '<', '>')
end
get_subst_parts(s) click to toggle source

Extract the method parameters

# File lib/modl/parser/modl_method.rb, line 149
def self.get_subst_parts(s)
  # should be of the form .r(s1,s2)
  result = extract_params(s).split(',')
  result[0] = '' if result.length.zero? || result[0].nil?
  result[1] = '' if result.length == 1 || result[1].nil?
  result
end
run_method(mthd, str) click to toggle source
# File lib/modl/parser/modl_method.rb, line 119
def self.run_method(mthd, str)
  m = mthd.match(/\w*/)[0]
  case m
  when 'u', 'upcase'
    str.upcase
  when 'd', 'downcase'
    str.downcase
  when 'i', 'initcap'
    str.split.map(&:capitalize) * ' '
  when 's', 'sentence'
    split = str.split
    split[0].capitalize!
    split.join(' ')
  when 'e', 'urlencode'
    CGI.escape(str)
  when 'r', 'replace'
    s1, s2 = get_subst_parts(mthd)
    str.gsub(s1, s2)
  when 't', 'trim'
    s1 = extract_params mthd
    i = str.index(s1)
    Sutil.head(str, i)
  when 'p', 'punydecode'
    Punycode.decode(str)
  else
    str.nil? ? '.' + mthd : str.to_s + '.' + mthd
  end
end
valid_method?(mthd) click to toggle source
# File lib/modl/parser/modl_method.rb, line 163
def self.valid_method?(mthd)
  m = mthd
  if m.include?('<')
    m = Sutil.until(m, '<')
  end
  return @@mthd_names.include?(m)
end