helium-console 0.1.9 → 0.1.10

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: 9bae4abb107ba24a4d9e30434e48cbfb8ff57b75b1bc5f636c2208a4af066b20
4
- data.tar.gz: 910786c0c312352c2a202bc82646c38135fa8e1890318ba4f91e4fc4f9955467
3
+ metadata.gz: 2775258ea31537dc27077753497d8c6fef2d34f31e6470c17574cd30395675e9
4
+ data.tar.gz: eafd3659c58654fc6566359f52093c928d7ecfc4bab9c23df74330f814760c6c
5
5
  SHA512:
6
- metadata.gz: 7d0cf4390043396e2dcf8f550b5ac4ef827dca0445abe9c740290a97d9c09c2986c1ab8b283870e2e9bf2821590c828033d86a6bd3247611a633f26f8d333009
7
- data.tar.gz: 26a26250b08bdf800e852887047f8c8848886bee69afa105bdd456688af6ee570a22fd17889624c5113d34b081f98bb1f5790ebb8be0733f62d841a089ff0730
6
+ metadata.gz: a18002a4319bb7154810167feb4888ab5199034f001262614d291725623a856fd0a18fea8c362573fb049b823b10753a928bc3401fefcda8be66258f3420bb39
7
+ data.tar.gz: 56b961dcbfab3a0b39041abba71a36e90166cb7f409f9ea54d3957b2c147ba304e5c35d6c1dcb5c0415e9b0d3f5ea71bbdfb14494ca08a15526b5e43dfa2a89b
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- helium-console (0.1.9)
4
+ helium-console (0.1.10)
5
5
  colorize
6
6
  pry
7
7
 
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Helium
4
+ class Console
5
+ define_formatter_for 'Date' do
6
+ def call
7
+ blue object.strftime('%A, %d %b %Y')
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Helium
4
+ class Console
5
+ define_formatter_for 'Pathname' do
6
+ def call
7
+ "#{format(Pathname, short: true)}: #{yellow(object.to_s)}"
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Helium
4
+ class Console
5
+ define_formatter_for Set do
6
+ def call
7
+ return "#{light_magenta('Set:')} #{red 'empty'}" if object.none?
8
+ return inline_with_truncation if force_inline?
9
+
10
+ inline_without_truncation || format_as_table
11
+ end
12
+
13
+ def simple?
14
+ object.none?
15
+ end
16
+
17
+ private
18
+
19
+ def format_as_table
20
+ table = Table.new(runner: '', format_keys: false)
21
+ object.each do |element|
22
+ table.row(light_magenta('-'), element)
23
+ end
24
+
25
+ [
26
+ light_magenta('Set: {'),
27
+ format(table),
28
+ light_magenta('}')
29
+ ].join("\n")
30
+ end
31
+
32
+ def inline_with_truncation
33
+ formatted = formatted_elements.with_index.inject([]) do |joined, (element, index)|
34
+ new_joined = [*joined[0..-2], element, trunc_message(object_size - index - 1, all_truncated: index.zero?)]
35
+ break joined if too_long?(new_joined, max_width: max_width - 9)
36
+
37
+ new_joined
38
+ end
39
+
40
+ "#{light_magenta('Set: {')} #{formatted.join(light_magenta(' | '))} #{light_magenta('}')}"
41
+ end
42
+
43
+ def inline_without_truncation
44
+ return unless object.all? { |element| Helium::Console.simple? element }
45
+
46
+ formatted = formatted_elements.inject([]) do |joined, element|
47
+ joined = [*joined, element]
48
+ break if too_long?(joined, max_width: max_width - 4)
49
+
50
+ joined
51
+ end
52
+
53
+ "#{light_magenta('Set: {')} #{formatted.join(light_magenta(' | '))} #{light_magenta('}')}" unless formatted.nil?
54
+ end
55
+
56
+ def too_long?(object, max_width:)
57
+ string = object.respond_to?(:join) ? object.join(' | ') : object
58
+ length_of(string) > max_width - 4
59
+ end
60
+
61
+ def formatted_elements(**options)
62
+ object.sort.each.lazy.map { |element| format_nested(element, **options) }
63
+ end
64
+
65
+ def trunc_message(count, all_truncated: false)
66
+ return if count < 1
67
+
68
+ light_black "(#{count} #{all_truncated ? 'elements' : 'more'})"
69
+ end
70
+
71
+ def object_size
72
+ @object_size ||= object.size
73
+ end
74
+
75
+ def force_inline?
76
+ level > 2
77
+ end
78
+ end
79
+ end
80
+ end
@@ -59,7 +59,7 @@ module Helium
59
59
 
60
60
  def rows
61
61
  @rows ||= case level
62
- when 1 then object.rows
62
+ when 1 then rows_limited_by(42)
63
63
  when 2 then rows_limited_by(10)
64
64
  else rows_limited_by(3)
65
65
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Helium
4
+ class Console
5
+ define_formatter_for Time do
6
+ def call
7
+ blue object.strftime('%A, %d %b %Y, %H:%M:%S')
8
+ end
9
+ end
10
+ end
11
+ end
@@ -68,6 +68,7 @@ module Helium
68
68
  def handler_for(object, **options)
69
69
  element_class = object.class.ancestors.find do |ancestor|
70
70
  break handlers[ancestor] if handlers.key?(ancestor)
71
+ break handlers[ancestor.name] if handlers.key?(ancestor.name)
71
72
  end
72
73
  return unless element_class
73
74
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Helium
4
4
  class Console
5
- VERSION = '0.1.9'
5
+ VERSION = '0.1.10'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: helium-console
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stanislaw Klajn
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-08-25 00:00:00.000000000 Z
11
+ date: 2021-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -67,14 +67,18 @@ files:
67
67
  - lib/helium/console/registry.rb
68
68
  - lib/helium/console/registry/array.rb
69
69
  - lib/helium/console/registry/booleans.rb
70
+ - lib/helium/console/registry/date.rb
70
71
  - lib/helium/console/registry/hash.rb
71
72
  - lib/helium/console/registry/module.rb
72
73
  - lib/helium/console/registry/nil.rb
73
74
  - lib/helium/console/registry/numeric.rb
74
75
  - lib/helium/console/registry/object.rb
76
+ - lib/helium/console/registry/pathname.rb
77
+ - lib/helium/console/registry/set.rb
75
78
  - lib/helium/console/registry/string.rb
76
79
  - lib/helium/console/registry/symbol.rb
77
80
  - lib/helium/console/registry/table.rb
81
+ - lib/helium/console/registry/time.rb
78
82
  - lib/helium/console/table.rb
79
83
  - lib/helium/console/version.rb
80
84
  homepage: https://github.com/helium-rb/console