denso-calendar 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3c7c33a85c6764a7fdca6d91f6a0cfe958a21a4d5c3a3e782fa9b0b0c0ee03a5
4
- data.tar.gz: d1bcda50e70edff6a53b166796e9818e523848cecb1897f71155103e7eb76837
3
+ metadata.gz: 8e5d414803855db1443a7a9a43b61b5d3faeec684a841a5acdb310eda9084749
4
+ data.tar.gz: 05fcf9bc1298cbf869e988f6a18f262a291b2dd76e5b0fcb12e00af13ec6879b
5
5
  SHA512:
6
- metadata.gz: 5dc68733a82f18c6fba78fd6fe7ebeed956d9338eed69758c91131e1deba568532e21a3b0e24ec906c63a3aa5ef84a264ea0a9f2769de19b83b3111564eb91c9
7
- data.tar.gz: 2a4a904f8b798def8ed7fc596a7d23df5b24ff52ce690f67752ef6dc00b011bdce36a2075762d25a72c0df4fb392c05125b6bce21bba8d07e724f818027a8285
6
+ metadata.gz: eed69658f6a8b4b2d34218b890197aba4a63527c1fc83c573d0f39df7699845b40ee8edae8da7d20b3f79b63c6657806086a679c34a10ff2ada072b6d6bb0e84
7
+ data.tar.gz: 002fee53742edb6cbf7b1193c2cd10c5333fdd2be1a71556af5098d65a4a744987a89b9308ef5be8ce6ac8ce386ebfe056db94aa5c12b0650edb9c4181b97f40
@@ -0,0 +1,12 @@
1
+ # These are supported funding model platforms
2
+
3
+ github: [satoryu] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4
+ patreon: # Replace with a single Patreon username
5
+ open_collective: # Replace with a single Open Collective username
6
+ ko_fi: # Replace with a single Ko-fi username
7
+ tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8
+ community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9
+ liberapay: # Replace with a single Liberapay username
10
+ issuehunt: # Replace with a single IssueHunt username
11
+ otechie: # Replace with a single Otechie username
12
+ custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
@@ -0,0 +1,62 @@
1
+ name: CI/CD
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ pull_request:
8
+ types: [opened, synchronize]
9
+
10
+ jobs:
11
+ build:
12
+ runs-on: ubuntu-latest
13
+ strategy:
14
+ matrix:
15
+ ruby-version:
16
+ - 2.6
17
+ - 2.7
18
+ name: Ruby ${{ matrix.ruby }}
19
+ steps:
20
+ - uses: actions/checkout@v2
21
+ - uses: actions/setup-ruby@v1
22
+ with:
23
+ ruby-version: ${{ matrix.ruby-version }}
24
+ - uses: actions/cache@v1
25
+ with:
26
+ path: vendor/bundle
27
+ key: ${{ runner.os }}-${{ matrix.ruby-version }}-gems-${{ hashFiles('**/Gemfile.lock') }}
28
+ restore-keys: ${{ runner.os }}-${{ matrix.ruby-version }}-gems-
29
+ - run: |
30
+ gem install bundler
31
+ bundle config path vendor/bundle
32
+ bundle install
33
+ bundle exec rake
34
+
35
+ build_gh-page:
36
+ name: Build gh-page
37
+ needs: build
38
+ if: github.event_name == 'push'
39
+ runs-on: ubuntu-latest
40
+ steps:
41
+ - uses: actions/checkout@v2
42
+ - uses: actions/setup-ruby@v1
43
+ with:
44
+ ruby-version: 2.7
45
+ - uses: actions/cache@v1
46
+ with:
47
+ path: vendor/bundle
48
+ key: ${{ runner.os }}-2.7-gems-${{ hashFiles('**/Gemfile.lock') }}
49
+ restore-keys: ${{ runner.os }}-2.7-gems-
50
+ - run: |
51
+ gem install bundler
52
+ gem install yard
53
+ yardoc
54
+ bundle config path vendor/bundle
55
+ bundle install
56
+ bundle exec denso-calendar --type tokyo -f ical > doc/tokyo.ics
57
+ bundle exec denso-calendar --type production -f ical > doc/production.ics
58
+ bundle exec denso-calendar --type flex -f ical > doc/flex.ics
59
+ - uses: maxheld83/ghpages@v0.3.0
60
+ env:
61
+ BUILD_DIR: doc
62
+ GH_PAT: ${{ secrets.GH_PAT }}
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- denso-calendar (0.1.0)
4
+ denso-calendar (0.2.0)
5
5
  icalendar (~> 2.6)
