formatador 1.0.0 → 1.1.1

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
  SHA256:
3
- metadata.gz: 58153bcd41291dcdd4aa4bbcfb724d233604d130470634682306fb0e8859f041
4
- data.tar.gz: 20d3a52adff269f0a29fc6c1dda6dd87679151fa13bc496f0fbb1a7edc3ae07b
3
+ metadata.gz: 9f775eb2a13c13d00ecb5b23150628a0336716adcf9b3125c35b6d6ca3e12827
4
+ data.tar.gz: f9cfbb270ef4f89f465bbc09711329e379329c84ba603721c736c8ea59146c42
5
5
  SHA512:
6
- metadata.gz: 12616b0af1aea1c3b5ee100440096e7b8def45f9ed5340efd98bbc958384005b80cb9dde10d16e0f443f8520b7466a67d93fe5d03a980a19988c3db9e08eef0f
7
- data.tar.gz: 7fd4a23d9cd157ed4e86dcec4ad15cbd277220c1c62346f36d414af5aac1db8a634a57e952073cca1feb015c039cd777b18dbbb9fadf24c983025ee4bdbf7e01
6
+ metadata.gz: 39fe3363f0bb482dc4709c37323f13cfd4422d6e3ad493f4913d9da7f76683c629c61e1d4cf8bc02e89e0bbad6d72b3fa9d4dab6abcab124f7e1289ad0ee9255
7
+ data.tar.gz: 30d4ea6d8fd9acb1908c39851fd288b215ae11c8c4aebb089e0b1564fa0ee6a93939252f2c4a15e8ecc23e744e21850aaa0f56cb8a345d01ed43eeab96527ae2
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
- source "http://rubygems.org"
1
+ source "https://rubygems.org"
2
2
 
3
3
  gemspec
