libtad 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +7 -0
  2. data/lib/libtad.rb +123 -0
  3. data/lib/services/astronomy.rb +102 -0
  4. data/lib/services/date_calculator.rb +155 -0
  5. data/lib/services/holidays.rb +34 -0
  6. data/lib/services/onthisday.rb +42 -0
  7. data/lib/services/places.rb +26 -0
  8. data/lib/services/time.rb +143 -0
  9. data/lib/types/astronomy/astronomy_current.rb +58 -0
  10. data/lib/types/astronomy/astronomy_day.rb +32 -0
  11. data/lib/types/astronomy/astronomy_day_event.rb +76 -0
  12. data/lib/types/astronomy/astronomy_event.rb +24 -0
  13. data/lib/types/astronomy/astronomy_event_class.rb +37 -0
  14. data/lib/types/astronomy/astronomy_location.rb +31 -0
  15. data/lib/types/astronomy/astronomy_object.rb +27 -0
  16. data/lib/types/astronomy/astronomy_object_details.rb +32 -0
  17. data/lib/types/astronomy/astronomy_object_type.rb +36 -0
  18. data/lib/types/astronomy/moonphase.rb +37 -0
  19. data/lib/types/date_calculator/business_days_filter.rb +39 -0
  20. data/lib/types/date_calculator/business_holiday.rb +26 -0
  21. data/lib/types/date_calculator/period.rb +44 -0
  22. data/lib/types/date_calculator/weekdays.rb +54 -0
  23. data/lib/types/holidays/holiday.rb +93 -0
  24. data/lib/types/holidays/holiday_state.rb +35 -0
  25. data/lib/types/holidays/holiday_type.rb +107 -0
  26. data/lib/types/onthisday/event.rb +51 -0
  27. data/lib/types/onthisday/event_type.rb +15 -0
  28. data/lib/types/onthisday/name.rb +24 -0
  29. data/lib/types/onthisday/person.rb +39 -0
  30. data/lib/types/places/country.rb +20 -0
  31. data/lib/types/places/geo.rb +34 -0
  32. data/lib/types/places/location.rb +43 -0
  33. data/lib/types/places/location_ref.rb +24 -0
  34. data/lib/types/places/place.rb +24 -0
  35. data/lib/types/places/region.rb +35 -0
  36. data/lib/types/time/datetime.rb +93 -0
  37. data/lib/types/time/dst_entry.rb +48 -0
  38. data/lib/types/time/time.rb +30 -0
  39. data/lib/types/time/time_change.rb +49 -0
  40. data/lib/types/time/timezone.rb +51 -0
  41. metadata +137 -0
