denso-calendar 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3c7c33a85c6764a7fdca6d91f6a0cfe958a21a4d5c3a3e782fa9b0b0c0ee03a5
4
+ data.tar.gz: d1bcda50e70edff6a53b166796e9818e523848cecb1897f71155103e7eb76837
5
+ SHA512:
6
+ metadata.gz: 5dc68733a82f18c6fba78fd6fe7ebeed956d9338eed69758c91131e1deba568532e21a3b0e24ec906c63a3aa5ef84a264ea0a9f2769de19b83b3111564eb91c9
7
+ data.tar.gz: 2a4a904f8b798def8ed7fc596a7d23df5b24ff52ce690f67752ef6dc00b011bdce36a2075762d25a72c0df4fb392c05125b6bce21bba8d07e724f818027a8285
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.0
6
+ before_install: gem install bundler -v 2.1.2
@@ -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 satoryu.1981@gmail.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 [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in denso-calendar.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,54 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ denso-calendar (0.1.0)
5
+ icalendar (~> 2.6)
6
+ nokogiri (~> 1.10)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.7.0)
12
+ public_suffix (>= 2.0.2, < 5.0)
13
+ crack (0.4.3)
14
+ safe_yaml (~> 1.0.0)
15
+ diff-lcs (1.3)
16
+ hashdiff (1.0.0)
17
+ icalendar (2.6.1)
18
+ ice_cube (~> 0.16)
19
+ ice_cube (0.16.3)
20
+ mini_portile2 (2.4.0)
21
+ nokogiri (1.10.8)
22
+ mini_portile2 (~> 2.4.0)
23
+ public_suffix (4.0.3)
24
+ rake (12.3.3)
25
+ rspec (3.9.0)
26
+ rspec-core (~> 3.9.0)
27
+ rspec-expectations (~> 3.9.0)
28
+ rspec-mocks (~> 3.9.0)
29
+ rspec-core (3.9.1)
30
+ rspec-support (~> 3.9.1)
31
+ rspec-expectations (3.9.0)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.9.0)
34
+ rspec-mocks (3.9.1)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.9.0)
37
+ rspec-support (3.9.2)
38
+ safe_yaml (1.0.5)
39
+ webmock (3.8.2)
40
+ addressable (>= 2.3.6)
41
+ crack (>= 0.3.2)
42
+ hashdiff (>= 0.4.0, < 2.0.0)
43
+
44
+ PLATFORMS
45
+ ruby
46
+
47
+ DEPENDENCIES
48
+ denso-calendar!
49
+ rake (~> 12.0)
50
+ rspec (~> 3.0)
51
+ webmock (~> 3.8)
52
+
53
+ BUNDLED WITH
54
+ 2.1.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Tatsuya Sato
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,70 @@
1
+ # Denso::Calendar
2
+
3
+ This gem provides a CLI and API for developers to parse DENSO Calendar published in [the website](https://www.denso.com/jp/ja/about-us/calendar/).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'denso-calendar'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```sh
16
+ bundle install
17
+ ```
18
+
19
+ Or install it yourself as:
20
+
21
+ ```sh
22
+ gem install denso-calendar
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ ### CLI
28
+
29
+ This gem provides a CLI `denso-calendar`.
30
+ You can see all holidays for a specific employee type as follows:
31
+
32
+ ```sh
33
+ desnso-calendar --type production
34
+ ```
35
+
36
+ ### Options
37
+
38
+ - `-t TYPE`, `--type TYPE`: Optional. `production` in default. `production`, `tokyo` and `flex` are available.
39
+ - `-f FORMATTER`, `--formatter FORMATTER`: Optional. `plain` in default. `ical` and `plain` are available.
40
+
41
+ ### API
42
+
43
+ You can deal with holidays in Denso Calendar in your code:
44
+
45
+ ```ruby
46
+ require 'denso/calendar'
47
+
48
+ calendar = Denso::Calendar.load # :production in default.
49
+
50
+ holidays = calendar.holidays # returns an Array of Date
51
+ ```
52
+
53
+ ## Development
54
+
55
+ 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.
56
+
57
+ 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).
58
+
59
+ ## Contributing
60
+
61
+ Bug reports and pull requests are welcome on GitHub at https://github.com/satoryu/denso-calendar. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/satoryu/denso-calendar/blob/master/CODE_OF_CONDUCT.md).
62
+
63
+
64
+ ## License
65
+
66
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
67
+
68
+ ## Code of Conduct
69
+
70
+ Everyone interacting in the Denso::Calendar project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/satoryu/denso-calendar/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "denso/calendar"
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
@@ -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,32 @@
1
+ require_relative 'lib/denso/calendar/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'denso-calendar'
5
+ spec.version = Denso::Calendar::VERSION
6
+ spec.authors = ['Tatsuya Sato']
7
+ spec.email = ['satoryu.1981@gmail.com']
8
+
9
+ spec.summary = 'A parser DENSO calendar'
10
+ spec.description = 'A parser DENSO calendar'
11
+ spec.homepage = 'https://github.com/satoryu/denso-calendar'
12
+ spec.license = 'MIT'
13
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.4.0')
14
+
15
+ spec.metadata['homepage_uri'] = spec.homepage
16
+ spec.metadata['source_code_uri'] = spec.homepage
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = 'exe'
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ['lib']
26
+
27
+ spec.add_dependency 'icalendar', '~> 2.6'
28
+ spec.add_dependency 'nokogiri', '~> 1.10'
29
+ spec.add_development_dependency 'rake', '~> 12.0'
30
+ spec.add_development_dependency 'rspec', '~> 3.0'
31
+ spec.add_development_dependency 'webmock', '~> 3.8'
32
+ end
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'denso/calendar/cli'
4
+
5
+ Denso::Calendar::Cli.run(ARGV)
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'denso/calendar'
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'denso/calendar/version'
4
+ require 'uri'
5
+ require 'date'
6
+ require 'nokogiri'
7
+ require 'net/http'
8
+
9
+ module Denso
10
+ class Calendar
11
+ URI = 'https://www.denso.com/jp/ja/about-us/calendar/'
12
+
13
+ # Your code goes here...
14
+
15
+ # Loads calendars from DENSO site
16
+ #
17
+ # @param type [Symbol] A calender type.
18
+ # @return [Array[Denso::Calendar]]
19
+ # @see Denso::Calendar::URI
20
+ def self.load(type = :production)
21
+ content = Net::HTTP.get(uri)
22
+ doc = Nokogiri::HTML(content)
23
+ tables = doc.xpath("//h2/a[@id='#{type}']/../../following-sibling::div[contains(@class, 'denso-calendar')][1]")
24
+
25
+ Calendar.new(tables)
26
+ end
27
+
28
+ def self.uri
29
+ @uri ||= ::URI.parse(URI)
30
+ end
31
+
32
+ attr_reader :holidays
33
+
34
+ def initialize(tables_doc)
35
+ @doc = tables_doc
36
+
37
+ parse
38
+ end
39
+
40
+ private
41
+
42
+ def parse
43
+ @holidays = []
44
+
45
+ @doc.xpath('.//table').each do |table|
46
+ caption = table.xpath('./caption/text()').to_s
47
+ m = caption.match(/(\d{4})年(\d{1,2})月/)
48
+ year = m[1].to_i
49
+ month = m[2].to_i
50
+
51
+ table.css('td.holiday').each do |element|
52
+ @holidays << Date.new(year, month, element.content.to_i)
53
+ end
54
+ end
55
+
56
+ @holidays
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'denso/calendar'
4
+ require 'denso/calendar/formatter'
5
+
6
+ module Denso
7
+ class Calendar
8
+ class Cli
9
+ def self.run(options)
10
+ new(options).run
11
+ end
12
+
13
+ attr_reader :options
14
+
15
+ def initialize(argv)
16
+ require 'optparse'
17
+ opt = OptionParser.new
18
+ opt.on('-t TYPE', '--type TYPE') { |v| v }
19
+ opt.on('-f FORMATTER', '--formatter FORMATTER') { |v| v }
20
+
21
+ @options = {}
22
+ opt.parse(argv, into: @options)
23
+ end
24
+
25
+ def run
26
+ calendar = Denso::Calendar.load(options[:type].to_sym)
27
+
28
+ formatter = load_formatter
29
+ puts formatter.format(calendar)
30
+ end
31
+
32
+ def load_formatter
33
+ formatter_type = options.fetch(:formatter, :plain)
34
+
35
+ require "denso/calendar/formatter/#{formatter_type}"
36
+ Denso::Calendar::Formatter.const_get(formatter_type.to_s.capitalize).new
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Denso
4
+ class Calendar
5
+ module Formatter
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Denso
4
+ class Calendar
5
+ module Formatter
6
+ class Ical
7
+ def format(calendar)
8
+ require 'icalendar'
9
+
10
+ cal = Icalendar::Calendar.new
11
+ calendar.holidays.each do |holiday|
12
+ cal.event do |e|
13
+ e.dtstart = Icalendar::Values::Date.new(holiday)
14
+ e.dtend = Icalendar::Values::Date.new(holiday)
15
+ end
16
+ end
17
+ cal.publish
18
+
19
+ cal.to_ical
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Denso
4
+ class Calendar
5
+ module Formatter
6
+ class Plain
7
+ def format(calendar)
8
+ out = StringIO.new
9
+ calendar.holidays.each do |holiday|
10
+ out.puts holiday
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,5 @@
1
+ module Denso
2
+ class Calendar
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: denso-calendar
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tatsuya Sato
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-02-26 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.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '12.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '12.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.8'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.8'
83
+ description: A parser DENSO calendar
84
+ email:
85
+ - satoryu.1981@gmail.com
86
+ executables:
87
+ - denso-calendar
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - CODE_OF_CONDUCT.md
95
+ - Gemfile
96
+ - Gemfile.lock
97
+ - LICENSE.txt
98
+ - README.md
99
+ - Rakefile
100
+ - bin/console
101
+ - bin/setup
102
+ - denso-calendar.gemspec
103
+ - exe/denso-calendar
104
+ - lib/denso-calendar.rb
105
+ - lib/denso/calendar.rb
106
+ - lib/denso/calendar/cli.rb
107
+ - lib/denso/calendar/formatter.rb
108
+ - lib/denso/calendar/formatter/ical.rb
109
+ - lib/denso/calendar/formatter/plain.rb
110
+ - lib/denso/calendar/version.rb
111
+ homepage: https://github.com/satoryu/denso-calendar
112
+ licenses:
113
+ - MIT
114
+ metadata:
115
+ homepage_uri: https://github.com/satoryu/denso-calendar
116
+ source_code_uri: https://github.com/satoryu/denso-calendar
117
+ post_install_message:
118
+ rdoc_options: []
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: 2.4.0
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ requirements: []
132
+ rubygems_version: 3.1.2
133
+ signing_key:
134
+ specification_version: 4
135
+ summary: A parser DENSO calendar
136
+ test_files: []