Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/games_and_rpg_paradise/lpc/modifications/modifications.rb

Overview

#

String

Extend the String class. We will sanitize some stuff.

#

Instance Method Summary collapse

Instance Method Details

#add_quotes(shall_we_check_for_only_upcase = false) ⇒ Object Also known as: aq, quotes

#

add_quotes

This will simply add quotes to a string, unless it is UPCASED.

#


43
44
45
46
47
48
49
50
51
52
53
# File 'lib/games_and_rpg_paradise/lpc/modifications/modifications.rb', line 43

def add_quotes(
    shall_we_check_for_only_upcase = false
  )
  _ = self.dup
  if shall_we_check_for_only_upcase
    _ = '"'+_+'"' unless _.only_upcase?
  else # else just do the quotes
    _ = '"'+_+'"'
  end
  return _
end

#convert_exit!Object Also known as: cexit!

#

convert_exit!

#


27
28
29
30
31
32
33
34
35
36
# File 'lib/games_and_rpg_paradise/lpc/modifications/modifications.rb', line 27

def convert_exit!
  all_values = HASH_EXITS_EXPANDED.values
  if HASH_EXITS_EXPANDED.keys.include?(self)
    replace( find_exit(self) )
  elsif all_values.include?(self)
    # silent pass through as "down"
  else
    warn 'In convert_exit()! `'+self+'` was not included.'
  end
end

#find_exit(shortcut) ⇒ Object

#

find_exit

This will return the long version.

#


99
100
101
102
103
104
105
# File 'lib/games_and_rpg_paradise/lpc/modifications/modifications.rb', line 99

def find_exit(shortcut)
  if HASH_EXITS_EXPANDED.keys.include? shortcut
    HASH_EXITS_EXPANDED[shortcut]
  else
    shortcut
  end
end

#inner_quotesObject

#

inner_quotes

As above, but will add quotes among ,.

#


61
62
63
64
65
# File 'lib/games_and_rpg_paradise/lpc/modifications/modifications.rb', line 61

def inner_quotes
  _ = self
  _ = _.gsub(/,/, '","') if self.include? ','
  return _
end

#only_caps?Boolean

#

only_caps?

#

Returns:

  • (Boolean)


20
21
22
# File 'lib/games_and_rpg_paradise/lpc/modifications/modifications.rb', line 20

def only_caps?
  return self.upcase == self
end

#sanitize(optional_indent = 0, threshold = GENERAL_THRESHOLD) ⇒ Object

#

sanitize (sanitize tag)

#


70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/games_and_rpg_paradise/lpc/modifications/modifications.rb', line 70

def sanitize(
    optional_indent = 0, threshold = GENERAL_THRESHOLD
  )
  optional_indent = ' ' * (optional_indent + 5)
  optional_indent = optional_indent.to_s # must be a string.
  _ = self.chomp
  # ================================================================== #
  # Finished padding. Now we add quotes if we have at least 80 chars.
  # ================================================================== #
  if _.size > threshold
    # _.gsub!(/(.{1,#{threshold}})(\s+|$)/, "\\1\n")
    # _.gsub!(/^/,optional_indent+'"')
    # _.gsub!(/$/,' "')
    # _.gsub!(/$/,'+')
    # _.gsub!(/""/,'"')
    # _.gsub!(/  /,' ')
    # _.gsub!(/\. "/,'."')
    # _.chop! if _[-1,1] == '+'
  else
    _ = optional_indent+_.add_quotes
  end
  replace(_)
end