ruby_figlet 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b029b1a636cebee4b50ec4cc7aae07817f6aa474
4
- data.tar.gz: 63126bc7878d1f3fb5c0c7b30f84debea0e0ac7b
3
+ metadata.gz: 581f31f99acc9ef55d8eea09a074b8254a578449
4
+ data.tar.gz: 6a9c6cd4545a14bd92c21ae571d436ff4b1b8394
5
5
  SHA512:
6
- metadata.gz: f79bd8e2b7b7238c33a5b7190c1cbcfa59ee66f1a0941e9029bf8eac20964c2de7962947d810019cb64637936f15c8ca226909fc6cfbc76f53fe234529fbb73a
7
- data.tar.gz: 75a5903063923d317a9bbe1922893045b45a4d6975fa6f9f02ad427748aed1ef06b1bb0a347d0cee2cbc2f3bef13fe8751d4d419a3fcdc2bb44351d51f1c0292
6
+ metadata.gz: 6905fef1aa55856518d5b12a91c36549d06b951b3b6a0e5c7bb5fb38a91c2aabbfc15dc1d683060dd06213ffaa4c00b646f7f04ccb238b2569ae59adfe837e5f
7
+ data.tar.gz: 18f9498fd39aa41140d7e253e0a2d19ec389073fb0a1d195ce7e2b0f32f18571b0fd115a2ef846db252389bb28c75869f4f405a9c7c1528939e2248f6c0812b7
data/README.md CHANGED
@@ -27,8 +27,9 @@ puts moo # Default font is 'standard' when no arguments given
27
27
 
28
28
  # or just
29
29
 
30
- puts "meow...".art
31
- puts RubyFiglet::Figlet.new "meow..." # both work the same
30
+ print "meow...".art
31
+ print RubyFiglet::Figlet.new("meow...").stringify
32
+ RubyFiglet::Figlet.new("meow...").show # all work the same
32
33
 
33
34
  # str.art(font)/str.art!(font) and RubyFiglet::Figlet.new(str, font) have a font parameter!
34
35
 
@@ -44,7 +45,7 @@ puts "Heizölrückstoßabdämpfung".art # =>
44
45
  # |_| |_| \___||_|/___| \___/ |_||_| \__,_| \___||_|\_\|___/ \__| \___/ | ||_/ \__,_||_.__/ \__,_| \__,_||_| |_| |_|| .__/ |_| \__,_||_| |_| \__, |
45
46
  # |_| |_| |___/
46
47
 
47
- puts RubyFiglet::Figlet.new("It's an abstract sort of font", 'weird')
48
+ puts RubyFiglet::Figlet.new("It's an abstract sort of font", 'weird').stringify
48
49
 
49
50
  bowl = "Soup?"
50
51
  bowl.art! 'alphabet'
data/bin/ruby-figlet CHANGED
@@ -22,4 +22,5 @@ if ARGV.include? '-f'
22
22
  ARGV.delete('-f')
23
23
  ARGV.delete(font)
24
24
  end
25
- puts ARGV[0].art font
25
+ first_arg = ARGV[0].gsub("\\n", "\n")
26
+ puts first_arg.art font
@@ -51,14 +51,10 @@ module FigFont
51
51
  @tag_count = meta[8].to_i
52
52
  end
53
53
  # we've got the information, now delete it form the `lines`
54
- (0..@commented).each { lines.delete_at 0 } # This bugger,
55
- # since I delete the first line
56
- # the next line has now become
57
- # the first line, embarrassing how long that took.
54
+ (0..@commented).each { lines.delete_at 0 } # since I delete the first line, the next line has now become the first line,
55
+
58
56
  endmark = lines[0][lines[0].length - 1]
59
- (0..lines.size - 1).each do |i|
60
- lines[i].gsub!(endmark, "")
61
- end
57
+ (0..lines.size - 1).each { |i| lines[i].gsub!(endmark, "") } #remove endmarks
62
58
 
63
59
  char_hash = Hash.new