@@ -0,0 +1,32 @@
1
+ module LibTAD
2
+ module Astronomy
3
+ # Information about an astronomy object.
4
+ class AstronomyObjectDetails
5
+ # @return [String]
6
+ # Object name.
7
+ attr_reader :name
8
+
9
+ # @return [Array<AstronomyDay>]
10
+ # Lists and wraps all requested days where events are happening.
11
+ attr_reader :days
12
+
13
+ # @return [AstronomyCurrent]
14
+ # The current data for the object. Only if requested.
15
+ attr_reader :current
16
+
17
+ # @return [Array<AstronomyCurrent>]
18
+ # The specific data for the object at isotime/utctime.
19
+ attr_reader :results
20
+
21
+ def initialize(hash)
22
+ @name = hash.fetch('name', nil)
23
+ @days = hash.fetch('days', nil)
24
+ &.map { |e| AstronomyDay.new(e) }
25
+
26
+ @current = AstronomyCurrent.new hash['current'] unless !hash.key?('current')
27
+ @results = hash.fetch('results', nil)
28
+ &.map { |e| AstronomyCurrent.new(e) }
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,36 @@
1
+ module LibTAD
2
+ module Astronomy
3
+ # All valid astronomy object types.
4
+ ASTRONOMY_OBJECT_TYPE = [
5
+ # The sun.
6
+ :sun,
7
+
8
+ # The moon.
9
+ :moon,
10
+
11
+ # Mercury.
12
+ :mercury,
13
+
14
+ # Venus.
15
+ :venus,
16
+
17
+ # Mars.
18
+ :mars,
19
+
20
+ # Jupiter.
21
+ :jupiter,
22
+
23
+ # Saturn.
24
+ :saturn,
25
+
26
+ # Uranus.
27
+ :uranus,
28
+
29
+ # Neptune.
30
+ :neptune,
31
+
32
+ # Pluto.
33
+ :pluto
34
+ ].freeze
35
+ end
36
+ end
@@ -0,0 +1,37 @@
1
+ module LibTAD
2
+ module Astronomy
3
+ # Moon phase.
4
+ class MoonPhase
5
+ # @return [String]
6
+ # Moonphase id.
7
+ attr_reader :id
8
+
9
+ # @return [String]
10
+ # Moonphase description.
11
+ def description
12
+ case @id
13
+ when 'newmoon'
14
+ 'New moon'
15
+ when 'waxingcrescent'
16
+ 'Waxing crescent'
17
+ when 'firstquarter'
18
+ 'Moon in first quarter'
19
+ when 'waxinggibbous'
20
+ 'Waxing gibbous moon'
21
+ when 'fullmoon'
22
+ 'Full moon'
23
+ when 'waninggibbous'
24
+ 'Waning gibbous moon'
25
+ when 'thirdquarter'
26
+ 'Moon in third quarter'
27
+ when 'waningcrescent'
28
+ 'Waning crescent moon'
29
+ end
30
+ end
31
+
32
+ def initialize(id)
33
+ @id = id
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,39 @@
1
+ module LibTAD
2
+ module DateCalculator
3
+ # All valid business days filters.
4
+ BUSINESS_DAYS_FILTER = [
5
+ # Include or exclude Mondays.
6
+ :mon,
7
+
8
+ # Include or exclude Tuesdays.
9
+ :tue,
10
+
11
+ # Include or exclude Wednesdays.
12
+ :wed,
13
+
14
+ # Include or exclude Thursdays.
15
+ :thu,
16
+
17
+ # Include or exclude Fridays.
18
+ :fri,
19
+
20
+ # Include or exclude Saturdays.
21
+ :sat,
22
+
23
+ # Include or exclude Sundays.
24
+ :sun,
25
+
26
+ # Include or exclude weekends.
27
+ :weekend,
28
+
29
+ # Include or exclude holidays.
30
+ :holidays,
31
+
32
+ # Include or exclude weekends and holidays combined.
33
+ :weekendholidays,
34
+
35
+ # Include or exclude nothing.
36
+ :none
37
+ ].freeze
38
+ end
39
+ end
@@ -0,0 +1,26 @@
1
+ module LibTAD
2
+ module DateCalculator
3
+ # A holiday event which occurs in a requested period.
4
+ class BusinessHoliday
5
+ # @return [String]
6
+ # Either included or excluded, specifying whether or not the holidays
7
+ # in the result array were included or excluded when queried.
8
+ attr_reader :type
9
+
10
+ # @return [Integer]
11
+ # The number of holidays in the results.
12
+ attr_reader :count
13
+
14
+ # @return [Array<::LibTAD::Holiday::Holiday>]
15
+ # Holidays which occur in the requested period.
16
+ attr_reader :list
17
+
18
+ def initialize(hash)
19
+ @type = hash.fetch('type', nil)
20
+ @count = hash.fetch('count', nil)
21
+ @list = hash.fetch('list', nil)
22
+ &.map { |e| ::LibTAD::Holidays::Holiday.new(e) }
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,44 @@
1
+ module LibTAD
2
+ module DateCalculator
3
+ # Calculated results for a requested period.
4
+ class Period
5
+ # @return [Integer]
6
+ # Number of days calculated.
7
+ attr_reader :includeddays
8
+
9
+ # @return [Integer]
10
+ # Number of calendar days in calculated period.
11
+ attr_reader :calendardays
12
+
13
+ # @return [Integer]
14
+ # Number of days which was skipped in the calculated period.
15
+ attr_reader :skippeddays
16
+
17
+ # @return [::LibTAD::TADTime::TADTime]
18
+ # The date the calculation started from.
19
+ attr_reader :startdate
20
+
21
+ # @return [::LibTAD::TADTime::TADTime]
22
+ # The date the calculation ended on.
23
+ attr_reader :enddate
24
+
25
+ # @return [::LibTAD::DateCalculator::Weekdays]
26
+ # The spread of excluded or included weekdays in includeddays.
27
+ attr_reader :weekdays
28
+
29
+ # @return [::LibTAD::DateCalculator::BusinessHoliday]
30
+ # Holidays which occur in the requested period.
31
+ attr_reader :holidays
32
+
33
+ def initialize(hash)
34
+ @includeddays = hash.fetch('includeddays', nil)
35
+ @calendardays = hash.fetch('calendardays', nil)
36
+ @skippeddays = hash.fetch('skippeddays', nil)
37
+ @startdate = ::LibTAD::TADTime::TADTime.new hash['startdate'] unless !hash.key?('startdate')
38
+ @enddate = ::LibTAD::TADTime::TADTime.new hash['enddate'] unless !hash.key?('enddate')
39
+ @weekdays = ::LibTAD::DateCalculator::Weekdays.new hash['weekdays'] unless !hash.key?('weekdays')
40
+ @holidays = ::LibTAD::DateCalculator::BusinessHoliday.new hash['holidays'] unless !hash.key?('holidays')
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,54 @@
1
+ module LibTAD
2
+ module DateCalculator
3
+ # The spread of excluded or included weekdays.
4
+ class Weekdays
5
+ # @return [String]
6
+ # Specifies whether or not the weekdays counted were part of an included or excluded filter.
7
+ attr_reader :type
8
+
9
+ # @return [Integer]
10
+ # How many days in total have been counted.
11
+ attr_reader :count
12
+
13
+ # @return [Integer]
14
+ # Count for Mondays.
15
+ attr_reader :mon
16
+
17
+ # @return [Integer]
18
+ # Count for Tuesdays.
19
+ attr_reader :tue
20
+
21
+ # @return [Integer]
22
+ # Count for Wednesdays.
23
+ attr_reader :wed
24
+
25
+ # @return [Integer]
26
+ # Count for Thursdays.
27
+ attr_reader :thu
28
+
29
+ # @return [Integer]
30
+ # Count for Fridays.
31
+ attr_reader :fri
32
+
33
+ # @return [Integer]
34
+ # Count for Saturdays.
35
+ attr_reader :sat
36
+
37
+ # @return [Integer]
38
+ # Count for Sundays.
39
+ attr_reader :sun
40
+
41
+ def initialize(hash)
42
+ @type = hash.fetch('type', nil)
43
+ @count = hash.fetch('count', nil)
44
+ @mon = hash.fetch('mon', nil)
45
+ @tue = hash.fetch('tue', nil)
46
+ @wed = hash.fetch('wed', nil)
47
+ @thu = hash.fetch('thu', nil)
48
+ @fri = hash.fetch('fri', nil)
49
+ @sat = hash.fetch('sat', nil)
50
+ @sun = hash.fetch('sun', nil)
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,93 @@
1
+ module LibTAD
2
+ module Holidays
3
+ # A holiday event.
4
+ class Holiday
5
+ # @return [Integer]
6
+ # Identifier for the holiday definition. Please note that this id
7
+ # is not unique, not even with a single year – the same holiday
8
+ # event may be returned multiple time because it is observed on a
9
+ # different day, or because it is scheduled in a different calendar
10
+ # (Hebrew or Muslim calendar) and happens multiple times within a
11
+ # Gregorian year. Use the uid attribute for purposes where you need a
12
+ # unique identifier.
13
+ attr_reader :id
14
+
15
+ # @return [String]
16
+ # Id for the shown holiday instance. The id is designed to be unique
17
+ # across all holiday instances generated by the timeanddate.com API
18
+ # services and respects different calendars and other reasons that
19
+ # may cause events to occurs multiple times within one Gregorian year.
20
+ #
21
+ # Example: 0007d600000007db
22
+ attr_reader :uid
23
+
24
+ # @return [Hash<String, String>]
25
+ # Hash of languages with corresponding holiday/observance name.
26
+ attr_reader :name
27
+
28
+ # @return [::LibTAD::TADTime::TADTime]
29
+ # Date/time of the holiday instance. Most holidays do have a specific
30
+ # time – in this case the time components will be skipped. Some
31
+ # special events like equinoxes and solstices include the exact time
32
+ # of the event as well, in this case the timestamp will be in local
33
+ # time zone (including time zone data) (countries with multiple
34
+ # timezones: local time in capital city).
35
+ attr_reader :date
36
+
37
+ # @return [String]
38
+ # Further information about the specific holiday. The URL points to
39
+ # the timeanddate.com web page.
40
+ #
41
+ # Example: http://www.timeanddate.com/holidays/us/new-year-day
42
+ attr_reader :url
43
+
44
+ # @return [::LibTAD::Models::Country]
45
+ # Country of the holiday instance.
46
+ attr_reader :country
47
+
48
+ # @return [String]
49
+ # Summary of locations where this holiday instance is valid. Element is
50
+ # only present if the holiday instance does not affect the whole country.
51
+ attr_reader :locations
52
+
53
+ # @return [Array<HolidayState>]
54
+ # States/subdivisions that are affected by this holiday instance. This
55
+ # element is only present if the holiday instance is not valid in the
56
+ # whole country.
57
+ attr_reader :states
58
+
59
+ # @return [Hash<String, String>]
60
+ # Languages with corresponding holiday description.
61
+ attr_reader :oneliner
62
+
63
+ # @return [Array<String>]
64
+ # Classification of the holiday. Most days have only one classification,
65
+ # but some have multiple types associated. This happens e.g. in
66
+ # conjunction with religious days that also are flag days.
67
+ #
68
+ # Example: National Holiday
69
+ attr_reader :types
70
+
71
+ def initialize(hash)
72
+ @id = hash.fetch('id', nil)
73
+ @uid = hash.fetch('uid', nil)
74
+ @name = hash.fetch('name', nil)
75
+ &.map { |e| [ e['lang'], e['text'] ] }
76
+ .to_h
77
+
78
+ @date = ::LibTAD::TADTime::TADTime.new hash.fetch('date', nil)
79
+ @url = hash.fetch('url', nil)
80
+ @country = ::LibTAD::Places::Country.new hash['country'] unless !hash.key?('country')
81
+ @locations = hash.fetch('locations', nil)
82
+ @states = hash.fetch('states', nil)
83
+ &.map { |e| HolidayState.new(e) }
84
+
85
+ @oneliner = hash.fetch('oneliner', nil)
86
+ &.map { |e| [ e['lang'], e['text'] ] }
87
+ .to_h
88
+
89
+ @types = hash.fetch('types', nil)
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,35 @@
1
+ module LibTAD
2
+ module Holidays
3
+ # A holiday event in a specific state.
4
+ class HolidayState
5
+ # @return [String]
6
+ # An ISO 3166-1 country or ISO 3166-2 country state code.
7
+ # @see https://dev-test.timeanddate.com/docs/external-references#ISO3166 ISO3166
8
+ attr_reader :iso
9
+
10
+ # @return [Integer]
11
+ # Unique id of the state/subdivision.
12
+ attr_reader :id
13
+
14
+ # @return [String]
15
+ # Abbreviation of the state/subdivision.
16
+ attr_reader :abbrev
17
+
18
+ # @return [String]
19
+ # Common name of the state/subdivision.
20
+ attr_reader :name
21
+
22
+ # @return [String]
23
+ # Eventual exception if the holiday does not affect the whole state/subdivision.
24
+ attr_reader :exception
25
+
26
+ def initialize(hash)
27
+ @iso = hash.fetch('iso', nil)
28
+ @id = hash.fetch('id', nil)
29
+ @abbrev = hash.fetch('abbrev', nil)
30
+ @name = hash.fetch('name', nil)
31
+ @exception = hash.fetch('exception', nil)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,107 @@
1
+ module LibTAD
2
+ module Holidays
3
+ # All valid holiday types
4
+ HOLIDAY_TYPE = [
5
+ # Combinations of all known types (except fun).
6
+ :all,
7
+
8
+ # Default holiday set: federal, federallocal, obs1, weekday.
9
+ :default,
10
+
11
+ # Default set depending on country.
12
+ # For most countries, this is the same as default. However,
13
+ # for some countries it makes sense to add further types – this type
14
+ # accounts for this case. Currently this only affects the UK:
15
+ # local holidays are added as well. This is to include days that
16
+ # are only valid in one of countries – e.g. Jan 2 is a holiday only for Scotland.
17
+ :countrydefault,
18
+
19
+ # Important (obs1), common (obs2) and other observances (obs3).
20
+ :obs,
21
+
22
+ # All religious holidays: buddhism, christian, hebrew, hinduism, muslim, orthodox.
23
+ :religious,
24
+
25
+ # Some countries (e.g. Sweden) have days which are de facto treted as official holidays, even if there's no legal regulation.
26
+ :defacto,
27
+
28
+ # Federal/national holidays.
29
+ :federal,
30
+
31
+ # Common local holidays.
32
+ :federallocal,
33
+
34
+ # Flag days.
35
+ :flagday,
36
+
37
+ # Half day holidays (only afternoon off). These days can be half day holidays either by law, or being de facto half day holidays (e.g. Sweden).
38
+ :halfday,
39
+
40
+ # Local holidays.
41
+ :local,
42
+
43
+ # Local observances.
44
+ :local2,
45
+
46
+ # Important observances.
47
+ :obs1,
48
+
49
+ # Common observances.
50
+ :obs2,
51
+
52
+ # Other observances
53
+ :obs3,
54
+
55
+ # Optional holiday.
56
+ # Employment and holiday laws in certain countries allow employees to choose a
57
+ # limited number of holidays from a list of holidays. Some employees may
58
+ # choose to take the day off on these day, however, most offices and businesses remain open.
59
+ :optional,
60
+
61
+ # Normal working days.
62
+ # In some cases, working days are declared non-working days
63
+ # in order to form a longer period of consecutive non-working days.
64
+ # In exchange, weekend days become normal working days.
65
+ :weekday,
66
+
67
+ # Buddhist holidays.
68
+ :buddhism,
69
+
70
+ # Christian holidays.
71
+ :christian,
72
+
73
+ # Hebrew holidays.
74
+ :hebrew,
75
+
76
+ # Hindu holidays.
77
+ :hinduism,
78
+
79
+ # Muslim holidays.
80
+ :muslim,
81
+
82
+ # Orthodox holidays.
83
+ :orthodox,
84
+
85
+ # Religious holidays, not covered by other types.
86
+ :otherreligion,
87
+
88
+ # Seasons (equinoxes and solstices).
89
+ :seasons,
90
+
91
+ # Sport events.
92
+ :sport,
93
+
94
+ # Time zone events – daylight savings time start and end.
95
+ :tz,
96
+
97
+ # United Nations days.
98
+ :un,
99
+
100
+ # Worldwide observances.
101
+ :world,
102
+
103
+ # Fun, Wacky and Trivial holidays.
104
+ :fun,
105
+ ].freeze
106
+ end
107
+ end