russian_workdays 0.0.1

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
+ SHA1:
3
+ metadata.gz: f8363c876ef30abb4c321979b22e0b7b025b2fd8
4
+ data.tar.gz: 45f5dc1d23f2f3033e035548c90c5c4a5d7baea7
5
+ SHA512:
6
+ metadata.gz: f3e139d92e398be1167183b795ce0592d5821acef17ead9f5d89537803fbc3f3813d347ef1d12294eee7b0bf9e01350d6ea03a01dfb3634e760a74676a924ac3
7
+ data.tar.gz: 6db794261c33f1f71e188579cf13bedfb7921ed3549ee7fa8b98ecbef8a3dbd823b4a41c11faabac848ef88d697315b885e2589f09f57fc20c55325840f95c41
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ .idea/
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in russian_workdays.gemspec
4
+ gemspec
5
+ gem 'nokogiri'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 heckfy
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # russian_workdays
2
+
3
+ Производственный календарь РФ
4
+
5
+ ## Установка
6
+ Выполняем в терминале:
7
+
8
+ gem install russian_workdays
9
+
10
+ и подгружаем:
11
+
12
+ ```ruby
13
+ require 'russian_workdays'
14
+ ```
15
+
16
+ ## Использование
17
+
18
+ Получить массив с выходными днями в 2014 году
19
+
20
+ ```ruby
21
+ RussianWorkdays.holidays(2014)
22
+ ```
23
+
24
+ Получить массив с короткими днями в 2014 году
25
+
26
+ ```ruby
27
+ RussianWorkdays.shorts(2014)
28
+ ```
29
+
30
+ Получить массив с рабочими днями в 2014 году
31
+
32
+ ```ruby
33
+ RussianWorkdays.works(2014)
34
+ ```
35
+
36
+ Является ли дата выходным днем?
37
+
38
+ ```ruby
39
+ RussianWorkdays.holiday?(Date.new 2014, 10, 5))
40
+ ```
41
+
42
+ Является ли дата коротким днем?
43
+
44
+ ```ruby
45
+ RussianWorkdays.short?(Date.new 2014, 10, 5))
46
+ ```
47
+
48
+ Является ли дата рабочим днем?
49
+
50
+ ```ruby
51
+ RussianWorkdays.work?(Date.new 2014, 10, 5))
52
+ ```
53
+
54
+ ## Contributing
55
+
56
+ 1. Fork it ( https://github.com/[my-github-username]/russian_workdays/fork )
57
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
58
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
59
+ 4. Push to the branch (`git push origin my-new-feature`)
60
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ # Default directory to look in is `/specs`
5
+ # Run with `rake spec`
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,47 @@
1
+ require 'russian_workdays/version'
2
+ require 'open-uri'
3
+ require 'nokogiri'
4
+
5
+ module RussianWorkdays
6
+ class << self
7
+ def get_dates year
8
+ if @year == year
9
+ return @dates
10
+ else
11
+ @year = year
12
+ end
13
+ @dates = parse Nokogiri::HTML(open("http://www.superjob.ru/proizvodstvennyj_kalendar/#{year}"))
14
+ end
15
+
16
+ def parse page
17
+ dates = {}
18
+ months = [nil, 'Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь']
19
+ page.css('td.pk_container').each do |month|
20
+ month.css('div.pk_cells div').each do |day|
21
+ unless day.attr('class') == 'pk_other'
22
+ date = Date.new @year, months.index(month.css('div.pk_header').inner_text), day.inner_text.to_i
23
+ case day.attr 'class'
24
+ when /pk_holiday/
25
+ dates[date] = 'holiday'
26
+ when /pk_preholiday/
27
+ dates[date] = 'short'
28
+ else
29
+ dates[date] = 'work'
30
+ end
31
+ end
32
+ end
33
+ end
34
+ dates
35
+ end
36
+
37
+ %w(holiday short work).each do |method|
38
+ define_method("#{method}?") do |date|
39
+ get_dates(date.year)[date] == method
40
+ end
41
+
42
+ define_method("#{method}s") do |year|
43
+ get_dates(year).select{|key, value| value == method}.keys
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,3 @@
1
+ module RussianWorkdays
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'russian_workdays/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'russian_workdays'
8
+ spec.version = RussianWorkdays::VERSION
9
+ spec.authors = ['heckfy']
10
+ spec.email = ['heckfyoz@gmail.com']
11
+ spec.summary = 'Russian workdays'
12
+ spec.description = ''
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.6'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'rspec'
24
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe RussianWorkdays do
4
+ before(:all) do
5
+ @shorts = %w(2014-02-24 2014-03-07 2014-04-30 2014-05-08 2014-06-11 2014-12-31)
6
+ @holidays = %w(2014-01-01 2014-03-22 2014-07-12 2014-09-06 2014-10-26 2014-12-28)
7
+ @works = %w(2014-01-09 2014-02-03 2014-05-27 2014-07-22 2014-11-11 2014-12-30)
8
+ end
9
+
10
+ it 'should return the right short days' do
11
+ expect(RussianWorkdays.shorts(2014).map(&:to_s)).to eq(@shorts)
12
+ end
13
+
14
+ it 'should return the right holydays' do
15
+ expect(RussianWorkdays.holidays(2014).map(&:to_s)).to include(*@holidays)
16
+ end
17
+
18
+ it 'should return the right short works' do
19
+ expect(RussianWorkdays.works(2014).map(&:to_s)).to include(*@works)
20
+ end
21
+
22
+ it 'should return true if date is short day' do
23
+ @shorts.each do |date|
24
+ expect(RussianWorkdays.short?(Date.parse date)).to eq(true)
25
+ end
26
+ end
27
+
28
+ it 'should return true if date is holiday day' do
29
+ @holidays.each do |date|
30
+ expect(RussianWorkdays.holiday?(Date.parse date)).to eq(true)
31
+ end
32
+ end
33
+
34
+ it 'should return true if date is work day' do
35
+ @works.each do |date|
36
+ expect(RussianWorkdays.work?(Date.parse date)).to eq(true)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,4 @@
1
+ require 'bundler/setup'
2
+ Bundler.setup
3
+
4
+ require 'russian_workdays'
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: russian_workdays
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - heckfy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-22 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.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '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: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: ''
56
+ email:
57
+ - heckfyoz@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/russian_workdays.rb
68
+ - lib/russian_workdays/version.rb
69
+ - russian_workdays.gemspec
70
+ - spec/russian_workdays_spec.rb
71
+ - spec/spec_helper.rb
72
+ homepage: ''
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.2.0
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Russian workdays
96
+ test_files:
97
+ - spec/russian_workdays_spec.rb
98
+ - spec/spec_helper.rb