64
60
  (32..126).each do |code|
@@ -73,19 +69,23 @@ module FigFont
73
69
  'ö' => Array.new(@height, String.new),
74
70
  'ü' => Array.new(@height, String.new),
75
71
  'ß' => Array.new(@height, String.new)
76
- }) if lines.length > 95 * @height
72
+ }) if lines.length > 95 * @height # 95 is the range of the num. of the default chars
77
73
 
78
74
  char_hash.each do |key, value|
79
- (0..@height - 1).each do |line|
80
- char_hash[key][line] = lines[line]
81
- end
75
+ @height.times { |line| char_hash[key][line] = lines[line] }
82
76
  lines.slice! 0..@height - 1
83
77
  end
84
78
 
85
79
  smush! char_hash unless @old_lay == -1
86
80
  char_hash.each do |key, arr|
87
- (0..@height - 1).each { |i| char_hash[key][i] = arr[i].gsub(@hardblank, " ") }
81
+ @height.times { |i| char_hash[key][i] = arr[i].gsub(@hardblank, " ") }
88
82
  end
83
+
84
+ # Add fake newline character
85
+ newline = Array.new(@height, String.new)
86
+ newline[-1] = 10.chr
87
+ char_hash[10.chr] = newline
88
+
89
89
  return char_hash
90
90
  end
91
91
 
@@ -97,9 +97,7 @@ module FigFont
97
97
  same_at_index[down] = true if (letter_arr[down][over] == letter_arr[down + 1][over]) && (letter_arr[down][over] == ' ' && letter_arr[down + 1][over] == ' ')
98
98
  end
99
99
  if same_at_index.all?
100
- (0..@height - 1).each do |down|
101
- hash[letter][down].delete_at! over
102
- end
100
+ @height.times { |down| hash[letter][down].delete_at! over }
103
101
  end
104
102
  end # Pre-word smushing for each letter, when there is a consective vertical line of spaces, then smush them away
105
103
  end
data/lib/ruby_figlet.rb CHANGED
@@ -29,23 +29,33 @@ module RubyFiglet
29
29
  end
30
30
 
31
31
  def stringify
32
- string = String.new
33
- (0..@height - 1).each do |row|
34
- @string.each do |char|
35
- string << @lookup[char][row]
32
+ breaks = @string.split "\n"
33
+ breaks.each_with_index do |break_line, i|
34
+ string = String.new
35
+ @height.times do |row|
36
+ break_line.each { |char| string << @lookup[char][row] }
37
+ string << "\n"
36
38
  end
37
- string << "\n"
38
- end
39
- if @direction == 1
40
- lines = string.split "\n"
41
- (0..(%x[tput cols].to_i - 1) - lines[0].length).each do # Holy Moly, from 0 to (terminal width minus 1) minus length of the ascii art word.
42
- lines.each_with_index do |line, i|
43
- lines[i].insert 0, " "
39
+ if @direction == 1
40
+ lines = string.split "\n"
41
+ (0..(%x[tput cols].to_i - 1) - lines[0].length).each do # Holy Moly, from 0 to (terminal width minus 1) minus length of the ascii art word.
42
+ lines.each_with_index { |line, j| lines[j].insert 0, " " }
44
43
  end
44
+ string = lines.join "\n"
45
+ end
46
+ breaks[i] = string
47
+ end
48
+ string = breaks.join ""
49
+
50
+ lines = string.split "\n"
51
+ offset = 0
52
+ (lines.size).times do |j|
53
+ if lines[j - offset].strip.empty? # when a line is deleted, there must be an offset as the new array is now shorter (after a delete) so we must climb back up it, so that whe don't dlete wrong lines and try to access non-existent indices
54
+ lines.delete_at(j - offset) # Remove any empty lines
55
+ offset += 1
45
56
  end
46
- string = lines.join "\n"
47
57
  end
48
- return string
58
+ return lines.join "\n"
49
59
  end
50
60
 
51
61
  def show
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_figlet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Demonstrandum