data/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2009-2013 [CONTRIBUTORS.md](https://github.com/geemus/formatador/blob/master/CONTRIBUTORS.md)
3
+ Copyright (c) 2009-2022 [CONTRIBUTORS.md](https://github.com/geemus/formatador/blob/master/CONTRIBUTORS.md)
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
  this software and associated documentation files (the "Software"), to deal in
data/SECURITY.md ADDED
@@ -0,0 +1,6 @@
1
+ ## Security contact information
2
+
3
+ To report a security vulnerability, please contact
4
+ [Tidelift security](https://tidelift.com/security).
5
+
6
+ Tidelift will coordinate the fix and disclosure.
data/changelog.txt CHANGED
@@ -1,3 +1,25 @@
1
+ v1.1.1 07/11/25
2
+ ===============
3
+
4
+ update actions/stale
5
+ update actions/checkout
6
+ improve unicode support
7
+ update ruby versions in test matrix
8
+ add funding info
9
+ move scheduled CI to weekly
10
+ update tested ruby versions
11
+ more consistently use length method in tables
12
+ adjust expected test output for Ruby 3.4+
13
+
14
+ v1.1.0 01/24/22
15
+ ===============
16
+
17
+ fixes to support ruby 3+
18
+ add options for right justifying numerics
19
+ drop unused gemspec directive
20
+ use https for rubygems.org in gemspec
21
+ drop duplicate bundle install from CI setup
22
+
1
23
  v1.0.0 01/20/21
2
24
  ===============
3
25
 
data/formatador.gemspec CHANGED
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
13
13
  ## If your rubyforge_project name is different, then edit it and comment out
14
14
  ## the sub! line in the Rakefile
15
15
  s.name = 'formatador'
16
- s.version = '1.0.0'
17
- s.date = '2022-01-20'
16
+ s.version = '1.1.1'
17
+ s.date = '2025-07-11'
18
18
 
19
19
  ## Make sure your summary is short. The description may be as long
20
20
  ## as you like.
@@ -67,6 +67,7 @@ Gem::Specification.new do |s|
67
67
  LICENSE.md
68
68
  README.md
69
69
  Rakefile
70
+ SECURITY.md
70
71
  changelog.txt
71
72
  formatador.gemspec
72
73
  lib/formatador.rb
@@ -77,8 +78,4 @@ Gem::Specification.new do |s|
77
78
  tests/tests_helper.rb
78
79
  ]
79
80
  # = MANIFEST =
80
-
81
- ## Test files will be grabbed from the file list. Make sure the path glob
82
- ## matches what you actually use.
83
- s.test_files = s.files.select { |path| path =~ /^[spec|tests]\/.*_[spec|tests]\.rb/ }
84
81
  end
@@ -1,20 +1,20 @@
1
1
  class Formatador
2
- def display_table(hashes, keys = nil, &block)
2
+ def display_table(hashes, keys = nil, **options, &block)
3
3
  new_hashes = hashes.inject([]) do |accum,item|
4
4
  accum << :split unless accum.empty?
5
5
  accum << item
6
6
  end
7
- display_compact_table(new_hashes, keys, &block)
7
+ display_compact_table(new_hashes, keys, **options, &block)
8
8
  end
9
9
 
10
- def display_compact_table(hashes, keys = nil, &block)
10
+ def display_compact_table(hashes, keys = nil, **options, &block)
11
11
  headers = keys || []
12
12
  widths = {}
13
13
 
14
14
  # Calculate Widths
15
15
  if hashes.empty? && keys
16
16
  keys.each do |key|
17
- widths[key] = key.to_s.length
17
+ widths[key] = length(key)
18
18
  end
19
19
  else
20
20
  hashes.each do |hash|
@@ -24,7 +24,7 @@ class Formatador
24
24
  if !keys
25
25
  headers << key
26
26
  end
27
- widths[key] = [ length(key), widths[key] || 0, length(calculate_datum(key, hash)) || 0].max
27
+ widths[key] = [length(key), widths[key] || 0, length(calculate_datum(key, hash)) || 0].max
28
28
  end
29
29
  headers = headers.uniq
30
30
  end
@@ -52,25 +52,25 @@ class Formatador
52
52
  # Display data row
53
53
  columns = []
54
54
  headers.each do |header|
55
- columns << "[bold]#{header}[/]#{' ' * (widths[header] - header.to_s.length)}"
55
+ columns << "[bold]#{header}[/]#{' ' * (widths[header] - length(header))}"
56
56
  end
57
57
  display_line("| #{columns.join(' | ')} |")
58
58
  display_line(split)
59
59
 
60
60
  hashes.each do |hash|
61
61
  if hash.respond_to? :keys
62
- columns = []
63
- headers.each do |header|
62
+ columns = headers.map do |header|
64
63
  datum = calculate_datum(header, hash)
65
64
  width = widths[header] - length(datum)
66
65
  width = width < 0 ? 0 : width
67
- columns << "#{datum}#{' ' * width}"
66
+
67
+ datum.is_a?(Numeric) && options[:numeric_rjust] ? "#{' ' * width}#{datum}" : "#{datum}#{' ' * width}"
68
68
  end
69
69
  display_line("| #{columns.join(' | ')} |")
70
70
  else
71
71
  if hash == :split
72
72
  display_line(split)
73
- end
73
+ end
74
74
  end
75
75
  nil
76
76
  end
@@ -80,7 +80,7 @@ class Formatador
80
80
  private
81
81
 
82
82
  def length(value)
83
- if Module.const_defined?(:Unicode)
83
+ if Module.const_defined?(:Unicode) && Unicode.respond_to?(:width)
84
84
  Unicode.width(value.to_s.gsub(PARSE_REGEX, ''))
85
85
  else
86
86
  value.to_s.gsub(PARSE_REGEX, '').chars.reduce(0) { |sum, char| sum += char.bytesize > 1 ? 2 : 1 }
data/lib/formatador.rb CHANGED
@@ -3,7 +3,7 @@ require File.join(File.dirname(__FILE__), 'formatador', 'progressbar')
3
3
 
4
4
  class Formatador
5
5
 
6
- VERSION = '1.0.0'
6
+ VERSION = '1.1.1'
7
7
 
8
8
  STYLES = {
9
9
  :"\/" => "0",
@@ -119,7 +119,7 @@ class Formatador
119
119
  string.gsub(PARSE_REGEX, '').gsub(INDENT_REGEX) { indentation }
120
120
  end
121
121
 
122
- %w{display display_line display_lines display_table display_compact_table indent parse redisplay redisplay_line new_line redisplay_progressbar}.each do |method|
122
+ %w{display display_line display_lines indent parse redisplay redisplay_line new_line redisplay_progressbar}.each do |method|
123
123
  eval <<-DEF
124
124
  def self.#{method}(*args, &block)
125
125
  Thread.current[:formatador] ||= new
@@ -128,4 +128,13 @@ class Formatador
128
128
  DEF
129
129
  end
130
130
 
131
+ %w{display_table display_compact_table}.each do |method|
132
+ eval <<-DEF
133
+ def self.#{method}(*args, **kwargs, &block)
134
+ Thread.current[:formatador] ||= new
135
+ Thread.current[:formatador].#{method}(*args, **kwargs, &block)
136
+ end
137
+ DEF
138
+ end
139
+
131
140
  end
data/tests/table_tests.rb CHANGED
@@ -64,6 +64,16 @@ output = Formatador.parse(output)
64
64
  end
65
65
  end
66
66
 
67
+
68
+ if (RUBY_VERSION.split('.').map(&:to_i) <=> [3, 4, 0]).positive?
69
+ output = <<-OUTPUT
70
+ +---+----------------+
71
+ | [bold]a[/] | [bold]nested[/] |
72
+ +---+----------------+
73
+ | 1 | {key: "value"} |
74
+ +---+----------------+
75
+ OUTPUT
76
+ else
67
77
  output = <<-OUTPUT
68
78
  +---+-----------------+
69
79
  | [bold]a[/] | [bold]nested[/] |
@@ -71,6 +81,7 @@ output = <<-OUTPUT
71
81
  | 1 | {:key=>"value"} |
72
82
  +---+-----------------+
73
83
  OUTPUT
84
+ end
74
85
  output = Formatador.parse(output)
75
86
 
76
87
  tests("#display_table([{:a => 1, :nested => {:key => 'value'}}])").returns(output) do
@@ -94,6 +105,36 @@ output = Formatador.parse(output)
94
105
  end
95
106
  end
96
107
 
108
+ output = <<-OUTPUT
109
+ +-------------------------+----------------+
110
+ | [bold]right-justify a numeric[/] | [bold]standard value[/] |
111
+ +-------------------------+----------------+
112
+ | 12345 | value |
113
+ +-------------------------+----------------+
114
+ OUTPUT
115
+ output = Formatador.parse(output)
116
+
117
+ tests("#display_table([{'right-justify a numeric' => 12345, 'standard value' => 'standard value'}], numeric_rjust: true)").returns(output) do
118
+ capture_stdout do
119
+ Formatador.display_table([{'right-justify a numeric' => 12345, 'standard value' => 'value'}], numeric_rjust: true)
120
+ end
121
+ end
122
+
123
+ output = <<-OUTPUT
124
+ +--------+------------+
125
+ | [bold]header[/] | [bold]nested.key[/] |
126
+ +--------+------------+
127
+ | 12345 | value |
128
+ +--------+------------+
129
+ OUTPUT
130
+ output = Formatador.parse(output)
131
+
132
+ tests("#display_table([{:header => 12345, :nested => {:key => value}}], [:header, :'nested.key'], numeric_rjust: true)").returns(output) do
133
+ capture_stdout do
134
+ Formatador.display_table([{:header => 12345, :nested => {:key => 'value'}}], [:header, :'nested.key'], numeric_rjust: true)
135
+ end
136
+ end
137
+
97
138
 
98
139
  output = <<-OUTPUT
99
140
  +------+
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formatador
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - geemus (Wesley Beary)
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2022-01-20 00:00:00.000000000 Z
10
+ date: 2025-07-11 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: rake
@@ -65,6 +64,7 @@ files:
65
64
  - LICENSE.md
66
65
  - README.md
67
66
  - Rakefile
67
+ - SECURITY.md
68
68
  - changelog.txt
69
69
  - formatador.gemspec
70
70
  - lib/formatador.rb
@@ -77,7 +77,6 @@ homepage: https://github.com/geemus/formatador
77
77
  licenses:
78
78
  - MIT
79
79
  metadata: {}
80
- post_install_message:
81
80
  rdoc_options:
82
81
  - "--charset=UTF-8"
83
82
  require_paths:
@@ -93,8 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
92
  - !ruby/object:Gem::Version
94
93
  version: '0'
95
94
  requirements: []
96
- rubygems_version: 3.2.15
97
- signing_key:
95
+ rubygems_version: 3.6.9
98
96
  specification_version: 2
99
97
  summary: Ruby STDOUT text formatting
100
98
  test_files: []