class AsciiParadise::Box
Constants
- DEFAULT_INPUT
#¶ ↑
DEFAULT_INPUT
¶ ↑#¶ ↑
- DEFAULT_TITLE
#¶ ↑
DEFAULT_TITLE
¶ ↑The default title to use will be denoted here. This title will appear on top of the ASCII-box.
#¶ ↑
- MAXIMUM_ALLOWED_LENGTH
#¶ ↑
MAXIMUM_ALLOWED_LENGTH
¶ ↑#¶ ↑
- TOKEN
#¶ ↑
TOKEN
¶ ↑#¶ ↑
Public Class Methods
[](i)
click to toggle source
new( i = nil, run_already = true ) { || ... }
click to toggle source
#¶ ↑
initialize¶ ↑
#¶ ↑
# File lib/ascii_paradise/static_ascii/box.rb, line 51 def initialize( i = nil, run_already = true ) reset set_input(i) if block_given? yielded = yield if yielded == :no_title no_title elsif yielded.is_a? Hash # Handle hash input. if yielded.has_key? :title set_title(yielded.delete(:title)) end end end run if run_already end
Public Instance Methods
add(i)
click to toggle source
add_body()
click to toggle source
center_this_string(i, use_this_token = ' ')
click to toggle source
#¶ ↑
center_this_string
¶ ↑
#¶ ↑
# File lib/ascii_paradise/static_ascii/box.rb, line 174 def center_this_string(i, use_this_token = ' ') i.center(width?, use_this_token) end
Also aliased as: center
colourize_title(use_this_colour = :slateblue)
click to toggle source
determine_longest_entry()
click to toggle source
#¶ ↑
determine_longest_entry
¶ ↑
This method will determine the longest entry.
#¶ ↑
# File lib/ascii_paradise/static_ascii/box.rb, line 222 def determine_longest_entry if input? @max = 0 input?.each_pair {|key, value| if key.size > @max @max = key.size elsif value.size > @max @max = value.size end } if @max > MAXIMUM_ALLOWED_LENGTH @max = MAXIMUM_ALLOWED_LENGTH end end end
draw_header(optional_title = title?)
click to toggle source
#¶ ↑
draw_header
(header tag)¶ ↑
This method willd raw the title.
If Konsole is available then we will also colourize the input.
#¶ ↑
# File lib/ascii_paradise/static_ascii/box.rb, line 209 def draw_header(optional_title = title?) optional_title = ''.dup if optional_title.nil? optional_title = " #{optional_title} " # Pad it here. optional_title = ''.dup unless @show_title # Reset here when we won't show the title. optional_title = optional_title.center(20, token?) add pad( center(optional_title, token?) ) end
input?()
click to toggle source
no_title()
click to toggle source
pad(i)
click to toggle source
reset()
click to toggle source
#¶ ↑
reset¶ ↑
#¶ ↑
Calls superclass method
AsciiParadise::Base#reset
# File lib/ascii_paradise/static_ascii/box.rb, line 73 def reset # (reset tag) super() reset_result @line_width = 80 # How long each line should be at maximum. @show_title = true # if true then we show the title in the header. set_title end
reset_result()
click to toggle source
result?()
click to toggle source
#¶ ↑
result?¶ ↑
#¶ ↑
# File lib/ascii_paradise/static_ascii/box.rb, line 100 def result? @result end
Also aliased as: result
run()
click to toggle source
sanitize_hash(hash)
click to toggle source
set_input(i = DEFAULT_INPUT)
click to toggle source
#¶ ↑
set_input
¶ ↑
The input should be a Hash. It may however had also be an Array, in which case we will convert it.
#¶ ↑
# File lib/ascii_paradise/static_ascii/box.rb, line 117 def set_input(i = DEFAULT_INPUT) i = DEFAULT_INPUT if i.nil? if i.is_a? Array # Check for commandline-arguments here. joined = i.join(' ') if joined.include? '--title' joined =~ /--title (\w+)/ set_title($1.to_s.dup) i = nil # reset here end end if i.is_a? String i = { i => '' } elsif i.is_a? Array # Convert Arrays into a Hash. i = Hash[*i] end i = sanitize_hash(i) if i @input = i determine_longest_entry end
set_title(i = DEFAULT_TITLE)
click to toggle source
show_result()
click to toggle source
#¶ ↑
show_result
¶ ↑
#¶ ↑
# File lib/ascii_paradise/static_ascii/box.rb, line 248 def show_result e result? end
Also aliased as: report
title?()
click to toggle source
token?()
click to toggle source