Class: Roebe::StringColourParser

Inherits:
Object
  • Object
show all
Defined in:
lib/roebe/classes/string_colour_parser.rb

Overview

Roebe::StringColourParser

Constant Summary collapse

TEST_STRING =
#

TEST_STRING

#
'We found |file|3 files|_|, |dir|25 directories|_| and |symlink|7 symlinks|_| in '\
'this directory. But we must not modify |shot|.'
ENCODING_ISO =
#

ENCODING_ISO

#
'ISO-8859-1'
SHALL_WE_DEBUG =
#

SHALL_WE_DEBUG

#
false

Instance Method Summary collapse

Constructor Details

#initialize(test_this_string = nil, run_already = true) ⇒ StringColourParser

#

initialize

#


45
46
47
48
49
50
51
52
53
54
# File 'lib/roebe/classes/string_colour_parser.rb', line 45

def initialize(
    test_this_string = nil,
    run_already      = true
  )
  reset
  set_string(
    test_this_string
  )
  run if run_already
end

Instance Method Details

#output_stringObject Also known as: report

#

output_string

#


96
97
98
# File 'lib/roebe/classes/string_colour_parser.rb', line 96

def output_string
  e @string
end

#parse_string(i) ⇒ Object

#

parse_string

#


110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/roebe/classes/string_colour_parser.rb', line 110

def parse_string(i)
  _ = ''.dup # This is the return string.
  splitted = i.split('|') # Split at the '|' tokens.
  pp splitted if @debug
  splitted.each { |char|
    if @debug
      e "The character is now: #{char}"
    end
    # ===================================================================== #
    # This is the specific part that will properly colourize the tags.
    # ===================================================================== #
    case char # case tag
    when '_' # <- This means to reinstate the original content.
      _ << ::Colours.rev()
    when 'fancy','fa'
      _ << ::Colours.sfancy()
    when 'important','imp','simp'
      _ << ::Colours.simportant()
    when 'file','fi'
      _ << ::Colours.sfile()
    when 'dir','directory'
      _ << ::Colours.sdir()
    when 'symlink'
      _ << ::Colours.ssymlink()
    else # Else, just append the content without any further modification.
      _ << char
    end
  }
  return _
end

#resetObject

#

reset

#


59
60
61
62
63
64
# File 'lib/roebe/classes/string_colour_parser.rb', line 59

def reset
  # ======================================================================= #
  # === @debug
  # ======================================================================= #
  @debug = SHALL_WE_DEBUG
end

#resultObject

#

result

#


69
70
71
# File 'lib/roebe/classes/string_colour_parser.rb', line 69

def result
  @string
end

#runObject

#

run (run tag)

#


144
145
146
147
148
149
150
# File 'lib/roebe/classes/string_colour_parser.rb', line 144

def run
  split_up_string
  if @debug
    e 'The string is now: '+@string
    pp @string
  end
end

#set_string(i = TEST_STRING) ⇒ Object

#

set_string

#


76
77
78
79
80
81
82
83
84
# File 'lib/roebe/classes/string_colour_parser.rb', line 76

def set_string(i = TEST_STRING)
  i = i.first if i.is_a? Array
  case i
  when :test_string, :default, nil
    i = TEST_STRING
  end
  i = i.to_s.dup
  @string = i
end

#split_up_stringObject

#

split_up_string

#


89
90
91
# File 'lib/roebe/classes/string_colour_parser.rb', line 89

def split_up_string
  @string = parse_string(@string)
end

#string?Boolean Also known as: string

#

string?

#

Returns:

  • (Boolean)


103
104
105
# File 'lib/roebe/classes/string_colour_parser.rb', line 103

def string?
  @string
end