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

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.options_update( vars, true )
    options, lines = self.options_prepare( ascii, _length, vars )
    elements = ''
    for y in 0..options[:grid][:y][:length] - 1
      line = lines[ y ]
      chars = line.split( '' )
      for x in 0..options[:grid][:x][:length] - 1
        char = line[ x ]
        symbols = self.cell_symbols( char, options )
        position = self.cell_position( x, y, options )
        elements += self.cell_svg( symbols, position, options )      
      end
    end
    result = self.generate( elements, options )
  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_optionsObject



92
93
94
# File 'lib/ascii_to_svg.rb', line 92

def self.get_options()
  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