r_calendar 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
+ SHA256:
3
+ metadata.gz: 710b51cee8311d095ec6c005f5f95c483b79f8743e936d4cc610221e5dca7224
4
+ data.tar.gz: 9dc775dbd47f025b4f018198b790e90c84a87f20e34dede63a95658ff2d47501
5
+ SHA512:
6
+ metadata.gz: 2001633b09fdfa4217ca6a1de948badc613dda203f102d5aae261a758ece51c39675c54beaf274a27e2865015c270cb26009144ec7cb33f37625cd42f752052b
7
+ data.tar.gz: edd253f6c7fd840d46a831377d64177420f93cb1c2ac23e353012662b0970ed3b8054b81844bdff7b19b4439d4063f04303338ccbbf5e0f752429c678a2c890d
data/.gitignore ADDED
@@ -0,0 +1,18 @@
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
+ gem_test
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in r_calendar.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Kenji Ohtsuka
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,42 @@
1
+ # RCalendar
2
+
3
+ calendar written in ruby
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'r_calendar'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install r_calendar
18
+
19
+ ## Usage
20
+
21
+ ### For 1 year calendar
22
+
23
+ ```ruby
24
+ 2.5.1 :002 > RCalendar.calendar(2018)
25
+ => [[[nil, 1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12, 13], [14, 15, 16, 17, 18, 19, 20], [21, 22, 23, 24, 25, 26, 27], [28, 29, 30, 31, nil, nil, nil]], [[nil, nil, nil, nil, 1, 2, 3], [4, 5, 6, 7, 8, 9, 10], [11, 12, 13, 14, 15, 16, 17], [18, 19, 20, 21, 22, 23, 24], [25, 26, 27, 28, nil, nil, nil]], [[nil, nil, nil, nil, 1, 2, 3], [4, 5, 6, 7, 8, 9, 10], [11, 12, 13, 14, 15, 16, 17], [18, 19, 20, 21, 22, 23, 24], [25, 26, 27, 28, 29, 30, 31]], [[1, 2, 3, 4, 5, 6, 7], [8, 9, 10, 11, 12, 13, 14], [15, 16, 17, 18, 19, 20, 21], [22, 23, 24, 25, 26, 27, 28], [29, 30, nil, nil, nil, nil, nil]], [[nil, nil, 1, 2, 3, 4, 5], [6, 7, 8, 9, 10, 11, 12], [13, 14, 15, 16, 17, 18, 19], [20, 21, 22, 23, 24, 25, 26], [27, 28, 29, 30, 31, nil, nil]], [[nil, nil, nil, nil, nil, 1, 2], [3, 4, 5, 6, 7, 8, 9], [10, 11, 12, 13, 14, 15, 16], [17, 18, 19, 20, 21, 22, 23], [24, 25, 26, 27, 28, 29, 30]], [[1, 2, 3, 4, 5, 6, 7], [8, 9, 10, 11, 12, 13, 14], [15, 16, 17, 18, 19, 20, 21], [22, 23, 24, 25, 26, 27, 28], [29, 30, 31, nil, nil, nil, nil]], [[nil, nil, nil, 1, 2, 3, 4], [5, 6, 7, 8, 9, 10, 11], [12, 13, 14, 15, 16, 17, 1 8], [19, 20, 21, 22, 23, 24, 25], [26, 27, 28, 29, 30, 31, nil]], [[nil, nil, nil, nil, nil, nil, 1], [2, 3, 4, 5, 6, 7, 8], [9, 10, 11, 12, 13, 14, 15], [16, 17, 18, 19, 20, 21, 22], [23, 24, 25, 26, 27, 28, 29], [30, nil, nil, nil, nil, nil, nil]], [[nil, 1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12, 13], [14, 15, 16, 17, 18, 19, 20], [21, 22, 23, 24, 25, 26, 27], [28, 29, 30, 31, nil, nil, nil]], [[nil, nil, nil, nil, 1, 2, 3], [4, 5, 6, 7, 8, 9, 10], [11, 12, 13, 14, 15, 16, 17], [18, 19, 20, 21, 22, 23, 24], [25, 26, 27, 28, 29, 30, nil]], [[nil, nil, nil, nil, nil, nil, 1], [2, 3, 4, 5, 6, 7, 8], [9, 10, 11, 12, 13, 14, 15], [16, 17, 18, 19, 20, 21, 22], [23, 24, 25, 26, 27, 28, 29], [30, 31, nil, nil, nil, nil, nil]]]
26
+ ```
27
+
28
+ ### For 1 month calendar
29
+
30
+ ```
31
+ 2.5.1 :003 > RCalendar.calendar(2018, 1)
32
+ => [[nil, 1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12, 13], [14, 15, 16, 17, 18, 19, 20], [21, 22, 23, 24, 25, 26, 27], [28, 29, 30, 31, nil, nil, nil]]
33
+ ```
34
+
35
+
36
+ ## Contributing
37
+
38
+ 1. Fork it
39
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
40
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
41
+ 4. Push to the branch (`git push origin my-new-feature`)
42
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,43 @@
1
+ <%#
2
+ available local variables
3
+ year_number: a page object for the currently displayed page
4
+ month_number: total number of pages
5
+ %>
6
+
7
+ <%weekday_names = ['日', '月', '火', '水', '木', '金', '土']%>
8
+ <%
9
+ begin_day = Date.new(year_number, month_number, 1)
10
+ begin_weekday = begin_day.wday
11
+ end_day_number = begin_day.end_of_month.day
12
+ %>
13
+ <table class="grid">
14
+ <caption><%=month_number%>月</caption>
15
+ <thead>
16
+ <tr>
17
+ <%weekday_names.each{|wn|%>
18
+ <th><%=wn%></th>
19
+ <%}%>
20
+ </tr>
21
+ </thead>
22
+ <tbody>
23
+ <%day_number = 0%>
24
+ <%while day_number < end_day_number%>
25
+ <tr>
26
+ <%weekday_names.each_with_index do |wn, index|%>
27
+ <%
28
+ if day_number > 0
29
+ if day_number <= end_day_number
30
+ day_number += 1
31
+ end
32
+ else
33
+ if begin_weekday == index
34
+ day_number += 1
35
+ end
36
+ end
37
+ %>
38
+ <td><%=day_number%></td>
39
+ <%end%>
40
+ </tr>
41
+ <%end%>
42
+ </tbody>
43
+ </table>
@@ -0,0 +1,10 @@
1
+ <div>
2
+ <ul class="monthly_calendar">
3
+ <%weekday_names = ['日', '月', '火', '水', '木', '金', '土']%>
4
+ <%closed_days = @result.map{|r| r.date}%>
5
+ <%for month_number in 1..12 do%>
6
+ <li>
7
+ <%=render '_a_month.html.erb', :year_number => year_number, :month_number => month_number%>
8
+ </li>
9
+ <%end%>
10
+ </ul>
@@ -0,0 +1,3 @@
1
+ module RCalendar
2
+ VERSION = "0.0.1"
3
+ end
data/lib/r_calendar.rb ADDED
@@ -0,0 +1,64 @@
1
+ require 'date'
2
+ begin
3
+ require 'action_view'
4
+ require 'active_support'
5
+ rescue LoadError
6
+ rescue
7
+ end
8
+ require "r_calendar/version"
9
+
10
+ module RCalendar
11
+ def self.calendar(year, month = nil)
12
+ if month.nil?
13
+ c = []
14
+ (1..12).each do |m|
15
+ c << month_calendar(year, m)
16
+ end
17
+ return c
18
+ end
19
+ return month_calendar year, month
20
+ end
21
+
22
+ def self.month_calendar(year, month)
23
+ begin_day = Date.new(year, month, 1)
24
+ begin_weekday = begin_day.wday
25
+ end_day_number = (begin_day.next_month - 1).day
26
+
27
+ day_number = - begin_weekday
28
+ c = []
29
+ while day_number < end_day_number
30
+ w = []
31
+ (0..6).each do |wday|
32
+ day_number += 1
33
+ if day_number <= 0
34
+ w << nil
35
+ next
36
+ end
37
+ if day_number > end_day_number
38
+ w << nil
39
+ next
40
+ end
41
+ w << day_number
42
+ end
43
+ c << w
44
+ end
45
+ return c
46
+ end
47
+
48
+ module ActionViewExtension
49
+ # Your code goes here...
50
+ def yearly_calendar(year_number, options = {})
51
+ render '../app/views/r_calendar/_a_year.html.erb', :year_number => year_number
52
+ end
53
+
54
+ def monthly_calendar(year_number, month_number, options = {})
55
+ render '../app/views/r_calendar/_a_month.html.erb', :year_number => year_number, :month_number => month_number
56
+ end
57
+ end
58
+ end
59
+
60
+ if defined?(ActiveSupport)
61
+ ActiveSupport.on_load(:action_view) do
62
+ ::ActionView::Base.send :include, RCalendar::ActionViewExtension
63
+ end
64
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'r_calendar/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "r_calendar"
8
+ spec.version = RCalendar::VERSION
9
+ spec.authors = ["Kenji Ohtsuka"]
10
+ spec.email = ["kok.fdcm@gmail.com"]
11
+ #spec.description = %q{s}
12
+ spec.summary = %q{script to generate calendar array}
13
+ spec.homepage = ""
14
+ spec.license = "GPL-3.0"
15
+
16
+ spec.files = `git ls-files`.split($/)
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.3"
22
+ spec.add_development_dependency "rake"
23
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: r_calendar
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kenji Ohtsuka
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-07-25 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
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
+ description:
42
+ email:
43
+ - kok.fdcm@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - app/views/r_calendar/_a_month.html.erb
54
+ - app/views/r_calendar/_a_year.html.erb
55
+ - lib/generators/r_calendar/views_generator.rb
56
+ - lib/r_calendar.rb
57
+ - lib/r_calendar/version.rb
58
+ - r_calendar.gemspec
59
+ homepage: ''
60
+ licenses:
61
+ - GPL-3.0
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.7.7
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: script to generate calendar array
83
+ test_files: []