smt 0.2.0 → 0.2.5

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: ecf7aa29986f62a7cd6aa32b27cbe12c9b20b5017fe6180172a9d67696baf3bd
4
- data.tar.gz: ba0ae7b542f03f3f6f8a976c45a917bda22c5c376c7fba17a563efb46ab7d0a9
3
+ metadata.gz: a860d33e3b1c1d71c485ac2b0707880d9f012464f3eae9d162630782ab78fe70
4
+ data.tar.gz: 2a3aaf74e8ab1105e7a88433a59f55adaa51dc0b37e70adf6fabd808479afa85
5
5
  SHA512:
6
- metadata.gz: d6d539fb81d2dff4826d739291249aea6ef8f7277853e8162014d589fb2d984ba0ef02337fbd8f927f3f2bf9734290783ac697772eecb8d69a0479281b380fb4
7
- data.tar.gz: 0de688a31227832bc2dfc44c7ee1755e7a58f66802d79f2e9d754b7a3217270ac912126cd625c7dd24fa5b7346dfeb11bd8bc01b0a9ebf1d1b8ac4ffc3cb6561
6
+ metadata.gz: c81bf6ec9939df418cf481818b46a8bc73fa71fc149ba2020db66292df5a1271357576b6c46c9ed9ba4e5fe353cc3b695099ed670c2e93a64c3505143e3354bb
7
+ data.tar.gz: 4946242d36d6be9b3aa28b19b399ffe64ccfc1982ec973b2ef87f6e9008b8f64fdf862208b6d68212c03c683c314a27ebe977aa6ec9f2c7124491ac42a95e3f8
data/exe/smt CHANGED
@@ -9,16 +9,21 @@ require "smt"
9
9
 
10
10
  @input, @format = *Smt::Options.new.parse!
11
11
 
12
- @format ||= "%Y-%m-%d %H:%M:%S"
12
+ @format ||= Smt::DEFAULT_FORMAT
13
13
 
14
14
  config = Smt::Config.load
15
15
 
16
- time = @input ? Time.parse(@input) : Time.current
16
+ time = if @input
17
+ begin
18
+ Time.parse(@input)
19
+ rescue ArgumentError
20
+ warn "Error: invalid time format '#{@input}'"
21
+ exit 1
22
+ end
23
+ else
24
+ Time.current
25
+ end
17
26
 
18
27
  return unless config
19
28
 
20
- max_length = config.map { |entry| entry[:label].length }.max
21
-
22
- config.each do |entry|
23
- Smt::Display.show(entry, @format, max_length, time)
24
- end
29
+ Smt::Display.table(entries: config, format: @format, time: time)
data/lib/smt/config.rb CHANGED
@@ -1,9 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "yaml"
4
+
3
5
  module Smt
4
6
  class Config
7
+ CONFIG_PATH = File.join(Dir.home, ".smtrc.yml").freeze
8
+
5
9
  def self.load
6
- File.exist?("#{Dir.home}/.smtrc.yml") && YAML.load_file("#{Dir.home}/.smtrc.yml")
10
+ return unless File.exist?(CONFIG_PATH)
11
+
12
+ YAML.safe_load_file(CONFIG_PATH, permitted_classes: [Symbol], symbolize_names: true)
7
13
  end
8
14
  end
9
15
  end
data/lib/smt/display.rb CHANGED
@@ -2,12 +2,54 @@
2
2
 
3
3
  module Smt
4
4
  class Display
5
- def self.show(entry, format, max_length, time)
6
- time_display = time.in_time_zone(entry[:time_zone]).strftime(format)
7
- formatted_time_zone = time.strftime(entry[:label]).rjust(max_length)
8
- formatted_time_display = time_display
5
+ BOX = {
6
+ tl: "┌", tr: "┐", bl: "└", br: "┘",
7
+ h: "─", v: "│",
8
+ lm: "├", rm: "┤", tm: "┬", bm: "┴", cross: "┼"
9
+ }.freeze
9
10
 
