miti 0.1.0 → 1.0.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 +4 -4
- data/CHANGELOG.md +6 -1
- data/Gemfile +2 -0
- data/exe/miti +8 -0
- data/lib/cli.rb +54 -0
- data/lib/miti/version.rb +1 -1
- data/lib/miti.rb +28 -0
- data/miti.gemspec +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44383837579fa3f0fbca4203616117938adfcc02a39d383d448ec5a8d8fc3a6b
|
4
|
+
data.tar.gz: 9f9b9415bd30a4cb3c7007bf531f04f44173a2cd1a28afa901431f69026880d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8436ce93a8ba9b3fe57387ec6c6e240b821665e37a052dadf6ae87bfbfd477a7a5c2c37a1fbb351a7e13e5db900d684ae5c0a91124631e9f4bef3e4f8aaa63ed
|
7
|
+
data.tar.gz: 2c4efc488ab171d0765c78f65707ea66296a8affa5f39564747f0835d448717845b27676168b84152c91cb89035b8d04ab1dbef51c5531470dec191b2704d978
|
data/CHANGELOG.md
CHANGED
@@ -7,4 +7,9 @@
|
|
7
7
|
## [0.1.0] - 2023-05-21
|
8
8
|
- Change Class method to constant for fetching date. Add corresponding date for Baisakh 1 and Jan 1.
|
9
9
|
- Simplify logic for AD to BS conversion
|
10
|
-
- Refactor and add comments
|
10
|
+
- Refactor and add comments
|
11
|
+
|
12
|
+
## [1.0.0] - 2023-06-27
|
13
|
+
- New release 1.0.0
|
14
|
+
- Integrate Miti CLI
|
15
|
+
- Miti CLI now accepts arguments for date conversion
|
data/Gemfile
CHANGED
data/exe/miti
ADDED
data/lib/cli.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "thor"
|
4
|
+
require "date"
|
5
|
+
require_relative "miti"
|
6
|
+
|
7
|
+
module Miti
|
8
|
+
# class to integrate CLI
|
9
|
+
class CLI < Thor
|
10
|
+
def initialize(*args)
|
11
|
+
super
|
12
|
+
@shell = Thor::Shell::Color.new
|
13
|
+
@output_color = :green
|
14
|
+
end
|
15
|
+
|
16
|
+
desc "today", "today's nepali miti"
|
17
|
+
def today
|
18
|
+
date = Date.today
|
19
|
+
current_nepali_miti = Miti.to_bs(date.to_s)
|
20
|
+
formatted_miti = "[#{current_nepali_miti} BS] #{current_nepali_miti.descriptive}"
|
21
|
+
formatted_date = "[#{date} AD] " + date.strftime("%B %d, %Y %A")
|
22
|
+
|
23
|
+
@shell.say("#{formatted_miti}\n#{formatted_date}", :green)
|
24
|
+
end
|
25
|
+
|
26
|
+
desc "on ENGLISH_DATE", "converts english date to nepali miti"
|
27
|
+
def to_bs(english_date)
|
28
|
+
converted_nepali_miti = Miti.to_bs(english_date)
|
29
|
+
output_txt = "[#{converted_nepali_miti} BS] #{converted_nepali_miti.descriptive}"
|
30
|
+
rescue ConversionUnavailableError => e
|
31
|
+
output_txt = e
|
32
|
+
@output_color = :red
|
33
|
+
ensure
|
34
|
+
@shell.say(output_txt, @output_color)
|
35
|
+
end
|
36
|
+
|
37
|
+
desc "to NEPALI_DATE", "converts nepali miti to english date"
|
38
|
+
def to_ad(nepali_date)
|
39
|
+
converted_english_date = Miti.to_ad(nepali_date)
|
40
|
+
output_txt = "[#{converted_english_date} AD] #{converted_english_date.strftime("%B %d, %Y %A")}"
|
41
|
+
rescue ConversionUnavailableError => e
|
42
|
+
output_txt = e
|
43
|
+
@output_color = :red
|
44
|
+
ensure
|
45
|
+
@shell.say(output_txt, @output_color)
|
46
|
+
end
|
47
|
+
|
48
|
+
no_commands do
|
49
|
+
def self.exit_on_failure?
|
50
|
+
true
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/miti/version.rb
CHANGED
data/lib/miti.rb
CHANGED
@@ -9,6 +9,7 @@ require_relative "miti/data/date_data"
|
|
9
9
|
# Base module for the gem
|
10
10
|
module Miti
|
11
11
|
class Error < StandardError; end
|
12
|
+
class ConversionUnavailableError < StandardError; end
|
12
13
|
|
13
14
|
class << self
|
14
15
|
##
|
@@ -16,6 +17,8 @@ module Miti
|
|
16
17
|
# @param english_date [String], refers to date in string format
|
17
18
|
# @return [<Miti::NepaliDate>], refers to the converted nepali date
|
18
19
|
def to_bs(english_date)
|
20
|
+
validate_date_range(date: english_date, conversion: :to_bs)
|
21
|
+
|
19
22
|
date = parse_english_date(english_date)
|
20
23
|
Miti::AdToBs.new(date).convert
|
21
24
|
rescue Date::Error
|
@@ -27,12 +30,37 @@ module Miti
|
|
27
30
|
# @param nepali_date [String], refers to date in string format
|
28
31
|
# @return [<Date>], refers to the converted english date from nepali date
|
29
32
|
def to_ad(nepali_date)
|
33
|
+
validate_date_range(date: nepali_date, conversion: :to_ad)
|
34
|
+
|
30
35
|
date = parse_nepali_date(nepali_date)
|
31
36
|
Miti::BsToAd.new(date).convert
|
32
37
|
end
|
33
38
|
|
34
39
|
private
|
35
40
|
|
41
|
+
##
|
42
|
+
# This method throws an exception if the conversion is not available
|
43
|
+
# for both BS and AD
|
44
|
+
# - For AD to BS conversion max conversion is supported upto 2044 AD
|
45
|
+
# - For BS to AD conversion max conversion is supported upto 2100 BS
|
46
|
+
# @param date [String], refers to date in string format '20XX-XX-XX'
|
47
|
+
# @param conversion, [Symbol], refers to the conversion either :to_ad or :to_bs
|
48
|
+
#
|
49
|
+
# @return ConversionUnavailableError
|
50
|
+
|
51
|
+
def validate_date_range(date:, conversion:)
|
52
|
+
max_conversion_year, min_conversion_year, date_format = if conversion == :to_bs
|
53
|
+
[2044, 1919, :AD]
|
54
|
+
else
|
55
|
+
[2100, 1975, :BS]
|
56
|
+
end
|
57
|
+
year_value = date.split("-")[0].to_i
|
58
|
+
return if year_value.between?(min_conversion_year, max_conversion_year)
|
59
|
+
|
60
|
+
raise ConversionUnavailableError,
|
61
|
+
"Conversion only available for #{min_conversion_year}-#{max_conversion_year} #{date_format}"
|
62
|
+
end
|
63
|
+
|
36
64
|
##
|
37
65
|
# This method parses the provided parameter english date to Date object
|
38
66
|
# It checks the class of the parameter and returns the Date object accordingly
|
data/miti.gemspec
CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
|
|
26
26
|
"miti.gemspec", ".github/*.md",
|
27
27
|
"Gemfile", "Rakefile"]
|
28
28
|
spec.bindir = "exe"
|
29
|
-
spec.executables =
|
29
|
+
spec.executables = ["miti"]
|
30
30
|
spec.require_paths = ["lib"]
|
31
31
|
spec.license = "MIT"
|
32
32
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: miti
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- xkshitizx
|
@@ -9,13 +9,14 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-06-
|
12
|
+
date: 2023-06-26 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Convert English date(AD) to Nepali date(BS) and vice-versa.
|
15
15
|
email:
|
16
16
|
- kshitizlama03@gmail.com
|
17
17
|
- sanzaymanandhar99@gmail.com
|
18
|
-
executables:
|
18
|
+
executables:
|
19
|
+
- miti
|
19
20
|
extensions: []
|
20
21
|
extra_rdoc_files: []
|
21
22
|
files:
|
@@ -24,6 +25,8 @@ files:
|
|
24
25
|
- LICENSE
|
25
26
|
- README.md
|
26
27
|
- Rakefile
|
28
|
+
- exe/miti
|
29
|
+
- lib/cli.rb
|
27
30
|
- lib/miti.rb
|
28
31
|
- lib/miti/ad_to_bs.rb
|
29
32
|
- lib/miti/bs_to_ad.rb
|