Class: Colours::Colour

Inherits:
Object
  • Object
show all
Defined in:
lib/colours/toplevel_methods/use_colours.rb

Overview

#

This file includes a standalone Colour class, as part of the Colours namespace.

#

Instance Method Summary collapse

Constructor Details

#initialize(optional_input = nil) ⇒ Colour

#

initialize

#

138
139
140
141
142
143
# File 'lib/colours/toplevel_methods/use_colours.rb', line 138

def initialize(
    optional_input = nil
  )
  reset
  set_input(optional_input) if optional_input
end

Instance Method Details

#b?Boolean

#

b?

#

Returns:

  • (Boolean)

221
222
223
# File 'lib/colours/toplevel_methods/use_colours.rb', line 221

def b?
  @b
end

#build_this_rgb_string(r, g, b) ⇒ Object

#

build_this_rgb_string

#

259
260
261
# File 'lib/colours/toplevel_methods/use_colours.rb', line 259

def build_this_rgb_string(r, g, b)
  Colours.build_this_rgb_string(r,g,b)
end

#g?Boolean

#

g?

#

Returns:

  • (Boolean)

214
215
216
# File 'lib/colours/toplevel_methods/use_colours.rb', line 214

def g?
  @g
end

#output_this_string(i = DEFAULT_TEXT+N, r = r?, , g = g?, , b = b? ) ⇒ Object Also known as: output_this, output, write_this_in_random_colour

#

output_this_string

#

228
229
230
231
232
233
234
235
236
# File 'lib/colours/toplevel_methods/use_colours.rb', line 228

def output_this_string(
    i = DEFAULT_TEXT+N,
    r = r?,
    g = g?,
    b = b?
  )
  result = return_this_string(i,r,g,b)
  e result
end

#r?Boolean

#

r?

#

Returns:

  • (Boolean)

207
208
209
# File 'lib/colours/toplevel_methods/use_colours.rb', line 207

def r?
  @r
end

#random_colour(this_string_to_display = 'test') ⇒ Object Also known as: return_random_colour

#

random_colour

Return a random colour here.

#

268
269
270
271
272
# File 'lib/colours/toplevel_methods/use_colours.rb', line 268

def random_colour(this_string_to_display = 'test')
  return_this_string(
    this_string_to_display, random_value, random_value, random_value
  )
end

#random_colour?(optional_text = nil) ⇒ Boolean

#

random_colour?

#

Returns:

  • (Boolean)

169
170
171
172
173
174
175
176
177
# File 'lib/colours/toplevel_methods/use_colours.rb', line 169

def random_colour?(
    optional_text = nil
  )
  if optional_text
    write_this_in_random_colour(optional_text)
  else
    ::Colours.random_colour?
  end
end

#random_valueObject

#

random_value

#

286
287
288
# File 'lib/colours/toplevel_methods/use_colours.rb', line 286

def random_value
  rand(255)
end

#resetObject

#

reset

#

198
199
200
201
202
# File 'lib/colours/toplevel_methods/use_colours.rb', line 198

def reset
  set_r
  set_g
  set_b
end

#return_this_string(i = DEFAULT_TEXT+N, r = r?, , g = g?, , b = b? ) ⇒ Object

#

return_this_string

#

243
244
245
246
247
248
249
250
251
252
253
254
# File 'lib/colours/toplevel_methods/use_colours.rb', line 243

def return_this_string(
    i = DEFAULT_TEXT+N,
    r = r?,
    g = g?,
    b = b?
  )
  i = DEFAULT_TEXT if i == :default
  i = i.join(' ') if i.is_a? Array
  i = i.to_s.dup
  i = build_this_rgb_string(r, g, b)+i
  return i
end

#seed_rgb_valuesObject

#

seed_rgb_values

Use this method to randomly obtain R,G,B values.

#

279
280
281
# File 'lib/colours/toplevel_methods/use_colours.rb', line 279

def seed_rgb_values
  set_rgb(random_value, random_value, random_value)
end

#set_b(i = nil) ⇒ Object

#

set_b

#

162
163
164
# File 'lib/colours/toplevel_methods/use_colours.rb', line 162

def set_b(i = nil)
  @b = i
end

#set_g(i = nil) ⇒ Object

#

set_g

#

155
156
157
# File 'lib/colours/toplevel_methods/use_colours.rb', line 155

def set_g(i = nil)
  @g = i
end

#set_input(i = nil) ⇒ Object

#

set_input

#

191
192
193
# File 'lib/colours/toplevel_methods/use_colours.rb', line 191

def set_input(i = nil)
  @input = i
end

#set_r(i = nil) ⇒ Object

#

set_r

#

148
149
150
# File 'lib/colours/toplevel_methods/use_colours.rb', line 148

def set_r(i = nil)
  @r = i
end

#set_rgb(r, g, b) ⇒ Object

#

set_rgb

#

182
183
184
185
186
# File 'lib/colours/toplevel_methods/use_colours.rb', line 182

def set_rgb(r,g,b)
  set_r(r)
  set_g(g)
  set_b(b)
end