10
- puts "#{formatted_time_zone} #{formatted_time_display}".colorize(entry[:color].to_sym)
11
+ def self.table(entries:, format:, time:)
12
+ rows = entries.map do |entry|
13
+ {
14
+ emoji: entry[:emoji],
15
+ label: time.strftime(entry[:label]),
16
+ time: time.in_time_zone(entry[:time_zone]).strftime(format),
17
+ color: entry[:color].to_sym
18
+ }
19
+ end
20
+
21
+ emoji_w = 2
22
+ label_w = rows.map { |r| r[:label].length }.max
23
+ time_w = rows.map { |r| r[:time].length }.max
24
+
25
+ puts top_border(emoji_w, label_w, time_w)
26
+ rows.each_with_index do |row, i|
27
+ puts row_line(row, emoji_w, label_w, time_w)
28
+ puts mid_border(emoji_w, label_w, time_w) unless i == rows.length - 1
29
+ end
30
+ puts bottom_border(emoji_w, label_w, time_w)
31
+ end
32
+
33
+ def self.top_border(ew, lw, tw)
34
+ "#{BOX[:tl]}#{BOX[:h] * (ew + 2)}#{BOX[:tm]}#{BOX[:h] * (lw + 2)}#{BOX[:tm]}#{BOX[:h] * (tw + 2)}#{BOX[:tr]}"
35
+ end
36
+
37
+ def self.mid_border(ew, lw, tw)
38
+ "#{BOX[:lm]}#{BOX[:h] * (ew + 2)}#{BOX[:cross]}#{BOX[:h] * (lw + 2)}#{BOX[:cross]}#{BOX[:h] * (tw + 2)}#{BOX[:rm]}"
11
39
  end
40
+
41
+ def self.bottom_border(ew, lw, tw)
42
+ "#{BOX[:bl]}#{BOX[:h] * (ew + 2)}#{BOX[:bm]}#{BOX[:h] * (lw + 2)}#{BOX[:bm]}#{BOX[:h] * (tw + 2)}#{BOX[:br]}"
43
+ end
44
+
45
+ def self.row_line(row, ew, lw, tw)
46
+ emoji_cell = row[:emoji] ? " #{row[:emoji]} " : " " * (ew + 2)
47
+ label_cell = " #{row[:label].ljust(lw)} "
48
+ time_cell = " #{row[:time].ljust(tw)} "
49
+
50
+ "#{BOX[:v]}#{emoji_cell}#{BOX[:v]}#{label_cell.colorize(row[:color])}#{BOX[:v]}#{time_cell.colorize(row[:color])}#{BOX[:v]}"
51
+ end
52
+
53
+ private_class_method :top_border, :mid_border, :bottom_border, :row_line
12
54
  end
13
55
  end
data/lib/smt/options.rb CHANGED
@@ -35,6 +35,13 @@ module Smt
35
35
  end
36
36
  end
37
37
 
38
+ def version_opts(opts)
39
+ opts.on("-v", "--version", "Show version") do
40
+ puts Smt::VERSION
41
+ exit
42
+ end
43
+ end
44
+
38
45
  def for_parse
39
46
  parser = OptionParser.new do |opts|
40
47
  opts.banner = "Usage: smt [options]"
@@ -43,6 +50,7 @@ module Smt
43
50
  time_opts(opts)
44
51
  format_opts(opts)
45
52
  list_opts(opts)
53
+ version_opts(opts)
46
54
  end
47
55
 
48
56
  {
data/lib/smt/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Smt
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.5"
5
5
  end
data/lib/smt.rb CHANGED
@@ -7,5 +7,6 @@ require_relative "smt/display"
7
7
 
8
8
  module Smt
9
9
  class Error < StandardError; end
10
- # Your code goes here...
10
+
11
+ DEFAULT_FORMAT = "%Y-%m-%d %H:%M:%S"
11
12
  end
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Ladachowski
8
+ autorequire:
8
9
  bindir: exe
9
10
  cert_chain: []
10
- date: 1980-01-02 00:00:00.000000000 Z
11
+ date: 2026-02-03 00:00:00.000000000 Z
11
12
  dependencies:
12
13
  - !ruby/object:Gem::Dependency
13
14
  name: activesupport
@@ -121,6 +122,7 @@ metadata:
121
122
  homepage_uri: https://github.com/aladac/smt
122
123
  source_code_uri: https://github.com/aladac/smt
123
124
  changelog_uri: https://github.com/aladac/smt
125
+ post_install_message:
124
126
  rdoc_options: []
125
127
  require_paths:
126
128
  - lib
@@ -135,7 +137,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
137
  - !ruby/object:Gem::Version
136
138
  version: '0'
137
139
  requirements: []
138
- rubygems_version: 3.6.7
140
+ rubygems_version: 3.5.22
141
+ signing_key:
139
142
  specification_version: 4
140
143
  summary: Shows time in multiple timezones
141
144
  test_files: []