Class: Roebe::Shell::ColourCodes

Inherits:
Object
  • Object
show all
Defined in:
lib/roebe/shell/colours/colour_codes.rb

Overview

Roebe::Shell::ColourCodes

Constant Summary collapse

N =
$/
DEBUG =
#

DEBUG

#
false

Instance Method Summary collapse

Constructor Details

#initialize(input = nil, run_already = true) ⇒ ColourCodes

#

initialize

#


37
38
39
40
41
42
43
44
45
# File 'lib/roebe/shell/colours/colour_codes.rb', line 37

def initialize(
    input       = nil,
    run_already = true
  )
  reset
  set_raw_input(input) if input
  run_already = false if @_.empty?
  run if run_already
end

Instance Method Details

#debugObject

#

debug

#


96
97
98
99
100
# File 'lib/roebe/shell/colours/colour_codes.rb', line 96

def debug
  e 'We are trying to debug now.'
  run
  e @modified
end

#format_value_of_string(i) ⇒ Object

#

format_value_of_string

#


157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/roebe/shell/colours/colour_codes.rb', line 157

def format_value_of_string(i) # This will modify the value of the string.
  i = i.chomp.strip
  #i[0,0] = ' ' unless i.include? '{' # properly align for padding.
  rest = i.index '=>'
  key = i[0..(rest-1)].gsub(/colour_for_/,'').
                       gsub(/_content/,'').
                       gsub(/"/,'').
                       gsub(/\{/,'').chomp
  value = i[rest+3..-2]
  value[-1,1] = '' if value.end_with? '"' # kill trailing '"'.
  modified_value = '"|'+key+'|'+value+'|_|",'
  modified_value.gsub!(/""/,'"')
  i[rest+2..-1] = modified_value+N
  i
end

#original_input?Boolean Also known as: original_input

#

original_input?

#

Returns:

  • (Boolean)


77
78
79
# File 'lib/roebe/shell/colours/colour_codes.rb', line 77

def original_input?
  @original_input
end

#process_inputObject Also known as: run

#

process_input

#


138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/roebe/shell/colours/colour_codes.rb', line 138

def process_input # This is actually run().
  _ = ''.dup
  @_.split(',').each { |string| # process each subsection
    string = string.strip.chomp
    padding = ''.dup
    padding << ' ' unless string.include? '{'
    padding << @padding
    # Now we process each individual entry.
    modified = padding+format_value_of_string(string)
    _ << modified
  }
  _.chomp!
  _.chop! if _.end_with? ','
  @modified = "#{_}}"
end

#resetObject

#

reset

#


50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/roebe/shell/colours/colour_codes.rb', line 50

def reset
  # ======================================================================= #
  # === @_
  # ======================================================================= #
  @_ = ''
  # ======================================================================= #
  # === @padding
  # ======================================================================= #
  @padding = ''
  # ======================================================================= #
  # === @modified
  # ======================================================================= #
  @modified = ''
end

#resultObject

#

result

Reader method over @modified.

#


70
71
72
# File 'lib/roebe/shell/colours/colour_codes.rb', line 70

def result
  @modified
end

#set_padding(i) ⇒ Object

#

set_padding

#


105
106
107
108
109
# File 'lib/roebe/shell/colours/colour_codes.rb', line 105

def set_padding(i)
  i = i.size if i.is_a? String
  i = i.to_i
  @padding = ' ' * i
end

#set_raw_input(i) ⇒ Object Also known as: set_input

#

set_raw_input

#


84
85
86
87
88
89
90
91
# File 'lib/roebe/shell/colours/colour_codes.rb', line 84

def set_raw_input(i) # Set the raw input.
  if DEBUG
    e 'The original input is:'
    e i
  end
  @original_input = i.dup
  @_ = i
end

#test(test_this_input = '{ "colour_for_end"=>"white", "colour_for_fancy_content"=>"darkgreen", "colour_for_warnings"=>"redb", "colour_for_arguments"=>"red", "colour_for_files"=>"lightblue", "colour_for_important_content"=>"teal", "colour_for_symlinks"=>"lightgreen", "colour_for_normal"=>"whiteonblack", "colour_for_directories"=>"brown" }') ⇒ Object

#

test

#


114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/roebe/shell/colours/colour_codes.rb', line 114

def test(
  test_this_input = '{
      "colour_for_end"=>"white",
      "colour_for_fancy_content"=>"darkgreen",
      "colour_for_warnings"=>"redb",
      "colour_for_arguments"=>"red",
      "colour_for_files"=>"lightblue",
      "colour_for_important_content"=>"teal",
      "colour_for_symlinks"=>"lightgreen",
      "colour_for_normal"=>"whiteonblack",
      "colour_for_directories"=>"brown"
    }'
  )
  set_input(test_this_input)
  set_padding 5
  run
  puts result
  puts "\n"+'The original input was:'
  puts original_input
end