russia_today 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c48cbdd25df16452f8a87e989bb311936ac29327
4
+ data.tar.gz: 1234533517023b65abc91eaa6845551e397e0591
5
+ SHA512:
6
+ metadata.gz: 32169eb2280f13348a253050d30153d4a5ff36e18ec7f4ae1f2e9640b6cf66f27c6af4fe2222f90835eeafad18539aca250107157d20d3eaa42cfcea4ca3f15b
7
+ data.tar.gz: 9a7a7cde1c5be36f540839c7f0c66a2c2f722d956c4d695ab138541f08b41bcf92b5a0a4d388f4a5a5a6fb9d847bddba9bb8322933b7d751a30825d2f109df7e
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.15.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in russia_today.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Aleksey Ivanov
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.
@@ -0,0 +1,39 @@
1
+ # RussiaToday
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/russia_today`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'russia_today'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install russia_today
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ivanovaleksey/russia_today.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,8 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'russia_today/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+ RussiaToday::RakeTask.new
7
+
8
+ task default: :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'russia_today'
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__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,6 @@
1
+ require 'russia_today/version'
2
+ require 'russia_today/manager'
3
+ require 'russia_today/core_ext/date'
4
+
5
+ module RussiaToday
6
+ end
@@ -0,0 +1,24 @@
1
+ require 'yaml'
2
+
3
+ module RussiaToday
4
+ class Calendar
5
+ def initialize(year)
6
+ @year = year
7
+ end
8
+
9
+ def holiday?(date)
10
+ calendar.fetch(date, false)
11
+ end
12
+
13
+ private
14
+
15
+ attr_reader :year
16
+
17
+ def calendar
18
+ @calendar ||= begin
19
+ filepath = File.join('lib', 'russia_today', 'calendars', "#{year}.yml")
20
+ YAML.load(File.read(filepath))
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,37 @@
1
+ require 'date'
2
+ require 'yaml'
3
+ require 'russia_today/official_calendar'
4
+
5
+ module RussiaToday
6
+ class CalendarGenerator
7
+ def initialize(year)
8
+ @year = year
9
+ end
10
+
11
+ def call
12
+ beginning_of_year = Date.new(year, 1, 1)
13
+ end_of_year = Date.new(year, 12, 31)
14
+
15
+ calendar = (beginning_of_year..end_of_year).select do |date|
16
+ official_calendar.holiday?(date)
17
+ end.map { |date| [date, true] }.to_h
18
+
19
+ dump_calendar(calendar)
20
+ end
21
+
22
+ private
23
+
24
+ attr_reader :year
25
+
26
+ def official_calendar
27
+ @official_calendar ||= OfficialCalendar.new(year)
28
+ end
29
+
30
+ def dump_calendar(calendar)
31
+ filepath = File.join('lib', 'russia_today', 'calendars', "#{year}.yml")
32
+ File.open(filepath, 'w') do |file|
33
+ file << YAML.dump(calendar)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,119 @@
1
+ ---
2
+ 2017-01-01: true
3
+ 2017-01-02: true
4
+ 2017-01-03: true
5
+ 2017-01-04: true
6
+ 2017-01-05: true
7
+ 2017-01-06: true
8
+ 2017-01-07: true
9
+ 2017-01-08: true
10
+ 2017-01-14: true
11
+ 2017-01-15: true
12
+ 2017-01-21: true
13
+ 2017-01-22: true
14
+ 2017-01-28: true
15
+ 2017-01-29: true
16
+ 2017-02-04: true
17
+ 2017-02-05: true
18
+ 2017-02-11: true
19
+ 2017-02-12: true
20
+ 2017-02-18: true
21
+ 2017-02-19: true
22
+ 2017-02-23: true
23
+ 2017-02-24: true
24
+ 2017-02-25: true
25
+ 2017-02-26: true
26
+ 2017-03-04: true
27
+ 2017-03-05: true
28
+ 2017-03-08: true
29
+ 2017-03-11: true
30
+ 2017-03-12: true
31
+ 2017-03-18: true
32
+ 2017-03-19: true
33
+ 2017-03-25: true
34
+ 2017-03-26: true
35
+ 2017-04-01: true
36
+ 2017-04-02: true
37
+ 2017-04-08: true
38
+ 2017-04-09: true
39
+ 2017-04-15: true
40
+ 2017-04-16: true
41
+ 2017-04-22: true
42
+ 2017-04-23: true
43
+ 2017-04-29: true
44
+ 2017-04-30: true
45
+ 2017-05-01: true
46
+ 2017-05-06: true
47
+ 2017-05-07: true
48
+ 2017-05-08: true
49
+ 2017-05-09: true
50
+ 2017-05-13: true
51
+ 2017-05-14: true
52
+ 2017-05-20: true
53
+ 2017-05-21: true
54
+ 2017-05-27: true
55
+ 2017-05-28: true
56
+ 2017-06-03: true
57
+ 2017-06-04: true
58
+ 2017-06-10: true
59
+ 2017-06-11: true
60
+ 2017-06-12: true
61
+ 2017-06-17: true
62
+ 2017-06-18: true
63
+ 2017-06-24: true
64
+ 2017-06-25: true
65
+ 2017-07-01: true
66
+ 2017-07-02: true
67
+ 2017-07-08: true
68
+ 2017-07-09: true
69
+ 2017-07-15: true
70
+ 2017-07-16: true
71
+ 2017-07-22: true
72
+ 2017-07-23: true
73
+ 2017-07-29: true
74
+ 2017-07-30: true
75
+ 2017-08-05: true
76
+ 2017-08-06: true
77
+ 2017-08-12: true
78
+ 2017-08-13: true
79
+ 2017-08-19: true
80
+ 2017-08-20: true
81
+ 2017-08-26: true
82
+ 2017-08-27: true
83
+ 2017-09-02: true
84
+ 2017-09-03: true
85
+ 2017-09-09: true
86
+ 2017-09-10: true
87
+ 2017-09-16: true
88
+ 2017-09-17: true
89
+ 2017-09-23: true
90
+ 2017-09-24: true
91
+ 2017-09-30: true
92
+ 2017-10-01: true
93
+ 2017-10-07: true
94
+ 2017-10-08: true
95
+ 2017-10-14: true
96
+ 2017-10-15: true
97
+ 2017-10-21: true
98
+ 2017-10-22: true
99
+ 2017-10-28: true
100
+ 2017-10-29: true
101
+ 2017-11-04: true
102
+ 2017-11-05: true
103
+ 2017-11-06: true
104
+ 2017-11-11: true
105
+ 2017-11-12: true
106
+ 2017-11-18: true
107
+ 2017-11-19: true
108
+ 2017-11-25: true
109
+ 2017-11-26: true
110
+ 2017-12-02: true
111
+ 2017-12-03: true
112
+ 2017-12-09: true
113
+ 2017-12-10: true
114
+ 2017-12-16: true
115
+ 2017-12-17: true
116
+ 2017-12-23: true
117
+ 2017-12-24: true
118
+ 2017-12-30: true
119
+ 2017-12-31: true
@@ -0,0 +1,8 @@
1
+ require 'date'
2
+
3
+ class Date
4
+ def holiday?
5
+ manager = RussiaToday::Manager.instance
6
+ manager.holiday?(self)
7
+ end
8
+ end
@@ -0,0 +1,31 @@
1
+ require 'singleton'
2
+ require 'russia_today/calendar'
3
+
4
+ module RussiaToday
5
+ class Manager
6
+ include Singleton
7
+
8
+ def initialize
9
+ @calendars = {}
10
+ end
11
+
12
+ def holiday?(date)
13
+ calendar = pick_calendar(date.year)
14
+ calendar.holiday?(date)
15
+ end
16
+
17
+ private
18
+
19
+ def pick_calendar(year)
20
+ if @calendars.has_key?(year)
21
+ @calendars[year]
22
+ else
23
+ @calendars[year] = load_calendar(year)
24
+ end
25
+ end
26
+
27
+ def load_calendar(year)
28
+ Calendar.new(year)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,37 @@
1
+ require 'net/http'
2
+ require 'json'
3
+
4
+ module RussiaToday
5
+ class OfficialCalendar
6
+ URL = 'http://basicdata.ru/api/json/calend'
7
+
8
+ def initialize(year)
9
+ @year = year
10
+ end
11
+
12
+ def holiday?(date)
13
+ type = calendar.dig(date.month.to_s, date.day.to_s, 'isWorking')
14
+
15
+ case type
16
+ when nil
17
+ date.saturday? || date.sunday?
18
+ when 2
19
+ true
20
+ else
21
+ false
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ attr_reader :year
28
+
29
+ def calendar
30
+ @calendar ||= begin
31
+ resp = Net::HTTP.get(URI(URL))
32
+ json = JSON.parse(resp)
33
+ json.dig('data', year.to_s)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,24 @@
1
+ require 'date'
2
+ require 'russia_today/calendar_generator'
3
+
4
+ module RussiaToday
5
+ class RakeTask < Rake::TaskLib
6
+ def initialize(name = :generate_calendar)
7
+ @name = name
8
+ define
9
+ end
10
+
11
+ private
12
+
13
+ attr_reader :name
14
+
15
+ def define
16
+ desc 'Generate calendar file'
17
+ task name, [:year] do |_, args|
18
+ year = args[:year] || Date.today.year
19
+ generator = CalendarGenerator.new(year.to_i)
20
+ generator.call
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module RussiaToday
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'russia_today/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'russia_today'
8
+ spec.version = RussiaToday::VERSION
9
+ spec.authors = ['Aleksey Ivanov']
10
+ spec.email = ['ialexxei@gmail.com']
11
+
12
+ spec.summary = 'Holidays according to official calendar.'
13
+ spec.description = spec.summary
14
+ spec.homepage = 'https://github.com/ivanovaleksey/russia_today'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.15'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'rspec', '~> 3.0'
27
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: russia_today
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Aleksey Ivanov
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-06-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: Holidays according to official calendar.
56
+ email:
57
+ - ialexxei@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - lib/russia_today.rb
72
+ - lib/russia_today/calendar.rb
73
+ - lib/russia_today/calendar_generator.rb
74
+ - lib/russia_today/calendars/2017.yml
75
+ - lib/russia_today/core_ext/date.rb
76
+ - lib/russia_today/manager.rb
77
+ - lib/russia_today/official_calendar.rb
78
+ - lib/russia_today/rake_task.rb
79
+ - lib/russia_today/version.rb
80
+ - russia_today.gemspec
81
+ homepage: https://github.com/ivanovaleksey/russia_today
82
+ licenses:
83
+ - MIT
84
+ metadata: {}
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 2.6.12
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: Holidays according to official calendar.
105
+ test_files: []