Module: AsciiToSvg
- Defined in:
- lib/ascii_to_svg.rb,
lib/ascii_to_svg/version.rb
Defined Under Namespace
Classes: Error
Constant Summary collapse
- VERSION =
"0.1.4"
Class Method Summary collapse
- .example_string(characters = [ '-', '/', '|', "\\", '+' ], t = 512) ⇒ Object
- .from_string(ascii, _length, vars = {}) ⇒ Object
- .get_hexdigest(str) ⇒ Object
- .get_options ⇒ Object
- .similar_svg(a, b) ⇒ Object
Class Method Details
.example_string(characters = [ '-', '/', '|', "\\", '+' ], t = 512) ⇒ Object
97 98 99 100 101 |
# File 'lib/ascii_to_svg.rb', line 97 def self.example_string( characters=[ '-', '/', '|', "\\", '+' ], t=512 ) return t.times .map { | s | characters[ rand( characters.length ) ] } .join() end |
.from_string(ascii, _length, vars = {}) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/ascii_to_svg.rb', line 104 def self.from_string( ascii, _length, vars = {} ) if self.( vars, true ) , lines = self.( ascii, _length, vars ) elements = '' for y in 0..[:grid][:y][:length] - 1 line = lines[ y ] chars = line.split( '' ) for x in 0..[:grid][:x][:length] - 1 char = line[ x ] symbols = self.cell_symbols( char, ) position = self.cell_position( x, y, ) elements += self.cell_svg( symbols, position, ) end end result = self.generate( elements, ) else end end |
.get_hexdigest(str) ⇒ Object
148 149 150 |
# File 'lib/ascii_to_svg.rb', line 148 def self.get_hexdigest( str ) Digest::MD5.hexdigest str end |
.get_options ⇒ Object
92 93 94 |
# File 'lib/ascii_to_svg.rb', line 92 def self.() return @TEMPLATE end |
.similar_svg(a, b) ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/ascii_to_svg.rb', line 124 def self.similar_svg( a, b ) compare = {} [ [ :a, a ], [ :b, b ] ].each do | str | str[ 1 ].gsub!( "\n", '' ) str[ 1 ].gsub!( ' ', '' ) compare[ str[ 0 ] ] = str[ 1 ] end result = { hexdigest1: nil, hexdigest2: nil, unique: nil, score: nil } result[:hexdigest1] = self.get_hexdigest( compare[:a] ) result[:hexdigest2] = self.get_hexdigest( compare[:b] ) result[:unique] = result[:hexdigest1] == result[:hexdigest2] result[:score] = self.str_difference( compare[:a], compare[:b] ) return result end |