more_holiday 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.rspec +3 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +68 -0
- data/LICENSE.txt +21 -0
- data/README.md +71 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/circle.yml +6 -0
- data/lib/more_holiday.rb +5 -0
- data/lib/more_holiday/cache/file.rb +65 -0
- data/lib/more_holiday/calculator.rb +76 -0
- data/lib/more_holiday/connector.rb +87 -0
- data/lib/more_holiday/connectors/ifeiertage/api.rb +26 -0
- data/lib/more_holiday/connectors/ifeiertage/connect.rb +54 -0
- data/lib/more_holiday/connectors/ifeiertage/ifeiertage.rb +8 -0
- data/lib/more_holiday/connectors/ifeiertage/source.rb +5 -0
- data/lib/more_holiday/exporter.rb +37 -0
- data/lib/more_holiday/exporters/i_cal.rb +32 -0
- data/lib/more_holiday/holiday.rb +52 -0
- data/lib/more_holiday/importer.rb +45 -0
- data/lib/more_holiday/importers/i_cal.rb +59 -0
- data/lib/more_holiday/version.rb +3 -0
- data/more_holiday.gemspec +44 -0
- metadata +183 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bcded40b95d1fe5186e076286ffd3ceae78990274c9c79a32721d050028edd04
|
4
|
+
data.tar.gz: 9afa62b0754a4215a483afc3dec2ed7ba32210878aef8424dc4e1a1895078674
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 45342d6f46ee5aa3ac5249950fc9aaff8fd91ced4d5f37a0d7c9e1be5e7e0e180ea225745e4e1b1cfda64387cb0bb686163a69b0e60f8ebfa69f9728e8becf16
|
7
|
+
data.tar.gz: 5191bdee0312dd3c0726ed9f23741445c475a49b6351d0fccb8811187d6751b34bbcb58a14e68375ab94cd82ef789e7b25d46ff470d4c4961c0e80dc23ed9db3
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at fredericwalch@me.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
more_holiday (0.0.1)
|
5
|
+
icalendar (~> 2.4)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
addressable (2.5.2)
|
11
|
+
public_suffix (>= 2.0.2, < 4.0)
|
12
|
+
coderay (1.1.2)
|
13
|
+
crack (0.4.3)
|
14
|
+
safe_yaml (~> 1.0.0)
|
15
|
+
diff-lcs (1.3)
|
16
|
+
docile (1.3.0)
|
17
|
+
hashdiff (0.3.7)
|
18
|
+
icalendar (2.4.1)
|
19
|
+
json (2.1.0)
|
20
|
+
method_source (0.8.2)
|
21
|
+
pry (0.10.4)
|
22
|
+
coderay (~> 1.1.0)
|
23
|
+
method_source (~> 0.8.1)
|
24
|
+
slop (~> 3.4)
|
25
|
+
pry-nav (0.2.4)
|
26
|
+
pry (>= 0.9.10, < 0.11.0)
|
27
|
+
public_suffix (3.0.2)
|
28
|
+
rake (10.5.0)
|
29
|
+
rspec (3.7.0)
|
30
|
+
rspec-core (~> 3.7.0)
|
31
|
+
rspec-expectations (~> 3.7.0)
|
32
|
+
rspec-mocks (~> 3.7.0)
|
33
|
+
rspec-core (3.7.1)
|
34
|
+
rspec-support (~> 3.7.0)
|
35
|
+
rspec-expectations (3.7.0)
|
36
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
37
|
+
rspec-support (~> 3.7.0)
|
38
|
+
rspec-mocks (3.7.0)
|
39
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
40
|
+
rspec-support (~> 3.7.0)
|
41
|
+
rspec-support (3.7.1)
|
42
|
+
safe_yaml (1.0.4)
|
43
|
+
simplecov (0.16.1)
|
44
|
+
docile (~> 1.1)
|
45
|
+
json (>= 1.8, < 3)
|
46
|
+
simplecov-html (~> 0.10.0)
|
47
|
+
simplecov-html (0.10.2)
|
48
|
+
slop (3.6.0)
|
49
|
+
webmock (3.3.0)
|
50
|
+
addressable (>= 2.3.6)
|
51
|
+
crack (>= 0.3.2)
|
52
|
+
hashdiff
|
53
|
+
|
54
|
+
PLATFORMS
|
55
|
+
ruby
|
56
|
+
|
57
|
+
DEPENDENCIES
|
58
|
+
bundler (~> 1.16)
|
59
|
+
more_holiday!
|
60
|
+
pry (~> 0.10)
|
61
|
+
pry-nav (~> 0.2)
|
62
|
+
rake (~> 10.0)
|
63
|
+
rspec (~> 3.0)
|
64
|
+
simplecov (~> 0.16)
|
65
|
+
webmock (~> 3.3)
|
66
|
+
|
67
|
+
BUNDLED WITH
|
68
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Frederic Walch
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# MoreHoliday
|
2
|
+
|
3
|
+
Make more out of your holidays!
|
4
|
+
|
5
|
+
## Description
|
6
|
+
|
7
|
+
Use bridging days smartly, to have more value out of your given holiday days. This gem automatically suggests you, which days to reserve next time you ask your employer for vacation.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'more_holiday'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install more_holiday
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
This libary comes with german official holidays build in! So you just need to select your state and how many days you have available. Then you will get a suggestion, which days you should use, to take advantage from bridging days.
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
MoreHoliday::Holiday.new("Berlin", available_days: 15).suggestions
|
31
|
+
```
|
32
|
+
|
33
|
+
Currently only german official holidays are supported. If you want to use select a different state or just want to play custom non official days, you can initialize with an ical file.
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
MoreHoliday::Holiday.new(nil, available_days: 15, file_path: "/path/to/ical.ics").suggestions
|
37
|
+
```
|
38
|
+
|
39
|
+
## Export
|
40
|
+
|
41
|
+
It is possible to export the suggested days as a ical file as well, so you don't need to add them all manually to your calendar.
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
MoreHoliday::Holiday.new("Berlin", available_days: 15).export_ical_file("/path/for/export")
|
45
|
+
# => "/path/for/export/MoreHoliday.ics"
|
46
|
+
```
|
47
|
+
|
48
|
+
## Next steps
|
49
|
+
|
50
|
+
- Add preference option, that suggestions are focused on specific time ranges
|
51
|
+
- Support more country states
|
52
|
+
- Add more import and export file content types
|
53
|
+
- Add browser support, that libary can be used with a stylish interface
|
54
|
+
|
55
|
+
## Development
|
56
|
+
|
57
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
58
|
+
|
59
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
60
|
+
|
61
|
+
## Contributing
|
62
|
+
|
63
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/freder1c/more_holiday. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
64
|
+
|
65
|
+
## License
|
66
|
+
|
67
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
68
|
+
|
69
|
+
## Code of Conduct
|
70
|
+
|
71
|
+
Everyone interacting in the MoreHoliday project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/freder1c/more_holiday/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "more_holiday"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/circle.yml
ADDED
data/lib/more_holiday.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
require "fileutils"
|
2
|
+
|
3
|
+
module MoreHoliday
|
4
|
+
module Cache
|
5
|
+
class File
|
6
|
+
attr_reader :file_name, :folder_path, :data
|
7
|
+
|
8
|
+
def initialize file_name:, folder_path:
|
9
|
+
@file_name = file_name
|
10
|
+
@folder_path = ::File.join(cache_base_path, folder_path)
|
11
|
+
end
|
12
|
+
|
13
|
+
def file_path
|
14
|
+
::File.join(folder_path, file_name)
|
15
|
+
end
|
16
|
+
|
17
|
+
def read
|
18
|
+
return nil if !exist? or !still_valid?
|
19
|
+
::File.read(file_path)
|
20
|
+
rescue
|
21
|
+
raise FileCacheReadError, "An error occurred while reading from file cache."
|
22
|
+
end
|
23
|
+
|
24
|
+
def write data
|
25
|
+
@data = data
|
26
|
+
FileUtils::mkdir_p(folder_path)
|
27
|
+
!!::File.write(file_path, data)
|
28
|
+
end
|
29
|
+
|
30
|
+
def exist?
|
31
|
+
::File.exists?(file_path) and still_valid?
|
32
|
+
end
|
33
|
+
|
34
|
+
def resolve function
|
35
|
+
if exist?
|
36
|
+
read
|
37
|
+
else
|
38
|
+
write function.call
|
39
|
+
data
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.clear!
|
44
|
+
!!FileUtils.rm_rf(::File.join("tmp", "cache"))
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def cache_base_path
|
50
|
+
::File.join("tmp", "cache")
|
51
|
+
end
|
52
|
+
|
53
|
+
def still_valid?
|
54
|
+
# TODO: implement useful invalidation rule
|
55
|
+
true
|
56
|
+
end
|
57
|
+
|
58
|
+
class FileCacheReadError < StandardError
|
59
|
+
end
|
60
|
+
|
61
|
+
class FileCacheWriteError < StandardError
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module MoreHoliday
|
2
|
+
class Calculator
|
3
|
+
attr_accessor :holidays, :available_days
|
4
|
+
attr_reader :suggestions
|
5
|
+
|
6
|
+
|
7
|
+
def initialize holidays, available_days
|
8
|
+
@holidays = holidays
|
9
|
+
@available_days = available_days
|
10
|
+
end
|
11
|
+
|
12
|
+
def suggestions
|
13
|
+
@suggestions = []
|
14
|
+
count = available_days
|
15
|
+
nwd = non_working_day_numbers
|
16
|
+
range = 1
|
17
|
+
|
18
|
+
while count > 0 do
|
19
|
+
bridges = find_bridges(nwd, range)
|
20
|
+
|
21
|
+
bridges.each do |bridge|
|
22
|
+
@suggestions << Date.ordinal(year, bridge).to_s
|
23
|
+
count -= 1
|
24
|
+
break if count == 0
|
25
|
+
end
|
26
|
+
|
27
|
+
range += 1
|
28
|
+
end
|
29
|
+
|
30
|
+
@suggestions.sort!
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def year
|
36
|
+
@year ||= holidays.any? ? Date.parse(holidays.first.first).year : nil
|
37
|
+
end
|
38
|
+
|
39
|
+
def first_sunday_of_year
|
40
|
+
day = 1
|
41
|
+
day += 1 until Date.new(year,1,day).sunday? == true
|
42
|
+
day
|
43
|
+
end
|
44
|
+
|
45
|
+
def holiday_day_numbers
|
46
|
+
holidays.map{ |date, summary| Date.parse(date).yday }
|
47
|
+
end
|
48
|
+
|
49
|
+
def week_end_day_numbers
|
50
|
+
range = Date.new(year,1,1)..Date.new(year,12,31)
|
51
|
+
grouped_days = range.group_by(&:wday)
|
52
|
+
(grouped_days[6] + grouped_days[0]).map(&:yday).sort
|
53
|
+
end
|
54
|
+
|
55
|
+
def non_working_day_numbers
|
56
|
+
(holiday_day_numbers + week_end_day_numbers).uniq.sort
|
57
|
+
end
|
58
|
+
|
59
|
+
def find_bridges days, size
|
60
|
+
bridges = Array.new
|
61
|
+
range = size + 1
|
62
|
+
|
63
|
+
for pointer in 0..(days.size-2)
|
64
|
+
if days[pointer + 1] - days[pointer] == range
|
65
|
+
for day in 1..size
|
66
|
+
bridges << (days[pointer] + day)
|
67
|
+
end
|
68
|
+
else
|
69
|
+
next
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
bridges
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require "more_holiday/importer"
|
2
|
+
require "more_holiday/exporter"
|
3
|
+
require "more_holiday/cache/file"
|
4
|
+
|
5
|
+
require "more_holiday/connectors/ifeiertage/ifeiertage"
|
6
|
+
|
7
|
+
module MoreHoliday
|
8
|
+
class Connector
|
9
|
+
attr_reader :state, :file_path, :year
|
10
|
+
|
11
|
+
def initialize state, file_path: nil, year: Date.today.year
|
12
|
+
@state = state
|
13
|
+
@file_path = file_path
|
14
|
+
@year = year
|
15
|
+
end
|
16
|
+
|
17
|
+
def holidays
|
18
|
+
@holidays ||=
|
19
|
+
if file_path.nil?
|
20
|
+
connect
|
21
|
+
else
|
22
|
+
Importer.new(year).from_file(file_path)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def source
|
27
|
+
return "file" unless file_path.nil?
|
28
|
+
service::SOURCE
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def service
|
34
|
+
@service ||=
|
35
|
+
case country
|
36
|
+
when "de" then Ifeiertage
|
37
|
+
else raise NotProvidedError, "No service for #{country} officals provided."
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def connect
|
42
|
+
eval(cache.resolve Proc.new { Importer.new(year).from_stream(service::Connect.get(state)).to_s })
|
43
|
+
end
|
44
|
+
|
45
|
+
def state_valid?
|
46
|
+
countries.values.flatten.include?(state)
|
47
|
+
end
|
48
|
+
|
49
|
+
def country
|
50
|
+
raise InvalidStateError, "#{state} not included in states list." unless state_valid?
|
51
|
+
countries.each { |country, states| return country if states.include?(state) }
|
52
|
+
end
|
53
|
+
|
54
|
+
def countries
|
55
|
+
@countries ||= {
|
56
|
+
"de" => [
|
57
|
+
"Baden-Württemberg",
|
58
|
+
"Bavaria",
|
59
|
+
"Berlin",
|
60
|
+
"Brandenburg",
|
61
|
+
"Bremen",
|
62
|
+
"Hamburg",
|
63
|
+
"Hesse",
|
64
|
+
"Lower Saxony",
|
65
|
+
"Mecklenburg-Vorpommern",
|
66
|
+
"North Rhine-Westphalia",
|
67
|
+
"Rhine-Palatinate",
|
68
|
+
"Saarland",
|
69
|
+
"Saxony",
|
70
|
+
"Saxony-Anhalt",
|
71
|
+
"Schleswig-Holstein",
|
72
|
+
"Thuringia"
|
73
|
+
]
|
74
|
+
}
|
75
|
+
end
|
76
|
+
|
77
|
+
def cache
|
78
|
+
@cache ||= Cache::File.new(file_name: year.to_s, folder_path: File.join("holidays", country, state))
|
79
|
+
end
|
80
|
+
|
81
|
+
class NotProvidedError < StandardError
|
82
|
+
end
|
83
|
+
|
84
|
+
class InvalidStateError < StandardError
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "net/http"
|
2
|
+
require "fileutils"
|
3
|
+
|
4
|
+
module MoreHoliday
|
5
|
+
module Ifeiertage
|
6
|
+
class Api
|
7
|
+
attr_reader :state
|
8
|
+
|
9
|
+
def get state
|
10
|
+
@state = state
|
11
|
+
response = Net::HTTP.get_response(URI(url))
|
12
|
+
raise ConnectionError, "Can't connect to #{SOURCE}" unless response.is_a?(Net::HTTPSuccess)
|
13
|
+
response.body
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def url
|
19
|
+
"#{SOURCE}/calendar.php?bl=#{state}&o=1&t=dnl"
|
20
|
+
end
|
21
|
+
|
22
|
+
class ConnectionError < StandardError
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module MoreHoliday
|
2
|
+
module Ifeiertage
|
3
|
+
class Connect
|
4
|
+
attr_reader :state
|
5
|
+
|
6
|
+
def initialize state
|
7
|
+
@state = converted(state)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.get state
|
11
|
+
new(state).get
|
12
|
+
end
|
13
|
+
|
14
|
+
def get
|
15
|
+
cache.resolve Proc.new { api.get(state) }
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def api
|
21
|
+
@api ||= Api.new
|
22
|
+
end
|
23
|
+
|
24
|
+
def cache
|
25
|
+
@cache ||= Cache::File.new(file_name: state, folder_path: cache_base_folder)
|
26
|
+
end
|
27
|
+
|
28
|
+
def cache_base_folder
|
29
|
+
File.join("connectors", "ifeiertage")
|
30
|
+
end
|
31
|
+
|
32
|
+
def converted state
|
33
|
+
{
|
34
|
+
"Baden-Württemberg" => "bw",
|
35
|
+
"Bavaria" => "by",
|
36
|
+
"Berlin" => "be",
|
37
|
+
"Brandenburg" => "bb",
|
38
|
+
"Bremen" => "hb",
|
39
|
+
"Hamburg" => "hh",
|
40
|
+
"Hesse" => "he",
|
41
|
+
"Lower Saxony" => "ni",
|
42
|
+
"Mecklenburg-Vorpommern" => "mv",
|
43
|
+
"North Rhine-Westphalia" => "nw",
|
44
|
+
"Rhine-Palatinate" => "rp",
|
45
|
+
"Saarland" => "sl",
|
46
|
+
"Saxony" => "sn",
|
47
|
+
"Saxony-Anhalt" => "st",
|
48
|
+
"Schleswig-Holstein" => "sh",
|
49
|
+
"Thuringia" => "th"
|
50
|
+
}[state]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "more_holiday/exporters/i_cal"
|
2
|
+
require "fileutils"
|
3
|
+
|
4
|
+
module MoreHoliday
|
5
|
+
class Exporter
|
6
|
+
attr_reader :content
|
7
|
+
|
8
|
+
def initialize content
|
9
|
+
@content = content
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_file path, type: "ical"
|
13
|
+
output_base_path = path || Dir.pwd
|
14
|
+
data, extension = serialize(type)
|
15
|
+
complete_path = File.join(output_base_path, "MoreHoliday.#{extension}")
|
16
|
+
FileUtils.mkdir_p(output_base_path)
|
17
|
+
File.write(complete_path, data)
|
18
|
+
complete_path
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_stream type
|
22
|
+
serialize(type).first
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def serialize type
|
28
|
+
case type
|
29
|
+
when "ical" then [Exporters::ICal.new(content).serialize, "ics"]
|
30
|
+
else raise NotSupportedError, "Type of file is not supported."
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class NotSupportedError < StandardError
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "icalendar"
|
2
|
+
|
3
|
+
module MoreHoliday
|
4
|
+
module Exporters
|
5
|
+
class ICal
|
6
|
+
attr_reader :content, :serialized
|
7
|
+
|
8
|
+
def initialize content
|
9
|
+
@content = content
|
10
|
+
end
|
11
|
+
|
12
|
+
def serialize
|
13
|
+
@cal = Icalendar::Calendar.new
|
14
|
+
serialize_events
|
15
|
+
@serialized = @cal.to_ical
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def serialize_events
|
21
|
+
@content.each do |date, summary|
|
22
|
+
@cal.event do |e|
|
23
|
+
e.dtstart = Icalendar::Values::Date.new(date.delete("-"))
|
24
|
+
e.dtend = Icalendar::Values::Date.new(date.delete("-"))
|
25
|
+
e.summary = summary
|
26
|
+
e.ip_class = "MoreHoliday"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require "more_holiday/connector"
|
2
|
+
require "more_holiday/calculator"
|
3
|
+
|
4
|
+
module MoreHoliday
|
5
|
+
class Holiday
|
6
|
+
attr_reader :state, :available_days, :file_path, :year
|
7
|
+
|
8
|
+
def initialize state, available_days: 0, file_path: nil, year: Date.today.year
|
9
|
+
@state = state
|
10
|
+
@available_days = available_days
|
11
|
+
@file_path = file_path
|
12
|
+
@year = year
|
13
|
+
end
|
14
|
+
|
15
|
+
def make_more_out_of_my_holidays!
|
16
|
+
suggestions
|
17
|
+
end
|
18
|
+
|
19
|
+
def suggestions
|
20
|
+
{
|
21
|
+
holidays_to_take: calculator.suggestions,
|
22
|
+
official_holidays: connector.holidays,
|
23
|
+
info: {
|
24
|
+
state: connector.state,
|
25
|
+
officials_source: connector.source
|
26
|
+
}
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
def give_me_a_calender_file! path
|
31
|
+
export_ical_file(path)
|
32
|
+
end
|
33
|
+
|
34
|
+
def export_ical_file path
|
35
|
+
export_suggestions.to_file(path, type: "ical")
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def connector
|
41
|
+
@connector ||= Connector.new(state, file_path: file_path, year: year)
|
42
|
+
end
|
43
|
+
|
44
|
+
def calculator
|
45
|
+
@calculator ||= Calculator.new(connector.holidays, available_days)
|
46
|
+
end
|
47
|
+
|
48
|
+
def export_suggestions
|
49
|
+
@export_suggestions ||= Exporter.new(calculator.suggestions.map{ |d| [d, "Take a break :)"] })
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "more_holiday/importers/i_cal"
|
2
|
+
|
3
|
+
module MoreHoliday
|
4
|
+
class Importer
|
5
|
+
attr_reader :path, :stream, :year, :content
|
6
|
+
|
7
|
+
def initialize year = Date.today.year
|
8
|
+
@year = year
|
9
|
+
end
|
10
|
+
|
11
|
+
def from_file path
|
12
|
+
@path = path
|
13
|
+
@content = read_file
|
14
|
+
end
|
15
|
+
|
16
|
+
def from_stream stream
|
17
|
+
@stream = stream
|
18
|
+
@contect = read_stream
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def read_file
|
24
|
+
File.open(path, "r") do |file|
|
25
|
+
case File.extname(file).delete(".")
|
26
|
+
when "ics" then Importers::ICal.new(File.read(file), year: year).serialize
|
27
|
+
else
|
28
|
+
file.close
|
29
|
+
raise LoadError, "Type of file is not supported."
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def read_stream
|
35
|
+
case true
|
36
|
+
when stream.start_with?("BEGIN:VCALENDAR")
|
37
|
+
Importers::ICal.new(stream, year: year).serialize
|
38
|
+
else raise StreamContentTypeError, "Could not detect content type of stream"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class StreamContentTypeError < StandardError
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require "icalendar"
|
2
|
+
|
3
|
+
module MoreHoliday
|
4
|
+
module Importers
|
5
|
+
class ICal
|
6
|
+
attr_reader :year, :content, :serialized
|
7
|
+
|
8
|
+
def initialize content, year: Date.today.year
|
9
|
+
@content = content
|
10
|
+
@year = year
|
11
|
+
end
|
12
|
+
|
13
|
+
def serialize
|
14
|
+
extract_events
|
15
|
+
remove_out_of_scope_events
|
16
|
+
@serialized.sort!
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def extract_events
|
22
|
+
Icalendar::Calendar.parse(content).map do |calendar|
|
23
|
+
calendar.events.map do |event|
|
24
|
+
if !event.rrule.first.nil?
|
25
|
+
complete_frequent(event)
|
26
|
+
else
|
27
|
+
add_event(event.dtstart, event.summary)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def add_event date, summary
|
34
|
+
@serialized = Array.new unless @serialized.is_a?(Array)
|
35
|
+
@serialized << [date.to_s, summary.to_s]
|
36
|
+
end
|
37
|
+
|
38
|
+
def complete_frequent event
|
39
|
+
rules = event.rrule.first
|
40
|
+
|
41
|
+
case rules.frequency
|
42
|
+
when "YEARLY"
|
43
|
+
event_year, month, day = event.dtstart.year, event.dtstart.month, event.dtstart.day
|
44
|
+
|
45
|
+
if rules.interval.is_a?(Integer)
|
46
|
+
while event_year <= year or event_year <= event.dtstamp.year
|
47
|
+
add_event(Date.parse("#{event_year}-#{month}-#{day}"), event.summary)
|
48
|
+
event_year += rules.interval
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def remove_out_of_scope_events
|
55
|
+
@serialized.reject! { |event| Date.parse(event.first).year != year }
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "more_holiday/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "more_holiday"
|
8
|
+
spec.version = MoreHoliday::VERSION
|
9
|
+
spec.authors = ["Frederic Walch"]
|
10
|
+
spec.email = ["fredericwalch@me.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Get more out of your holidays! Use bridge days smartly.}
|
13
|
+
spec.description = %q{Get more out of your holidays! Use bridge days smartly.}
|
14
|
+
spec.homepage = "https://github.com/freder1c"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
"public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_dependency "icalendar", "~> 2.4"
|
34
|
+
|
35
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
36
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
37
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
38
|
+
spec.add_development_dependency "webmock", "~> 3.3"
|
39
|
+
|
40
|
+
spec.add_development_dependency "pry", "~> 0.10"
|
41
|
+
spec.add_development_dependency "pry-nav", "~> 0.2"
|
42
|
+
|
43
|
+
spec.add_development_dependency "simplecov", "~> 0.16"
|
44
|
+
end
|
metadata
ADDED
@@ -0,0 +1,183 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: more_holiday
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Frederic Walch
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-03-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: icalendar
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.4'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.16'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.16'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: webmock
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.3'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.3'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.10'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.10'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry-nav
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.2'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.2'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: simplecov
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.16'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0.16'
|
125
|
+
description: Get more out of your holidays! Use bridge days smartly.
|
126
|
+
email:
|
127
|
+
- fredericwalch@me.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".gitignore"
|
133
|
+
- ".rspec"
|
134
|
+
- CODE_OF_CONDUCT.md
|
135
|
+
- Gemfile
|
136
|
+
- Gemfile.lock
|
137
|
+
- LICENSE.txt
|
138
|
+
- README.md
|
139
|
+
- Rakefile
|
140
|
+
- bin/console
|
141
|
+
- bin/setup
|
142
|
+
- circle.yml
|
143
|
+
- lib/more_holiday.rb
|
144
|
+
- lib/more_holiday/cache/file.rb
|
145
|
+
- lib/more_holiday/calculator.rb
|
146
|
+
- lib/more_holiday/connector.rb
|
147
|
+
- lib/more_holiday/connectors/ifeiertage/api.rb
|
148
|
+
- lib/more_holiday/connectors/ifeiertage/connect.rb
|
149
|
+
- lib/more_holiday/connectors/ifeiertage/ifeiertage.rb
|
150
|
+
- lib/more_holiday/connectors/ifeiertage/source.rb
|
151
|
+
- lib/more_holiday/exporter.rb
|
152
|
+
- lib/more_holiday/exporters/i_cal.rb
|
153
|
+
- lib/more_holiday/holiday.rb
|
154
|
+
- lib/more_holiday/importer.rb
|
155
|
+
- lib/more_holiday/importers/i_cal.rb
|
156
|
+
- lib/more_holiday/version.rb
|
157
|
+
- more_holiday.gemspec
|
158
|
+
homepage: https://github.com/freder1c
|
159
|
+
licenses:
|
160
|
+
- MIT
|
161
|
+
metadata:
|
162
|
+
allowed_push_host: https://rubygems.org
|
163
|
+
post_install_message:
|
164
|
+
rdoc_options: []
|
165
|
+
require_paths:
|
166
|
+
- lib
|
167
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
168
|
+
requirements:
|
169
|
+
- - ">="
|
170
|
+
- !ruby/object:Gem::Version
|
171
|
+
version: '0'
|
172
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
173
|
+
requirements:
|
174
|
+
- - ">="
|
175
|
+
- !ruby/object:Gem::Version
|
176
|
+
version: '0'
|
177
|
+
requirements: []
|
178
|
+
rubyforge_project:
|
179
|
+
rubygems_version: 2.7.3
|
180
|
+
signing_key:
|
181
|
+
specification_version: 4
|
182
|
+
summary: Get more out of your holidays! Use bridge days smartly.
|
183
|
+
test_files: []
|