ruby_figlet 0.1.0 → 0.2.0

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: 55b9eefe921ecda1f181254911dbacf22b658bae
4
- data.tar.gz: 4599bcfea9c47f9d79ec41ac42bb93c061754500
3
+ metadata.gz: '0887a9805f5a671af2b41d61472b85b981714d79'
4
+ data.tar.gz: d23cdc8114c666e61d49dc991305e45643636f96
5
5
  SHA512:
6
- metadata.gz: e4f80091efd9506b70c4f2a221668141d462ecd0657b685ebe929592f98ba067cc816fb4c2d59365c717407a8eedf348a12a9eb71c4ef3d03cda7409a39d883e
7
- data.tar.gz: 25c72dcd7db1915ee2be14c4c2917152f595857dce45c822aebdfff54f1e535fbb2a5b2c92150c0161b5a014bffc6a352d5da952fba65eba422924954be478e2
6
+ metadata.gz: bffb5334ba880591ad285f8412b99e6d28c960d126f62daeddb04c695ddc58532a0aef58c41a3b9bb9bc15e322969b905cadee6e80d8e9d83cd543fed52fb675
7
+ data.tar.gz: 870dfd5aefdbf7dbb7a2b70a2d35b67e13c7c820e9e3f9a440eca4df03ea43d835f54fb1086d3418d0d58e4474b6dd75f48c611859f0d60511bf0a7627c6e8d3
@@ -5,6 +5,14 @@ class String
5
5
  str = str.force_encoding("BINARY")
6
6
  str.encode("UTF-8", invalid: :replace, undef: :replace)
7
7
  end
8
+
9
+ def delete_at! n
10
+ slice! n
11
+ self
12
+ end
13
+ def delete_at n
14
+ dup.delete_at! n
15
+ end
8
16
  end
9
17
 
10
18
  module FigFont
@@ -35,12 +43,12 @@ module FigFont
35
43
  @commented = meta[5].to_i
36
44
  # defaults, currently not used
37
45
  @print_way = 0
38
- full_lay = 64
39
- tag_count = 229
46
+ @full_lay = 64
47
+ @tag_count = 229
40
48
  if meta.size > 6 # overide defaults
41
49
  @print_way = meta[6].to_i
42
- full_lay = meta[7].to_i
43
- tag_count = meta[8].to_i
50
+ @full_lay = meta[7].to_i
51
+ @tag_count = meta[8].to_i
44
52
  end
45
53
  # we've got the information, now delete it form the `lines`
46
54
  (0..@commented).each { lines.delete_at 0 } # This bugger,
@@ -49,7 +57,6 @@ module FigFont
49
57
  # the first line, embarrassing how long that took.
50
58
  endmark = lines[0][lines[0].length - 1]
51
59
  (0..lines.size - 1).each do |i|
52
- lines[i].gsub!(@hardblank, " ")
53
60
  lines[i].gsub!(endmark, "")
54
61
  end
55
62
 
@@ -75,11 +82,42 @@ module FigFont
75
82
  lines.slice! 0..@height - 1
76
83
  end
77
84
 
85
+ smush! char_hash, lines
86
+ char_hash.each do |key, arr|
87
+ (0..@height - 1).each { |i| char_hash[key][i] = arr[i].gsub(@hardblank, " ") }
88
+ end
78
89
  return char_hash
79
90
  end
80
91
 
92
+ private def smush hash, lines
93
+ hash.each do |letter, letter_arr|
94
+ (0..lines.min_by(&:length).length - 1).each do |over| # from 0 to the length of the shortest line in the array
95
+ same_at_index = Array.new(@height - 1, false)
96
+ (0..@height - 2).each do |down|
97
+ same_at_index[down] = true if (letter_arr[over][down] == letter_arr[over][down + 1]) && (letter_arr[over][down] == ' ' && letter_arr[over][down + 1] == ' ')
98
+ end
99
+ if same_at_index.all?
100
+ (0..@height - 1).each do |down|
101
+ hash[letter][down].delete_at! over
102
+ end
103
+ end
104
+ end # Pre-word smushing for each letter, when there is a consective vertical line of spaces, then smush them away
105
+ end
106
+ hash
107
+ end
108
+
109
+ private def smush! hash, lines
110
+ hash.replace smush hash, lines
111
+ end
112
+
81
113
  def font_data
82
- {'lookup_table': scan, 'height': @height, 'direction': @print_way}
114
+ {
115
+ 'lookup_table': scan,
116
+ 'height': @height,
117
+ 'direction': @print_way,
118
+ 'old_layout': @old_lay,
119
+ 'full_layout': @full_lay
120
+ }
83
121
  end
84
122
  end
85
123
  end
data/lib/ruby_figlet.rb CHANGED
@@ -22,6 +22,7 @@ module RubyFiglet
22
22
  @lookup = data[:lookup_table]
23
23
  @height = data[:height]
24
24
  @direction = data[:direction]
25
+ @smushing = data[:old_layout]
25
26
  string = string.reverse if @direction == 1
26
27
  @string = string
27
28
  @font = font
@@ -35,14 +36,14 @@ module RubyFiglet
35
36
  end
36
37
  string << "\n"
37
38
  end
38
- lines = string.split "\n"
39
39
  if @direction == 1
40
+ lines = string.split "\n"
40
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.
41
42
  lines.each_with_index do |line, i|
42
43
  lines[i].insert 0, " "
43
44
  end
44
45
  end
45
- return lines.join "\n"
46
+ string = lines.join "\n"
46
47
  end
47
48
  return string
48
49
  end
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.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Demonstrandum