smt 0.1.2 → 0.2.4

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: 524d8bcd8769fa265493ad7563b715577bb5abc8091bfc81e86da405ef196d2a
4
- data.tar.gz: cabb8b09f93228c049e195abec578f1afaa59a40c0bffa92d0aaf45b1641df64
3
+ metadata.gz: aa3c806fef6492b4843010597720a1673857b670454476f57e5ded22f4437db7
4
+ data.tar.gz: ffe25ac7cd3dd11d2065262625e86257c98f683197ed1f6b4a421d189b475e43
5
5
  SHA512:
6
- metadata.gz: fc05b3883d1a98ea5fb40501548664466328a267aea14ca239d3d8d0eaf16e96cc7b23a27049ded2aded22d90acf175b496bbffc341fc691ccf4f0b94c6f64f9
7
- data.tar.gz: 5a7627d7f97328630723fb589b1600496adfde8c4d325c80ce21e89125f7ceb9f4ed1a66ea74137bcdf3bf85da429da9d5377b168e654a9fdef948387b2f821a
6
+ metadata.gz: 3279a60d1292ad11ddcbb6460046a3b6996b52792d8a0cffb9b7143935311559bd5d1c5a223169d83b228bc68d4b535cdfbfd3206208ee5107383207bd010eeb
7
+ data.tar.gz: 2b3f4c176544dc832f5d59df94428be9153efb1366f894b56e4f5d475dfc425b04320cda3572b87438d65c85bb4f3d6a66700c19f74ce97a9667488b14455002
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # Smt
2
+ [![Ruby](https://github.com/aladac/smt/actions/workflows/main.yml/badge.svg)](https://github.com/aladac/smt/actions/workflows/main.yml)
2
3
 
3
4
  TODO: Delete this and the text below, and describe your gem
4
5
 
data/Rakefile CHANGED
@@ -1,12 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'bundler/gem_tasks'
4
- require 'rspec/core/rake_task'
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
5
 
6
6
  RSpec::Core::RakeTask.new(:spec)
7
7
 
8
- require 'rubocop/rake_task'
9
-
10
- RuboCop::RakeTask.new
11
-
12
- task default: %i[spec rubocop]
8
+ task default: %i[spec]
data/exe/smt CHANGED
@@ -1,24 +1,29 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'active_support/all'
5
- require 'bundler'
6
- require 'colorize'
7
- require 'optparse'
8
- require 'smt'
4
+ require "active_support/all"
5
+ require "bundler"
6
+ require "colorize"
7
+ require "optparse"
8
+ 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[:time_zone].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[:time_zone]).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
@@ -6,42 +6,51 @@ module Smt
6
6
  Usage: smt [options]
7
7
  BANNER
8
8
 
9
- def initialize; end
9
+ def initialize
10
+ end
10
11
 
11
12
  def time_opts(opts)
12
- opts.on('-t', '--time TIME', 'Time to convert') do |time|
13
+ opts.on("-t", "--time TIME", "Time to convert") do |time|
13
14
  @input = time
14
15
  end
15
16
  end
16
17
 
17
18
  def format_opts(opts)
18
- opts.on('-f', '--format FORMAT', 'Time format') do |fmt|
19
+ opts.on("-f", "--format FORMAT", "Time format") do |fmt|
19
20
  @format = fmt
20
21
  end
21
22
  end
22
23
 
23
24
  def help_opts(opts)
24
- opts.on('-h', '--help', 'Display this screen') do
25
+ opts.on("-h", "--help", "Display this screen") do
25
26
  puts opts
26
27
  exit
27
28
  end
28
29
  end
29
30
 
30
31
  def list_opts(opts)
31
- opts.on('-l', '--list', 'List all timezones') do
32
+ opts.on("-l", "--list", "List all timezones") do
32
33
  puts ActiveSupport::TimeZone.all.map(&:name)
33
34
  exit
34
35
  end
35
36
  end
36
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
+
37
45
  def for_parse
38
46
  parser = OptionParser.new do |opts|
39
- opts.banner = 'Usage: smt [options]'
47
+ opts.banner = "Usage: smt [options]"
40
48
 
41
49
  help_opts(opts)
42
50
  time_opts(opts)
43
51
  format_opts(opts)
44
52
  list_opts(opts)
53
+ version_opts(opts)
45
54
  end
46
55
 
47
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.1.2'
4
+ VERSION = "0.2.4"
5
5
  end
data/lib/smt.rb CHANGED
@@ -1,11 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'smt/version'
4
- require_relative 'smt/config'
5
- require_relative 'smt/options'
6
- require_relative 'smt/display'
3
+ require_relative "smt/version"
4
+ require_relative "smt/config"
5
+ require_relative "smt/options"
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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Ladachowski
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-06-25 00:00:00.000000000 Z
11
+ date: 2026-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -67,19 +67,19 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: 3.13.0
69
69
  - !ruby/object:Gem::Dependency
70
- name: rubocop
70
+ name: standard
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 1.64.1
75
+ version: 1.39.0
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 1.64.1
82
+ version: 1.39.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: simplecov
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -103,7 +103,6 @@ extensions: []
103
103
  extra_rdoc_files: []
104
104
  files:
105
105
  - ".rspec"
106
- - ".rubocop.yml"
107
106
  - CHANGELOG.md
108
107
  - CODE_OF_CONDUCT.md
109
108
  - LICENSE.txt
@@ -138,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
137
  - !ruby/object:Gem::Version
139
138
  version: '0'
140
139
  requirements: []
141
- rubygems_version: 3.5.11
140
+ rubygems_version: 3.5.22
142
141
  signing_key:
143
142
  specification_version: 4
144
143
  summary: Shows time in multiple timezones
data/.rubocop.yml DELETED
@@ -1,6 +0,0 @@
1
- AllCops:
2
- TargetRubyVersion: 3.0
3
-
4
- Style/Documentation:
5
- Enabled: false
6
-