holiday_co 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 54948857733519963c3d42cdf2bf4e81d71ac72388f144650717d57adfeffc4f
4
+ data.tar.gz: 7231619889a4d1f88d014be6eae490aaa417fef4bd092c79b10c21993c595ef1
5
+ SHA512:
6
+ metadata.gz: 84f6c942bc60bb0752b7ddfb8b5d8b421b1254b3cb4efbb34921798a4435bd21e65d624fae4498227500cf7977d1c10cda53b6b0a51b5b050c439da6cbe461cb
7
+ data.tar.gz: d311a1ea85b85ad43b099c56b771a0926cfeadf5f59c2f1e957461d0fef6098b4051ed8bf3be9d0b362c1816b99f8aab9dd85fbf59e388356b92b5d3a7d07390
data/data/years.yml ADDED
@@ -0,0 +1,4 @@
1
+ # List any new supported year here (in addition to adding the .yml in years)
2
+
3
+ - 2023
4
+ - 2024
@@ -0,0 +1,22 @@
1
+ require "date"
2
+ require_relative "year"
3
+
4
+ module HolidayCo
5
+ class Day
6
+ attr_reader :date
7
+
8
+ def initialize(date)
9
+ @date = date.to_s
10
+ end
11
+
12
+ def holiday?
13
+ holiday_dates.include?(date)
14
+ end
15
+
16
+ private
17
+
18
+ def holiday_dates
19
+ Year.new(Date.parse(date).year).holiday_dates
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "yaml"
4
+
5
+ module HolidayCo
6
+ class YearDataNotAvailableError < StandardError
7
+ def message
8
+ "There is no data file available for the specified year (yet)."
9
+ end
10
+ end
11
+
12
+ class Year
13
+ attr_reader :year
14
+
15
+ def initialize(year)
16
+ @year = year.to_s
17
+ end
18
+
19
+ def holidays
20
+ raise YearDataNotAvailableError unless year_data_available?
21
+
22
+ YAML
23
+ .load_file(File.expand_path("../../../../data/years/#{year}.yml", __FILE__))
24
+ .fetch("holidays", [])
25
+ .map { |h| h.transform_keys(&:to_sym) }
26
+ end
27
+
28
+ def holiday_names
29
+ holidays.map { |h| h[:name] }
30
+ end
31
+
32
+ def holiday_dates
33
+ holidays.map { |h| h[:date] }
34
+ end
35
+
36
+ private
37
+
38
+ def year_data_available?
39
+ available_years.include?(year)
40
+ end
41
+
42
+ def available_years
43
+ YAML
44
+ .load_file(File.expand_path("../../../../data/years.yml", __FILE__))
45
+ .map(&:to_s)
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,18 @@
1
+ require "date"
2
+
3
+ module HolidayCo
4
+ # Colombian time zone is 5 hours behind UTC.
5
+ UTC_OFFSET = "-05:00".freeze
6
+
7
+ def self.current_time
8
+ Time.now.getlocal(UTC_OFFSET)
9
+ end
10
+
11
+ def self.current_year
12
+ current_time.year
13
+ end
14
+
15
+ def self.current_date
16
+ current_time.to_date
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ module HolidayCo
2
+ VERSION = "0.1.0"
3
+ end
data/lib/holiday_co.rb ADDED
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "holiday_co/utils"
4
+ require_relative "holiday_co/version"
5
+ require_relative "holiday_co/models/day"
6
+ require_relative "holiday_co/models/year"
7
+
8
+ module HolidayCo
9
+ class << self
10
+ def is_holiday?(date = current_date)
11
+ Day.new(date).holiday?
12
+ end
13
+
14
+ def holidays(year = current_year)
15
+ Year.new(year).holidays
16
+ end
17
+
18
+ def holidays_names(year = current_year)
19
+ Year.new(year).holiday_names
20
+ end
21
+
22
+ def holidays_dates(year = current_year)
23
+ Year.new(year).holiday_dates
24
+ end
25
+ end
26
+ end
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: holiday_co
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Gabriel Coronado
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-09-08 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A simple gem to handle holidays in Colombia
14
+ email:
15
+ - gabrielomar2809@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - data/years.yml
21
+ - lib/holiday_co.rb
22
+ - lib/holiday_co/models/day.rb
23
+ - lib/holiday_co/models/year.rb
24
+ - lib/holiday_co/utils.rb
25
+ - lib/holiday_co/version.rb
26
+ homepage: https://github.com/gabo-cs/holiday_co
27
+ licenses:
28
+ - MIT
29
+ metadata: {}
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubygems_version: 3.2.33
46
+ signing_key:
47
+ specification_version: 4
48
+ summary: Colombian Holidays
49
+ test_files: []