ruby_figlet 0.5.1 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -6
- data/lib/ruby_figlet.rb +3 -2
- data/lib/ruby_figlet/interface.rb +19 -14
- data/lib/ruby_figlet/parser.rb +23 -17
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e559305adf72baf5a2742d277b4f93e366b149e
|
4
|
+
data.tar.gz: 429c534c7c3c1b319e40a60334938b9ac7a8df31
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc8a8c7360155bdafab1f7389ce51297f1a6b9d22614bef68317e6d73d137f222d1a2d9ab7fd1519311008b537a0c12a3b9ca45e7ad8e15f9f210dfc93bf2373
|
7
|
+
data.tar.gz: 003fafe9daa0f7a9869d3e7cc0a7d18ec34d0fda6a6703e9aae51b1570f8d3456dc162e106d23f1124f2147c99cd891a09efc925f606bca0c627dd3bc277e327
|
data/README.md
CHANGED
@@ -17,20 +17,22 @@ gem install ruby_figlet --no-rdoc --no-ri
|
|
17
17
|
In your shell
|
18
18
|
```shell
|
19
19
|
ruby-figlet -f alligator "ruby"
|
20
|
-
|
20
|
+
```
|
21
|
+
```
|
21
22
|
::::::::: ::: ::: ::::::::: ::: :::
|
22
23
|
:+: :+: :+: :+: :+: :+: :+: :+:
|
23
24
|
+:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+
|
24
25
|
+#++:++#: +#+ +:+ +#++:++#+ +#++:
|
25
26
|
+#+ +#+ +#+ +#+ +#+ +#+ +#+
|
26
27
|
#+# #+# #+# #+# #+# #+# #+#
|
27
|
-
### ### ######## ######### ###
|
28
|
-
|
28
|
+
### ### ######## ######### ###
|
29
|
+
```
|
30
|
+
```shell
|
29
31
|
# You can list all the possible fonts with `ruby-figlet list`
|
30
32
|
# To preview the fonts, you could do something like this:
|
31
33
|
OLDIFS=$IFS; IFS=$'\n'; for f in $(ruby-figlet list); do printf "\n\n\nFont: \"$f\":\n\n"; ruby-figlet "$f " -f "$f"; done; IFS=$OLDIFS
|
32
34
|
|
33
|
-
# please note that the list of fonts is very long, and will flood the terminal.
|
35
|
+
# please note that the list of fonts is very long, and will flood the terminal.
|
34
36
|
```
|
35
37
|
But mainly as a library
|
36
38
|
|
@@ -57,7 +59,7 @@ puts moo # Default font is 'standard' when no arguments given
|
|
57
59
|
# or
|
58
60
|
|
59
61
|
puts "meow...".art # all
|
60
|
-
puts RubyFiglet::Figlet.new("meow...").
|
62
|
+
puts RubyFiglet::Figlet.new("meow...").to_s # work
|
61
63
|
RubyFiglet::Figlet.new("meow...").show # equally
|
62
64
|
|
63
65
|
# str.art(font)/str.art!(font) and RubyFiglet::Figlet.new(str, font) have a font parameter!
|
@@ -112,4 +114,3 @@ two_lines.show
|
|
112
114
|
# 88booo. .88. 88 V888 88.
|
113
115
|
# Y88888P Y888888P VP V8P Y88888P
|
114
116
|
```
|
115
|
-
|
data/lib/ruby_figlet.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
Dir["#{File.dirname __FILE__}/ruby_figlet/*.rb"].each { |f| require f }
|
2
2
|
|
3
|
+
# Main namespace for all RubyFIGlet classes and methods.
|
3
4
|
module RubyFiglet
|
4
|
-
VERSIONS = { :major => 0, :minor =>
|
5
|
+
VERSIONS = { :major => 0, :minor => 6, :tiny => 1 }.freeze
|
5
6
|
|
6
7
|
def self.version *args
|
7
|
-
VERSIONS.flatten.select.with_index { |
|
8
|
+
VERSIONS.flatten.select.with_index { |_, i| i.odd? }.join '.'
|
8
9
|
end
|
9
10
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class String
|
2
2
|
def each
|
3
3
|
i = 0
|
4
|
-
while i <
|
4
|
+
while i < length
|
5
5
|
yield self[i]
|
6
6
|
i += 1
|
7
7
|
end
|
@@ -16,17 +16,18 @@ module RubyFiglet
|
|
16
16
|
|
17
17
|
class Figlet
|
18
18
|
def initialize string, font='standard'
|
19
|
-
|
20
|
-
|
21
|
-
@
|
22
|
-
@
|
23
|
-
@
|
19
|
+
parsed = Parser.new(font)
|
20
|
+
font_data = parsed.font_table
|
21
|
+
@lookup = font_data[:letter_lookup]
|
22
|
+
@height = font_data[:height]
|
23
|
+
@direction = font_data[:direction]
|
24
|
+
@smushing = font_data[:old_layout]
|
24
25
|
string = string.reverse if @direction == 1
|
25
26
|
@string = string
|
26
27
|
@font = font
|
27
28
|
end
|
28
29
|
|
29
|
-
def
|
30
|
+
def to_s
|
30
31
|
breaks = @string.split "\n"
|
31
32
|
breaks.each_with_index do |break_line, i|
|
32
33
|
string = String.new
|
@@ -36,8 +37,10 @@ module RubyFiglet
|
|
36
37
|
end
|
37
38
|
if @direction == 1
|
38
39
|
lines = string.split "\n"
|
39
|
-
(0..(%x[tput cols].to_i - 1) - lines
|
40
|
-
|
40
|
+
(0..(%x[tput cols].to_i - 1) - lines.max_by(&:length).length).each do
|
41
|
+
# Holy Moly, from 0 to (terminal width minus 1) minus max length
|
42
|
+
# of the ASCII art word.
|
43
|
+
lines.each_with_index { |_, j| lines[j].insert 0, " " }
|
41
44
|
end
|
42
45
|
string = lines.join "\n"
|
43
46
|
end
|
@@ -48,14 +51,16 @@ module RubyFiglet
|
|
48
51
|
lines = string.split "\n"
|
49
52
|
offset = 0
|
50
53
|
(lines.size).times do |j|
|
51
|
-
if lines[j - offset].strip.empty?
|
54
|
+
if lines[j - offset].strip.empty?
|
52
55
|
lines.delete_at(j - offset) # Remove any empty lines
|
53
56
|
offset += 1
|
54
57
|
end
|
55
58
|
end
|
56
|
-
|
59
|
+
lines.join "\n"
|
57
60
|
end
|
58
61
|
|
62
|
+
alias stringify to_s
|
63
|
+
|
59
64
|
def show
|
60
65
|
puts stringify
|
61
66
|
end
|
@@ -67,15 +72,15 @@ module RubyFiglet
|
|
67
72
|
dir[i] += '/' unless dir[i].include? '.'
|
68
73
|
end
|
69
74
|
(0..dir.size - 1).each do |i|
|
70
|
-
dir[i] =
|
75
|
+
dir[i] = '' unless dir[i].include?('.flf') || dir[i].include?('/')
|
71
76
|
end
|
72
77
|
|
73
|
-
dir.sort_by!
|
78
|
+
dir.sort_by!(&:downcase)
|
74
79
|
list = dir.join "\n"
|
75
80
|
ignore = ["..", ".", ".DS_Store", "._.DS_Store", ".DS_Store?", ".Spotlight-V100", ".Trashes", "ehthumbs.db", "Thumbs.db", "desktop.ini"]
|
76
81
|
ignore.each { |file| list.gsub! "#{file}/", "" }
|
77
82
|
|
78
|
-
list.gsub! ".flf", ""
|
83
|
+
list.gsub! ".flf", "" # Don't show extensions
|
79
84
|
list.squeeze! "\n"
|
80
85
|
end
|
81
86
|
end
|
data/lib/ruby_figlet/parser.rb
CHANGED
@@ -1,26 +1,32 @@
|
|
1
|
+
# Add some useful methods for String class:
|
2
|
+
# - String#to_utf8 forces utf8 encoding
|
3
|
+
# - String#delete_at returns a new string with a certain index of a character
|
4
|
+
# deleted.
|
5
|
+
# - String#delete_at! is the self mutating equivilant.
|
1
6
|
class String
|
2
7
|
def to_utf8
|
3
|
-
str =
|
8
|
+
str = force_encoding 'UTF-8'
|
4
9
|
return str if str.valid_encoding?
|
5
|
-
str = str.force_encoding
|
6
|
-
str.encode
|
10
|
+
str = str.force_encoding 'BINARY'
|
11
|
+
str.encode 'UTF-8', :invalid => :replace, :undef => :replace
|
7
12
|
end
|
8
13
|
|
9
14
|
def delete_at! n
|
10
15
|
slice! n
|
11
16
|
self
|
12
17
|
end
|
18
|
+
|
13
19
|
def delete_at n
|
14
20
|
dup.delete_at! n
|
15
21
|
end
|
16
22
|
end
|
17
23
|
|
18
|
-
module
|
24
|
+
module RubyFiglet
|
19
25
|
WD = File.dirname(__FILE__)
|
20
|
-
class
|
26
|
+
class Parser
|
21
27
|
def initialize font
|
22
28
|
unless Dir.entries("#{WD}/fonts").include? "#{font}.flf"
|
23
|
-
puts
|
29
|
+
puts 'Font not found!'
|
24
30
|
exit 1
|
25
31
|
end
|
26
32
|
@fontName = font
|
@@ -61,7 +67,7 @@ module FigFont
|
|
61
67
|
char_hash[code.chr] = Array.new(@height, String.new)
|
62
68
|
end # Much shorter than manually writing out every value
|
63
69
|
|
64
|
-
char_hash.merge!(
|
70
|
+
char_hash.merge!(
|
65
71
|
'Ä' => Array.new(@height, String.new),
|
66
72
|
'Ö' => Array.new(@height, String.new),
|
67
73
|
'Ü' => Array.new(@height, String.new),
|
@@ -69,32 +75,32 @@ module FigFont
|
|
69
75
|
'ö' => Array.new(@height, String.new),
|
70
76
|
'ü' => Array.new(@height, String.new),
|
71
77
|
'ß' => Array.new(@height, String.new)
|
72
|
-
|
78
|
+
) if lines.length > 94 * @height # 94 is the n. of required ASCII chars
|
73
79
|
|
74
|
-
char_hash.each do |key,
|
80
|
+
char_hash.each do |key, _|
|
75
81
|
@height.times { |line| char_hash[key][line] = lines[line] }
|
76
82
|
lines.slice! 0..@height - 1
|
77
83
|
end
|
78
84
|
|
79
85
|
smush! char_hash unless @old_lay == -1
|
80
86
|
char_hash.each do |key, arr|
|
81
|
-
@height.times { |i| char_hash[key][i] = arr[i].gsub
|
87
|
+
@height.times { |i| char_hash[key][i] = arr[i].gsub @hardblank, " " }
|
82
88
|
end
|
83
89
|
|
84
90
|
# Add fake newline character
|
85
|
-
newline = Array.new
|
91
|
+
newline = Array.new @height, String.new
|
86
92
|
newline[-1] = 10.chr
|
87
93
|
char_hash[10.chr] = newline
|
88
94
|
|
89
|
-
|
95
|
+
char_hash
|
90
96
|
end
|
91
97
|
|
92
98
|
private def smush hash
|
93
99
|
hash.each do |letter, letter_arr|
|
94
|
-
(0..letter_arr.min_by(&:length).length - 1).each do |over|
|
95
|
-
same_at_index = Array.new
|
100
|
+
(0..letter_arr.min_by(&:length).length - 1).each do |over|
|
101
|
+
same_at_index = Array.new @height - 1, false
|
96
102
|
(0..@height - 2).each do |down|
|
97
|
-
same_at_index[down] =
|
103
|
+
same_at_index[down] = letter_arr[down][over] == ' ' && letter_arr[down + 1][over] == ' '
|
98
104
|
end
|
99
105
|
if same_at_index.all?
|
100
106
|
@height.times { |down| hash[letter][down].delete_at! over }
|
@@ -108,9 +114,9 @@ module FigFont
|
|
108
114
|
hash.replace smush hash
|
109
115
|
end
|
110
116
|
|
111
|
-
def
|
117
|
+
def font_table
|
112
118
|
{
|
113
|
-
'
|
119
|
+
'letter_lookup': scan,
|
114
120
|
'height': @height,
|
115
121
|
'direction': @print_way,
|
116
122
|
'old_layout': @old_lay,
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_figlet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Demonstrandum
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-01 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: FIGlet font interpretation and printing library for Ruby
|
14
14
|
email: knutsen@jetspace.co
|
@@ -777,7 +777,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
777
777
|
version: '0'
|
778
778
|
requirements: []
|
779
779
|
rubyforge_project:
|
780
|
-
rubygems_version: 2.6.
|
780
|
+
rubygems_version: 2.6.14
|
781
781
|
signing_key:
|
782
782
|
specification_version: 4
|
783
783
|
summary: FIGlet in Ruby
|