6
6
  nokogiri (~> 1.10)
7
7
 
@@ -18,7 +18,7 @@ GEM
18
18
  ice_cube (~> 0.16)
19
19
  ice_cube (0.16.3)
20
20
  mini_portile2 (2.4.0)
21
- nokogiri (1.10.8)
21
+ nokogiri (1.10.10)
22
22
  mini_portile2 (~> 2.4.0)
23
23
  public_suffix (4.0.3)
24
24
  rake (12.3.3)
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Denso::Calendar
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/denso-calendar.svg)](https://badge.fury.io/rb/denso-calendar)
4
+ ![CI/CD](https://github.com/satoryu/denso-calendar/workflows/CI/CD/badge.svg)
5
+
3
6
  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
7
 
5
8
  ## Installation
@@ -33,11 +36,21 @@ You can see all holidays for a specific employee type as follows:
33
36
  desnso-calendar --type production
34
37
  ```
35
38
 
36
- ### Options
39
+ #### Options
37
40
 
38
41
  - `-t TYPE`, `--type TYPE`: Optional. `production` in default. `production`, `tokyo` and `flex` are available.
39
42
  - `-f FORMATTER`, `--formatter FORMATTER`: Optional. `plain` in default. `ical` and `plain` are available.
40
43
 
44
+ #### Generated ics files
45
+
46
+ You can get samples of ics files generated by the latest version of the cli:
47
+
48
+ - https://satoryu.github.io/denso-calendar/production.ics
49
+ - https://satoryu.github.io/denso-calendar/flex.ics
50
+ - https://satoryu.github.io/denso-calendar/tokyo.ics
51
+
52
+ You can import the above to your calendar/scheduling software like Outlook :calendar:
53
+
41
54
  ### API
42
55
 
43
56
  You can deal with holidays in Denso Calendar in your code:
@@ -50,6 +63,8 @@ calendar = Denso::Calendar.load # :production in default.
50
63
  holidays = calendar.holidays # returns an Array of Date
51
64
  ```
52
65
 
66
+ [Read more...](https://satoryu.github.io/denso-calendar/)
67
+
53
68
  ## Development
54
69
 
55
70
  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.
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.description = 'A parser DENSO calendar'
11
11
  spec.homepage = 'https://github.com/satoryu/denso-calendar'
12
12
  spec.license = 'MIT'
13
- spec.required_ruby_version = Gem::Requirement.new('>= 2.4.0')
13
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.6.0')
14
14
 
15
15
  spec.metadata['homepage_uri'] = spec.homepage
16
16
  spec.metadata['source_code_uri'] = spec.homepage
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'denso/calendar/version'
4
+ require 'denso/calendar/date'
4
5
  require 'uri'
5
- require 'date'
6
6
  require 'nokogiri'
7
7
  require 'net/http'
8
8
 
@@ -29,7 +29,8 @@ module Denso
29
29
  @uri ||= ::URI.parse(URI)
30
30
  end
31
31
 
32
- attr_reader :holidays
32
+ # @return [Array[Denso::Calendar::Date]]
33
+ attr_reader :days
33
34
 
34
35
  def initialize(tables_doc)
35
36
  @doc = tables_doc
@@ -37,10 +38,26 @@ module Denso
37
38
  parse
38
39
  end
39
40
 
41
+ # Returns all business days in the Calendar
42
+ #
43
+ # @return [Array[Denso::Calendar::Date]]
44
+ # @see Denso::Calendar::Date#business_day?
45
+ def business_days
46
+ @business_days ||= days.select(&:business_day?)
47
+ end
48
+
49
+ # Returns all holidays in the Calendar
50
+ #
51
+ # @return [Array[Denso::Calendar::Date]]
52
+ # @see Denso::Calendar::Date#holiday?
53
+ def holidays
54
+ @holidays ||= days.select(&:holiday?)
55
+ end
56
+
40
57
  private
41
58
 
42
59
  def parse
43
- @holidays = []
60
+ @days = []
44
61
 
45
62
  @doc.xpath('.//table').each do |table|
46
63
  caption = table.xpath('./caption/text()').to_s
@@ -48,12 +65,15 @@ module Denso
48
65
  year = m[1].to_i
49
66
  month = m[2].to_i
50
67
 
51
- table.css('td.holiday').each do |element|
52
- @holidays << Date.new(year, month, element.content.to_i)
68
+ table.css('td').each do |element|
69
+ day = element.content
70
+ next if day !~ /\A\d+\Z/
71
+
72
+ holiday = element['class'] && element['class'].include?('holiday')
73
+
74
+ @days << Denso::Calendar::Date.new(year, month, day.to_i, holiday: holiday)
53
75
  end
54
76
  end
55
-
56
- @holidays
57
77
  end
58
78
  end
59
79
  end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'date'
4
+
5
+ module Denso
6
+ class Calendar
7
+ class Date < ::Date
8
+ def initialize(*args)
9
+ options = args.last.is_a?(Hash) ? args.pop : { holiday: true }
10
+ super(*args)
11
+
12
+ @holiday = options[:holiday]
13
+ end
14
+
15
+ # Returns true if the day is holiday
16
+ #
17
+ # @return [Boolean]
18
+ # @see #business_day?
19
+ def holiday?
20
+ @holiday
21
+ end
22
+
23
+ # Returns true if the day is business day, meaning not holiday
24
+ #
25
+ # @return [Boolean]
26
+ # @see #holiday?
27
+ def business_day?
28
+ !holiday?
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,5 +1,5 @@
1
1
  module Denso
2
2
  class Calendar
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: denso-calendar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tatsuya Sato
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-02-26 00:00:00.000000000 Z
11
+ date: 2020-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: icalendar
@@ -88,6 +88,8 @@ executables:
88
88
  extensions: []
89
89
  extra_rdoc_files: []
90
90
  files:
91
+ - ".github/FUNDING.yml"
92
+ - ".github/workflows/main.yml"
91
93
  - ".gitignore"
92
94
  - ".rspec"
93
95
  - ".travis.yml"
@@ -104,6 +106,7 @@ files:
104
106
  - lib/denso-calendar.rb
105
107
  - lib/denso/calendar.rb
106
108
  - lib/denso/calendar/cli.rb
109
+ - lib/denso/calendar/date.rb
107
110
  - lib/denso/calendar/formatter.rb
108
111
  - lib/denso/calendar/formatter/ical.rb
109
112
  - lib/denso/calendar/formatter/plain.rb
@@ -114,7 +117,7 @@ licenses:
114
117
  metadata:
115
118
  homepage_uri: https://github.com/satoryu/denso-calendar
116
119
  source_code_uri: https://github.com/satoryu/denso-calendar
117
- post_install_message:
120
+ post_install_message:
118
121
  rdoc_options: []
119
122
  require_paths:
120
123
  - lib
@@ -122,7 +125,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
122
125
  requirements:
123
126
  - - ">="
124
127
  - !ruby/object:Gem::Version
125
- version: 2.4.0
128
+ version: 2.6.0
126
129
  required_rubygems_version: !ruby/object:Gem::Requirement
127
130
  requirements:
128
131
  - - ">="
@@ -130,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
133
  version: '0'
131
134
  requirements: []
132
135
  rubygems_version: 3.1.2
133
- signing_key:
136
+ signing_key:
134
137
  specification_version: 4
135
138
  summary: A parser DENSO calendar
136
139
  test_files: []