tty-font 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9e2386849887ca6ba94f9d32e7e89b7304fd181a
4
- data.tar.gz: f1fdde346a01e43653f6156180ad670366432586
3
+ metadata.gz: a04850a2bc3ff2ea8a003c245f440f58bea9dc88
4
+ data.tar.gz: 0e10290aac997330a2556a13f9e7f250e9762de6
5
5
  SHA512:
6
- metadata.gz: 9c940a8acbf2c27502ce10ddbefd731ffcc5b818b705ca42df62818e49f8385ce7f300e37499559ed57c394638123e9815ad0efa6e308e318f03cf168ee68d8a
7
- data.tar.gz: 600a17cc22208aae3cc5dc17cb77943e61e7753f926c454d10c945e63101e91ed08af1fc6be33e7a3ce7fc4a3fd673350b687cd2c9ab3fe5a6b697839e166acf
6
+ metadata.gz: 55fcb422aca75166e4bc80fab96ac8c78a9715f228f718a846ac5008dc9ecf49fd4af254b28950c3c8d95a818538c17f5aed18b65473270670c69b82974eba9a
7
+ data.tar.gz: 5f9244ea33eeda0776620b0c179f8a2be0c5b276784b4e5e8b98b9591ff002776749c1b7653bf56b0df4279c84512e062e6057e3879f2c2d93cb2e4ea6881f0b
data/.rspec CHANGED
@@ -1,3 +1,4 @@
1
1
  --format documentation
2
2
  --color
3
3
  --require spec_helper
4
+ --warnings
@@ -8,8 +8,9 @@ rvm:
8
8
  - 2.0.0
9
9
  - 2.1.10
10
10
  - 2.2.8
11
- - 2.3.5
12
- - 2.4.2
11
+ - 2.3.6
12
+ - 2.4.3
13
+ - 2.5.0
13
14
  - ruby-head
14
15
  - jruby-9000
15
16
  - jruby-head
@@ -1,7 +1,19 @@
1
1
  # Change log
2
2
 
3
+ ## [v0.2.0] - 2018-02-20
4
+
5
+ ### Added
6
+ * Add Result for processing transformed output
7
+
8
+ ### Changed
9
+ * Change #add_line to #create_line and refactor
10
+
11
+ ### Fixed
12
+ * Fix File to use global namespace
13
+
3
14
  ## [v0.1.0] - 2017-12-18
4
15
 
5
16
  * Initial implementation and release
6
17
 
18
+ [v0.2.0]: https://github.com/piotrmurach/tty-font/compare/v0.1.0...v0.2.0
7
19
  [v0.1.0]: https://github.com/piotrmurach/tty-font/compare/v0.1.0
data/README.md CHANGED
@@ -109,4 +109,4 @@ Everyone interacting in the TTY::Font project’s codebases, issue trackers, cha
109
109
 
110
110
  ## Copyright
111
111
 
112
- Copyright (c) 2017 Piotr Murach. See LICENSE for further details.
112
+ Copyright (c) 2017-2018 Piotr Murach. See LICENSE for further details.
@@ -19,3 +19,5 @@ environment:
19
19
  - ruby_version: "23-x64"
20
20
  - ruby_version: "24"
21
21
  - ruby_version: "24-x64"
22
+ - ruby_version: "25"
23
+ - ruby_version: "25-x64"
@@ -1,5 +1,5 @@
1
- require 'tty-font'
2
1
  require 'pastel'
2
+ require_relative '../lib/tty-font'
3
3
 
4
4
  pastel = Pastel.new
5
5
  font = TTY::Font.new("3d")
@@ -1,5 +1,5 @@
1
- require 'tty-font'
2
1
  require 'pastel'
2
+ require_relative '../lib/tty-font'
3
3
 
4
4
  pastel = Pastel.new
5
5
  font = TTY::Font.new(:doom)
@@ -1,5 +1,5 @@
1
- require 'tty-font'
2
1
  require 'pastel'
2
+ require_relative '../lib/tty-font'
3
3
 
4
4
  pastel = Pastel.new
5
5
  font = TTY::Font.new(:standard)
@@ -1,8 +1,9 @@
1
1
  require 'pastel'
2
- require 'tty-font'
3
2
  require 'tty-cursor'
4
3
  require 'tty-screen'
5
4
 
5
+ require_relative '../lib/tty-font'
6
+
6
7
  @pastel = Pastel.new
7
8
  @cursor = TTY::Cursor
