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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 914c78b137f42af31f9f51fb045ec3dd89907558
4
- data.tar.gz: 50ffca3499b0e66e4f9d7c751e89ed9131f5e415
3
+ metadata.gz: 9e559305adf72baf5a2742d277b4f93e366b149e
4
+ data.tar.gz: 429c534c7c3c1b319e40a60334938b9ac7a8df31
5
5
  SHA512:
6
- metadata.gz: 938c479afac3b41865cb30073fdade656759116ac6163fba95da698f8f56340fee836bd11e610dc11a287bf9e6cce919c3f3154fb7669292e908f8c9e4117c20
7
- data.tar.gz: 74a48d0b32c5b1b132f12afdaf258bc3ccfbf852189902412429f0802de10cf4815fcd2eeef31269d2d62b3eeaee30bd32e3ce830165283649609fed6c070364
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...").stringify # work
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
-
@@ -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, :tiny => 1 }
5
+ VERSIONS = { :major => 0, :minor => 6, :tiny => 1 }.freeze
5
6
 
6
7
  def self.version *args
7
- VERSIONS.flatten.select.with_index { |val, i| i.odd? }.join '.'
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 < self.length
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
- data = FigFont::Figlet.new(font).font_data
20
- @lookup = data[:lookup_table]
21
- @height = data[:height]
22
- @direction = data[:direction]
23
- @smushing = data[:old_layout]
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 stringify
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[0].length).each do # Holy Moly, from 0 to (terminal width minus 1) minus length of the ascii art word.
40
- lines.each_with_index { |line, j| lines[j].insert 0, " " }
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? # 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
+ 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
- return lines.join "\n"
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] = "" unless dir[i].include?('.flf') || dir[i].include?('/')
75
+ dir[i] = '' unless dir[i].include?('.flf') || dir[i].include?('/')
71
76
  end
72
77
 
73
- dir.sort_by! &:downcase
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", "" # don't show extensions
83
+ list.gsub! ".flf", "" # Don't show extensions
79
84
  list.squeeze! "\n"
80
85
  end
81
86
  end
@@ -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 = self.force_encoding("UTF-8")
8
+ str = force_encoding 'UTF-8'
4
9
  return str if str.valid_encoding?
5
- str = str.force_encoding("BINARY")
6
- str.encode("UTF-8", invalid: :replace, undef: :replace)
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 FigFont
24
+ module RubyFiglet
19
25
  WD = File.dirname(__FILE__)
20
- class Figlet
26
+ class Parser
21
27
  def initialize font
22
28
  unless Dir.entries("#{WD}/fonts").include? "#{font}.flf"
23
- puts "Font not found!"
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
- }) if lines.length > 95 * @height # 95 is the range of the num. of the default chars
78
+ ) if lines.length > 94 * @height # 94 is the n. of required ASCII chars
73
79
 
74
- char_hash.each do |key, value|
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(@hardblank, " ") }
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(@height, String.new)
91
+ newline = Array.new @height, String.new
86
92
  newline[-1] = 10.chr
87
93
  char_hash[10.chr] = newline
88
94
 
89
- return char_hash
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| # from 0 to the length of the shortest line in the array
95
- same_at_index = Array.new(@height - 1, false)
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] = true if (letter_arr[down][over] == letter_arr[down + 1][over]) && (letter_arr[down][over] == ' ' && letter_arr[down + 1][over] == ' ')
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 font_data
117
+ def font_table
112
118
  {
113
- 'lookup_table': scan,
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.5.1
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: 2017-09-23 00:00:00.000000000 Z
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.11
780
+ rubygems_version: 2.6.14
781
781
  signing_key:
782
782
  specification_version: 4
783
783
  summary: FIGlet in Ruby