formatador 1.0.0 → 1.1.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
  SHA256:
3
- metadata.gz: 58153bcd41291dcdd4aa4bbcfb724d233604d130470634682306fb0e8859f041
4
- data.tar.gz: 20d3a52adff269f0a29fc6c1dda6dd87679151fa13bc496f0fbb1a7edc3ae07b
3
+ metadata.gz: c7691580892da9215dfc4bbe6523203fef95cd0c57a25652af464d208e1a7a64
4
+ data.tar.gz: 8e99624363cc7a8b76d2cc699664618d184ffdffe16ca4d4b3ce73927aa3e5d0
5
5
  SHA512:
6
- metadata.gz: 12616b0af1aea1c3b5ee100440096e7b8def45f9ed5340efd98bbc958384005b80cb9dde10d16e0f443f8520b7466a67d93fe5d03a980a19988c3db9e08eef0f
7
- data.tar.gz: 7fd4a23d9cd157ed4e86dcec4ad15cbd277220c1c62346f36d414af5aac1db8a634a57e952073cca1feb015c039cd777b18dbbb9fadf24c983025ee4bdbf7e01
6
+ metadata.gz: 240f470bb912d51efd07d5916ba31ca06694db82058146ad1d5403959966bc8c4c7c409b5d53958ac6232a87d46ff299e9640a7b5b4333bbff527fdf0055f604
7
+ data.tar.gz: 10800e56b00b910904da64dc8a8b64d01e717ffcc91ec19d4ac4e3c4e94ce903921722707ca16cc675c082bff888e170b1324da5426f7f8e7c1668de64448b37
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/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.0'
17
+ s.date = '2022-01-24'
18
18
 
19
19
  ## Make sure your summary is short. The description may be as long
20
20
  ## as you like.
@@ -77,8 +77,4 @@ Gem::Specification.new do |s|
77
77
  tests/tests_helper.rb
78
78
  ]
79
79
  # = 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
80
  end
@@ -1,13 +1,13 @@
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
 
@@ -59,12 +59,12 @@ class Formatador
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
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.0'
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
@@ -94,6 +94,36 @@ output = Formatador.parse(output)
94
94
  end
95
95
  end
96
96
 
97
+ output = <<-OUTPUT
98
+ +-------------------------+----------------+
99
+ | [bold]right-justify a numeric[/] | [bold]standard value[/] |
100
+ +-------------------------+----------------+
101
+ | 12345 | value |
102
+ +-------------------------+----------------+
103
+ OUTPUT
104
+ output = Formatador.parse(output)
105
+
106
+ tests("#display_table([{'right-justify a numeric' => 12345, 'standard value' => 'standard value'}], numeric_rjust: true)").returns(output) do
107
+ capture_stdout do
108
+ Formatador.display_table([{'right-justify a numeric' => 12345, 'standard value' => 'value'}], numeric_rjust: true)
109
+ end
110
+ end
111
+
112
+ output = <<-OUTPUT
113
+ +--------+------------+
114
+ | [bold]header[/] | [bold]nested.key[/] |
115
+ +--------+------------+
116
+ | 12345 | value |
117
+ +--------+------------+
118
+ OUTPUT
119
+ output = Formatador.parse(output)
120
+
121
+ tests("#display_table([{:header => 12345, :nested => {:key => value}}], [:header, :'nested.key'], numeric_rjust: true)").returns(output) do
122
+ capture_stdout do
123
+ Formatador.display_table([{:header => 12345, :nested => {:key => 'value'}}], [:header, :'nested.key'], numeric_rjust: true)
124
+ end
125
+ end
126
+
97
127
 
98
128
  output = <<-OUTPUT
99
129
  +------+
metadata CHANGED
@@ -1,14 +1,14 @@
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.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - geemus (Wesley Beary)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-20 00:00:00.000000000 Z
11
+ date: 2022-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -93,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
93
  - !ruby/object:Gem::Version
94
94
  version: '0'
95
95
  requirements: []
96
- rubygems_version: 3.2.15
96
+ rubygems_version: 3.3.5
97
97
  signing_key:
98
98
  specification_version: 2
99
99
  summary: Ruby STDOUT text formatting