formatador 0.3.0 → 1.1.0

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
  SHA256:
3
- metadata.gz: 371ea2974db0d03751e1a559433313ef4f7e7c2c46cabba41f004dba91632065
4
- data.tar.gz: 05ee97c7103cb73f5a6ee26e135a828f2c8d738937409a933c379f66b0f2cd76
3
+ metadata.gz: c7691580892da9215dfc4bbe6523203fef95cd0c57a25652af464d208e1a7a64
4
+ data.tar.gz: 8e99624363cc7a8b76d2cc699664618d184ffdffe16ca4d4b3ce73927aa3e5d0
5
5
  SHA512:
6
- metadata.gz: dbec7dda7093e08b69ff2372fbbff210cc7d6bde6f2d03e6ca5bf4ed03ff0e75ed7791c4a53812f7f1804c11ed801fbad3acadc71dd48a769977f42cde522ddc
7
- data.tar.gz: 54c7902a6d39b65d929c02f9f66c490f27753c3aec04d27c3921b33f8d3a49bc9524965d52eaac0fdd14a7892f0797d38f0e5c758d6c55dd026d465517160e4b
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/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  STDOUT text formatting
4
4
 
5
- [![Build Status](https://travis-ci.org/geemus/formatador.svg)](http://travis-ci.org/geemus/formatador)
5
+ [![Build Status](https://github.com/geemus/formatador/actions/workflows/ruby.yml/badge.svg)](https://github.com/geemus/formatador/actions/workflows/ruby.yml)
6
6
 
7
7
  ## Quick and dirty
8
8
 
@@ -123,7 +123,7 @@ formatador.display_line('one level of indentation')
123
123
 
124
124
  (The MIT License)
125
125
 
126
- Copyright (c) 2015 [geemus (Wesley Beary)](http://github.com/geemus)
126
+ Copyright (c) 2022 [geemus (Wesley Beary)](http://github.com/geemus)
127
127
 
128
128
  Permission is hereby granted, free of charge, to any person obtaining
129
129
  a copy of this software and associated documentation files (the
data/Rakefile CHANGED
@@ -84,7 +84,7 @@ task :release => :build do
84
84
  puts "You must be on the master branch to release!"
85
85
  exit!
86
86
  end
87
- sh "sudo gem install pkg/#{name}-#{version}.gem"
87
+ sh "gem install pkg/#{name}-#{version}.gem"
88
88
  sh "git commit --allow-empty -a -m 'Release #{version}'"
89
89
  sh "git tag v#{version}"
90
90
  sh "git push origin master"
data/changelog.txt CHANGED
@@ -1,3 +1,8 @@
1
+ v1.0.0 01/20/21
2
+ ===============
3
+
4
+ release v1, it's been stable for ages
5
+
1
6
  v0.3.0 06/17/21
2
7
  ===============
3
8
 
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 = '0.3.0'
17
- s.date = '2021-06-17'
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 = '0.3.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
  +------+
@@ -106,7 +136,7 @@ output = <<-OUTPUT
106
136
  OUTPUT
107
137
  output = Formatador.parse(output)
108
138
 
109
- tests("#display_table([{:a => 1}, {:a => 2}])").returns(output) do
139
+ tests("#display_table([{:a => 1}, {:a => '震度'}])").returns(output) do
110
140
  capture_stdout do
111
141
  Formatador.display_table([{:a => 1}, {:a => "震度"}])
112
142
  end
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: 0.3.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: 2021-06-17 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