8
9
  @font = TTY::Font.new(:starwars)
@@ -1,5 +1,5 @@
1
- require 'tty-font'
2
1
  require 'pastel'
2
+ require_relative '../lib/tty-font'
3
3
 
4
4
  pastel = Pastel.new
5
5
  font = TTY::Font.new(:starwars)
@@ -1,5 +1,5 @@
1
- require 'tty-font'
2
1
  require 'pastel'
2
+ require_relative '../lib/tty-font'
3
3
 
4
4
  pastel = Pastel.new
5
5
  font = TTY::Font.new(:straight)
@@ -3,11 +3,12 @@
3
3
  require 'pathname'
4
4
  require 'yaml'
5
5
 
6
+ require_relative 'font/result'
6
7
  require_relative 'font/version'
7
8
 
8
9
  module TTY
9
10
  class Font
10
- FONTS_PATH = Pathname.new(File.join(__dir__, 'font'))
11
+ FONTS_PATH = ::Pathname.new(::File.join(__dir__, 'font'))
11
12
 
12
13
  def initialize(font = :standard, **options)
13
14
  @font = font
@@ -22,16 +23,16 @@ module TTY
22
23
  #
23
24
  # @api public
24
25
  def write(text, **options)
25
- output = []
26
+ result = Result.new
26
27
  chars = text.chars
27
28
  space = options.fetch(:letter_spacing) { @space }
28
29
  indexes = words_boundary_indexes(text)
29
30
 
30
- @data['char_height'].times do |line|
31
- output << add_line(chars, indexes, line, space)
31
+ @data['char_height'].times do |line_no|
32
+ result << create_line(chars, indexes, line_no, space)
32
33
  end
33
34
 
34
- output.join("\n")
35
+ result.to_s
35
36
  end
36
37
 
37
38
  # Inspect font attributes
@@ -49,18 +50,17 @@ module TTY
49
50
 
50
51
  private
51
52
 
52
- # Add new line to output
53
+ # Create a new line for the output
54
+ #
55
+ # @return [String]
53
56
  #
54
57
  # @api private
55
- def add_line(chars, indexes, line, space)
56
- chars.each_with_index.reduce([]) do |acc, (char, indx)|
57
- if @data['chars'].key?(char)
58
- acc << @data['chars'][char][line]
59
- acc << ' ' * space if space > 0 && !indexes.include?(indx)
60
- else
58
+ def create_line(chars, indexes, line_no, space)
59
+ chars.each_with_index.map do |char, i|
60
+ unless @data['chars'].key?(char)
61
61
  raise ArgumentError, "Font #{@font} doesn't support '#{char}' character"
62
62
  end
63
- acc
63
+ @data['chars'][char][line_no] + (!indexes.include?(i) ? ' ' : '') * space
64
64
  end.join
65
65
  end
66
66
 
@@ -80,7 +80,7 @@ module TTY
80
80
  #
81
81
  # @api private
82
82
  def load_font(font_path)
83
- YAML.load_file(font_path)
83
+ ::YAML.load_file(font_path)
84
84
  rescue Errno::ENOENT
85
85
  raise ArgumentError, "Font '#{File.basename(font_path)}' not found"
86
86
  end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TTY
4
+ class Font
5
+ # Represents font rendering result. It provides more
6
+ # convenient interface for using the output.
7
+ class Result
8
+ include Enumerable
9
+
10
+ def initialize
11
+ @output = []
12
+ end
13
+
14
+ def each(&block)
15
+ return to_enum(:each) unless block
16
+ @output.each(&block)
17
+ end
18
+
19
+ def add(line)
20
+ @output << line
21
+ end
22
+ alias << add
23
+
24
+ def lines
25
+ @output
26
+ end
27
+
28
+ def to_s
29
+ @output.join("\n")
30
+ end
31
+ end
32
+ end # Font
33
+ end # TTY
@@ -1,5 +1,5 @@
1
1
  module TTY
2
2
  class Font
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end # Font
5
5
  end # TTY
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tty-font
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
  - Piotr Murach
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-12-18 00:00:00.000000000 Z
11
+ date: 2018-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -87,6 +87,7 @@ files:
87
87
  - lib/tty/font.rb
88
88
  - lib/tty/font/3d.yml
89
89
  - lib/tty/font/doom.yml
90
+ - lib/tty/font/result.rb
90
91
  - lib/tty/font/standard.yml
91
92
  - lib/tty/font/starwars.yml
92
93
  - lib/tty/font/straight.yml