calendario 0.1.0 → 0.2.0
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 +4 -4
- data/.overcommit.yml +2 -0
- data/CHANGELOG.md +10 -0
- data/README.md +7 -7
- data/lib/calendario/calendar.rb +1 -1
- data/lib/calendario/month.rb +1 -1
- data/lib/calendario/rendered_month.rb +75 -0
- data/lib/calendario/rendered_year.rb +66 -0
- data/lib/calendario/renderers/month_renderer.rb +120 -0
- data/lib/calendario/renderers/year_renderer.rb +44 -108
- data/lib/calendario/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89a09aa1117a1ad2bac868c40efd513e14fb6de0fb7d5954956af9c2071b9c8d
|
4
|
+
data.tar.gz: 003dabc70ca610796204de8ec3efad4357ec75090b352b6c7a20d7e72476be73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1fd1c4568c21d9278bdcadf849ab13bdd4b83cb5b9be5a84a741c6ab7e3097b71500a598758b4f7ca8e0f42d5d96c1692f7d534c49789b6dafd0dbd9320181cc
|
7
|
+
data.tar.gz: 8e23336cd1bbc7aef8317374464b7cb7e701ebcd4d5665911d36ae4bdc3391dd51e791e48713339963575da7780db6ddfae65b630e2ed123c10eae1ad2d21467
|
data/.overcommit.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -4,9 +4,19 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
5
5
|
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
+
## [0.2.0] - 2020-06-29
|
8
|
+
### Changed
|
9
|
+
- Split the year rendering into 4 classes: `YearRenderer`, `RenderedYear`, `MonthRenderer` and `RenderedMonth`
|
10
|
+
- Refactored the renderers to remove magic strings and numbers
|
11
|
+
- Refactored the renderers to create the basis for different column layouts
|
12
|
+
|
13
|
+
### Fixed
|
14
|
+
- Fixed the usage documentation
|
15
|
+
|
7
16
|
## [0.1.0] - 2020-06-25
|
8
17
|
### Added
|
9
18
|
- Initial core functionality
|
10
19
|
- Codebase maintenance tools
|
11
20
|
|
21
|
+
[0.2.0]: https://github.com/wilsonsilva/tuga/compare/v0.1.0...v0.2.0
|
12
22
|
[0.1.0]: https://github.com/wilsonsilva/tuga/compare/15adab8...v0.1.0
|
data/README.md
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# Calendario
|
2
2
|
|
3
|
-
[](https://badge.fury.io/rb/calendario)
|
4
|
+
[](https://travis-ci.org/wilsonsilva/calendario)
|
5
|
+
[](https://codeclimate.com/github/wilsonsilva/calendario/maintainability)
|
6
|
+
[](https://codeclimate.com/github/wilsonsilva/calendario/test_coverage)
|
7
|
+
[](https://hakiri.io/github/wilsonsilva/calendario/master)
|
8
|
+
[](http://inch-ci.org/github/wilsonsilva/calendario)
|
9
9
|
|
10
10
|
A cal-like calendar.
|
11
11
|
|
@@ -75,7 +75,7 @@ You can also customize what to display on each day. For example, this code wil d
|
|
75
75
|
```ruby
|
76
76
|
calendar = Calendario::Calendar.new
|
77
77
|
rendered_calendar = calendar.render_current_year do |date|
|
78
|
-
if date.wday == 5 ||
|
78
|
+
if date.wday == 5 || date.wday == 6
|
79
79
|
'WE'
|
80
80
|
else
|
81
81
|
date.day.to_s.rjust(2)
|
data/lib/calendario/calendar.rb
CHANGED
data/lib/calendario/month.rb
CHANGED
@@ -36,7 +36,7 @@ module Calendario
|
|
36
36
|
# @param [Integer] year_number The primitive numeric representation of a year
|
37
37
|
# @param [Integer] month_number The month's number from 1 to 12
|
38
38
|
#
|
39
|
-
def initialize(year_number
|
39
|
+
def initialize(year_number, month_number)
|
40
40
|
@year_number = year_number
|
41
41
|
@month_number = month_number
|
42
42
|
@days = (first_day..last_day).to_a
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module Calendario
|
2
|
+
# A cal-like representation of a month:
|
3
|
+
#
|
4
|
+
# January
|
5
|
+
# Su Mo Tu We Th Fr Sa
|
6
|
+
# 1 2 3 4
|
7
|
+
# 5 6 7 8 9 10 11
|
8
|
+
# 12 13 14 15 16 17 18
|
9
|
+
# 19 20 21 22 23 24 25
|
10
|
+
# 26 27 28 29 30 31
|
11
|
+
#
|
12
|
+
class RenderedMonth
|
13
|
+
# A list of lines representing a month. The month name, the weekday initials and 4 to 5 lines of weeks
|
14
|
+
#
|
15
|
+
# @api private
|
16
|
+
# @return [Array<String>]
|
17
|
+
#
|
18
|
+
attr_reader :lines
|
19
|
+
|
20
|
+
# Initializes a rendered month
|
21
|
+
#
|
22
|
+
# @api private
|
23
|
+
# @param [Array<String>] lines List of lines representing a month. The month name, the weekday
|
24
|
+
# initials and 4 to 5 lines of weeks
|
25
|
+
#
|
26
|
+
def initialize(lines)
|
27
|
+
@lines = lines
|
28
|
+
end
|
29
|
+
|
30
|
+
# Returns the textual representation of a month
|
31
|
+
#
|
32
|
+
# @api private
|
33
|
+
# @return [String]
|
34
|
+
#
|
35
|
+
def to_s
|
36
|
+
lines.join("\n")
|
37
|
+
end
|
38
|
+
|
39
|
+
# The centered name of the month
|
40
|
+
#
|
41
|
+
# @api private
|
42
|
+
# @return [String]
|
43
|
+
#
|
44
|
+
def name
|
45
|
+
lines[0]
|
46
|
+
end
|
47
|
+
|
48
|
+
# The list of weekday initials (Su Mo Tu We Th Fr Sa)
|
49
|
+
#
|
50
|
+
# @api private
|
51
|
+
# @return [String]
|
52
|
+
#
|
53
|
+
def weekdays
|
54
|
+
lines[1]
|
55
|
+
end
|
56
|
+
|
57
|
+
# Returns 4 or 5 rows of weeks
|
58
|
+
#
|
59
|
+
# @api private
|
60
|
+
# @return [Array<String>]
|
61
|
+
#
|
62
|
+
def weeks
|
63
|
+
lines[2..-1]
|
64
|
+
end
|
65
|
+
|
66
|
+
# Finds one or more lines of the rendered month
|
67
|
+
#
|
68
|
+
# @api private
|
69
|
+
# @return [Array<String>]
|
70
|
+
#
|
71
|
+
def [](index)
|
72
|
+
lines.public_send(:[], index)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Calendario
|
2
|
+
# A cal-like representation of a year:
|
3
|
+
#
|
4
|
+
# 2020
|
5
|
+
# January February March
|
6
|
+
# Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
|
7
|
+
# 1 2 3 4 1 1 2 3 4 5 6 7
|
8
|
+
# 5 6 7 8 9 10 11 2 3 4 5 6 7 8 8 9 10 11 12 13 14
|
9
|
+
# 12 13 14 15 16 17 18 9 10 11 12 13 14 15 15 16 17 18 19 20 21
|
10
|
+
# 19 20 21 22 23 24 25 16 17 18 19 20 21 22 22 23 24 25 26 27 28
|
11
|
+
# 26 27 28 29 30 31 23 24 25 26 27 28 29 29 30 31
|
12
|
+
#
|
13
|
+
#
|
14
|
+
# April May June
|
15
|
+
# Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
|
16
|
+
# 1 2 3 4 1 2 1 2 3 4 5 6
|
17
|
+
# 5 6 7 8 9 10 11 3 4 5 6 7 8 9 7 8 9 10 11 12 13
|
18
|
+
# 12 13 14 15 16 17 18 10 11 12 13 14 15 16 14 15 16 17 18 19 20
|
19
|
+
# 19 20 21 22 23 24 25 17 18 19 20 21 22 23 21 22 23 24 25 26 27
|
20
|
+
# 26 27 28 29 30 24 25 26 27 28 29 30 28 29 30
|
21
|
+
# 31
|
22
|
+
#
|
23
|
+
# July August September
|
24
|
+
# Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
|
25
|
+
# 1 2 3 4 1 1 2 3 4 5
|
26
|
+
# 5 6 7 8 9 10 11 2 3 4 5 6 7 8 6 7 8 9 10 11 12
|
27
|
+
# 12 13 14 15 16 17 18 9 10 11 12 13 14 15 13 14 15 16 17 18 19
|
28
|
+
# 19 20 21 22 23 24 25 16 17 18 19 20 21 22 20 21 22 23 24 25 26
|
29
|
+
# 26 27 28 29 30 31 23 24 25 26 27 28 29 27 28 29 30
|
30
|
+
# 30 31
|
31
|
+
#
|
32
|
+
# October November December
|
33
|
+
# Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
|
34
|
+
# 1 2 3 1 2 3 4 5 6 7 1 2 3 4 5
|
35
|
+
# 4 5 6 7 8 9 10 8 9 10 11 12 13 14 6 7 8 9 10 11 12
|
36
|
+
# 11 12 13 14 15 16 17 15 16 17 18 19 20 21 13 14 15 16 17 18 19
|
37
|
+
# 18 19 20 21 22 23 24 22 23 24 25 26 27 28 20 21 22 23 24 25 26
|
38
|
+
# 25 26 27 28 29 30 31 29 30 27 28 29 30 31
|
39
|
+
#
|
40
|
+
class RenderedYear
|
41
|
+
# A list of lines representing a year
|
42
|
+
#
|
43
|
+
# @api private
|
44
|
+
# @return [Array<String>]
|
45
|
+
#
|
46
|
+
attr_reader :lines
|
47
|
+
|
48
|
+
# Initializes a rendered year
|
49
|
+
#
|
50
|
+
# @api private
|
51
|
+
# @param [Array<String>] lines List of lines representing a year
|
52
|
+
#
|
53
|
+
def initialize(lines)
|
54
|
+
@lines = lines
|
55
|
+
end
|
56
|
+
|
57
|
+
# Returns the textual representation of a year
|
58
|
+
#
|
59
|
+
# @api private
|
60
|
+
# @return [String]
|
61
|
+
#
|
62
|
+
def to_s
|
63
|
+
lines.join("\n")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'calendario/month'
|
2
|
+
require 'calendario/rendered_month'
|
3
|
+
|
4
|
+
module Calendario
|
5
|
+
module Renderers
|
6
|
+
# Renders a month line by line
|
7
|
+
#
|
8
|
+
# @api private
|
9
|
+
#
|
10
|
+
class MonthRenderer
|
11
|
+
# The space of an empty day
|
12
|
+
# @return [String]
|
13
|
+
EMPTY_DAY_SPACES = ' '.freeze
|
14
|
+
|
15
|
+
# Initials of each week day
|
16
|
+
# @return [String]
|
17
|
+
WEEKDAY_INITIALS = 'Su Mo Tu We Th Fr Sa'.freeze
|
18
|
+
|
19
|
+
# Width of a rendered month
|
20
|
+
# @return [Integer]
|
21
|
+
MONTH_WIDTH = 20
|
22
|
+
|
23
|
+
# A proc to be executed on each date to define what is displayed on each day
|
24
|
+
#
|
25
|
+
# @api private
|
26
|
+
# @return [Proc]
|
27
|
+
#
|
28
|
+
attr_accessor :filter
|
29
|
+
|
30
|
+
# Initializes a month renderer
|
31
|
+
#
|
32
|
+
# @api private
|
33
|
+
#
|
34
|
+
def initialize
|
35
|
+
@filter = proc { |date| date.day.to_s.rjust(2) }
|
36
|
+
end
|
37
|
+
|
38
|
+
# Renders a month
|
39
|
+
#
|
40
|
+
# @api private
|
41
|
+
# @param [Month] month The month to be rendered
|
42
|
+
# @return [RenderedMonth]
|
43
|
+
#
|
44
|
+
def render(month)
|
45
|
+
weeks = build_weeks(month).map { |week| week.join(' ') }
|
46
|
+
|
47
|
+
lines = [
|
48
|
+
center_name(month),
|
49
|
+
WEEKDAY_INITIALS,
|
50
|
+
*weeks
|
51
|
+
]
|
52
|
+
|
53
|
+
RenderedMonth.new(lines)
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
# Builds all weeks in a month, applying a filter on every date
|
59
|
+
#
|
60
|
+
# @api private
|
61
|
+
# @param [Month] month The month containing the weeks
|
62
|
+
# @return [Array<Date|String>]
|
63
|
+
#
|
64
|
+
def build_weeks(month)
|
65
|
+
weeks = month.weeks
|
66
|
+
|
67
|
+
add_leading_spaces(month.weeks.first)
|
68
|
+
add_trailing_spaces(month.weeks.last)
|
69
|
+
|
70
|
+
weeks << [EMPTY_DAY_SPACES] * 7 if month.weeks.size == 5
|
71
|
+
weeks.map do |week|
|
72
|
+
week.map(&method(:apply_filter))
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# Applies a filter on a date or a blank space
|
77
|
+
#
|
78
|
+
# @api private
|
79
|
+
# @param [Date|String] date_or_string A date or a string to be parsed by a filter
|
80
|
+
# @return [Date|String]
|
81
|
+
#
|
82
|
+
def apply_filter(date_or_string)
|
83
|
+
date_or_string.is_a?(Date) ? filter.call(date_or_string) : date_or_string
|
84
|
+
end
|
85
|
+
|
86
|
+
# Prepends leading spaces in a week until the first day of the week is found
|
87
|
+
#
|
88
|
+
# @api private
|
89
|
+
# @param [Array<Date>] week A list of days in a week
|
90
|
+
# @return [void]
|
91
|
+
#
|
92
|
+
def add_leading_spaces(week)
|
93
|
+
first_day_is_sunday = week.first.wday.zero?
|
94
|
+
return if first_day_is_sunday
|
95
|
+
|
96
|
+
week.first.wday.times { week.unshift(EMPTY_DAY_SPACES) }
|
97
|
+
end
|
98
|
+
|
99
|
+
# Appends trailing spaces in a week until it has 7 items
|
100
|
+
#
|
101
|
+
# @api private
|
102
|
+
# @param [Array<Date>] week A list of days in a week
|
103
|
+
# @return [void]
|
104
|
+
#
|
105
|
+
def add_trailing_spaces(week)
|
106
|
+
(6 - week.last.wday).abs.times { week.push(EMPTY_DAY_SPACES) }
|
107
|
+
end
|
108
|
+
|
109
|
+
# Centers the month's name horizontally
|
110
|
+
#
|
111
|
+
# @api private
|
112
|
+
# @param [Month] month The month to be centered
|
113
|
+
# @return [String]
|
114
|
+
#
|
115
|
+
def center_name(month)
|
116
|
+
month.name.center(MONTH_WIDTH)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
@@ -1,147 +1,83 @@
|
|
1
|
-
require 'calendario/
|
1
|
+
require 'calendario/rendered_year'
|
2
|
+
require 'calendario/renderers/month_renderer'
|
2
3
|
|
3
4
|
module Calendario
|
4
5
|
module Renderers
|
5
|
-
#
|
6
|
+
# Renders a year, line by line, in a table of 3 columns by 4 rows
|
6
7
|
class YearRenderer
|
7
|
-
# The space of an empty day
|
8
|
-
|
8
|
+
# The space of an empty day
|
9
|
+
# @return [String]
|
10
|
+
EMPTY_DAY_SPACES = ' '.freeze
|
9
11
|
|
10
|
-
#
|
11
|
-
|
12
|
+
# Number of month columns to display
|
13
|
+
# @return [Integer]
|
14
|
+
NUMBER_OF_MONTH_COLUMNS = 3
|
12
15
|
|
13
|
-
#
|
14
|
-
#
|
15
|
-
# 2020 | Title, centered
|
16
|
-
# January February March | Names of months, centered
|
17
|
-
# Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa | Weekday initials
|
18
|
-
# 1 2 3 4 1 1 2 3 4 5 6 7 | Rows of weeks
|
19
|
-
# 5 6 7 8 9 10 11 2 3 4 5 6 7 8 8 9 10 11 12 13 14 |
|
20
|
-
# 12 13 14 15 16 17 18 9 10 11 12 13 14 15 15 16 17 18 19 20 21 |
|
21
|
-
# 19 20 21 22 23 24 25 16 17 18 19 20 21 22 22 23 24 25 26 27 28 |
|
22
|
-
# 26 27 28 29 30 31 23 24 25 26 27 28 29 29 30 31 | Add spaces after the last day of the
|
23
|
-
# | month until the first day of the week of
|
24
|
-
# | the month of the following month on the
|
25
|
-
# April May June | same row.
|
26
|
-
# Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa |
|
27
|
-
# 1 2 3 4 1 2 1 2 3 4 5 6 | Add spaces before the first day of the
|
28
|
-
# 5 6 7 8 9 10 11 3 4 5 6 7 8 9 7 8 9 10 11 12 13 | month unless it is a Sunday.
|
29
|
-
# 12 13 14 15 16 17 18 10 11 12 13 14 15 16 14 15 16 17 18 19 20 |
|
30
|
-
# 19 20 21 22 23 24 25 17 18 19 20 21 22 23 21 22 23 24 25 26 27 |
|
31
|
-
# 26 27 28 29 30 24 25 26 27 28 29 30 28 29 30 |
|
32
|
-
# 31 | Add spaces before a day on the second
|
33
|
-
# | or third month columns if the first or
|
34
|
-
# July August September | second columns month are empty.
|
35
|
-
# Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa |
|
36
|
-
# 1 2 3 4 1 1 2 3 4 5 |
|
37
|
-
# 5 6 7 8 9 10 11 2 3 4 5 6 7 8 6 7 8 9 10 11 12 |
|
38
|
-
# 12 13 14 15 16 17 18 9 10 11 12 13 14 15 13 14 15 16 17 18 19 |
|
39
|
-
# 19 20 21 22 23 24 25 16 17 18 19 20 21 22 20 21 22 23 24 25 26 |
|
40
|
-
# 26 27 28 29 30 31 23 24 25 26 27 28 29 27 28 29 30 |
|
41
|
-
# 30 31 |
|
42
|
-
# |
|
43
|
-
# October November December |
|
44
|
-
# Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa |
|
45
|
-
# 1 2 3 1 2 3 4 5 6 7 1 2 3 4 5 |
|
46
|
-
# 4 5 6 7 8 9 10 8 9 10 11 12 13 14 6 7 8 9 10 11 12 |
|
47
|
-
# 11 12 13 14 15 16 17 15 16 17 18 19 20 21 13 14 15 16 17 18 19 |
|
48
|
-
# 18 19 20 21 22 23 24 22 23 24 25 26 27 28 20 21 22 23 24 25 26 |
|
49
|
-
# 25 26 27 28 29 30 31 29 30 27 28 29 30 31 |
|
16
|
+
# Initializes a year renderer
|
50
17
|
#
|
51
18
|
# @api private
|
52
|
-
# @param [
|
53
|
-
# @return [String]
|
19
|
+
# @param [MonthRenderer] month_renderer A service to render a month line by line
|
54
20
|
#
|
55
|
-
def
|
56
|
-
|
57
|
-
|
58
|
-
# Display months in
|
59
|
-
year.months.each_slice(3).with_index do |group_of_3_months, month_row|
|
60
|
-
output << month_names_line(group_of_3_months)
|
61
|
-
output << weekdays_initials_line
|
62
|
-
|
63
|
-
# Display 6 rows of days. Each row is a week.
|
64
|
-
0.upto(5) do |week_number|
|
65
|
-
# Display
|
66
|
-
group_of_3_months.each_with_index do |month, index|
|
67
|
-
# Correct the position for the first date of the first week
|
68
|
-
output << EMPTY_DAY_SPACES * month.first_day.wday if week_number.zero?
|
69
|
-
|
70
|
-
# Display a complete row of week days
|
71
|
-
output << (month.weeks[week_number] || []).map do |date|
|
72
|
-
if block_given?
|
73
|
-
yield(date)
|
74
|
-
else
|
75
|
-
date.day.to_s.rjust(2)
|
76
|
-
end
|
77
|
-
end.join(' ') + ' '
|
78
|
-
|
79
|
-
# Correct the position for the first date of the following month
|
80
|
-
output << lead_space_after_last_day(month) if last_week_of_the_month?(month, week_number)
|
21
|
+
def initialize(month_renderer = MonthRenderer.new)
|
22
|
+
@month_renderer = month_renderer
|
23
|
+
end
|
81
24
|
|
82
|
-
|
83
|
-
|
84
|
-
|
25
|
+
# Formats a year, line by line, in a table of 3 columns by 4 rows
|
26
|
+
#
|
27
|
+
# @api private
|
28
|
+
# @param [Year] year The year to be rendered.
|
29
|
+
# @return [RenderedYear]
|
30
|
+
#
|
31
|
+
def render(year, &block)
|
32
|
+
month_renderer.filter = block if block_given?
|
85
33
|
|
86
|
-
|
87
|
-
|
88
|
-
end
|
34
|
+
lines = [center_year_number(year)]
|
35
|
+
rendered_months = render_months(year.months)
|
89
36
|
|
90
|
-
|
91
|
-
|
37
|
+
rendered_months.each_slice(NUMBER_OF_MONTH_COLUMNS) do |months|
|
38
|
+
0.upto(7) { |month_line| lines << take_row(month_line, months) }
|
39
|
+
lines.push('') # Separate rows of months
|
92
40
|
end
|
93
41
|
|
94
|
-
|
42
|
+
RenderedYear.new(lines)
|
95
43
|
end
|
96
44
|
|
97
45
|
private
|
98
46
|
|
99
|
-
#
|
100
|
-
#
|
101
|
-
# @api private
|
102
|
-
# @param [Month] month
|
103
|
-
# @return [String]
|
104
|
-
#
|
105
|
-
def lead_space_after_last_day(month)
|
106
|
-
EMPTY_DAY_SPACES * (6 - month.last_day.wday)
|
107
|
-
end
|
108
|
-
|
109
|
-
# Centers the year in the middle of the calendar
|
47
|
+
# A service to render a month line by line
|
110
48
|
#
|
111
49
|
# @api private
|
112
|
-
# @
|
113
|
-
# @return [String]
|
50
|
+
# @return [Calendario::Renderers::MonthRenderer]
|
114
51
|
#
|
115
|
-
|
116
|
-
year.year_number.to_s.center(61) + "\n"
|
117
|
-
end
|
52
|
+
attr_accessor :month_renderer
|
118
53
|
|
119
|
-
#
|
54
|
+
# Extracts a row from a group of months
|
120
55
|
#
|
121
56
|
# @api private
|
122
|
-
# @
|
123
|
-
# @return [String]
|
57
|
+
# @return [Array<String>]
|
124
58
|
#
|
125
|
-
def
|
126
|
-
|
59
|
+
def take_row(month_line, months)
|
60
|
+
months.map { |month| month[month_line] }.join(EMPTY_DAY_SPACES)
|
127
61
|
end
|
128
62
|
|
129
|
-
#
|
63
|
+
# Centers the year in the middle of the calendar
|
130
64
|
#
|
131
65
|
# @api private
|
66
|
+
# @param [Year] year The year to be displayed at the top of the calendar
|
132
67
|
# @return [String]
|
133
68
|
#
|
134
|
-
def
|
135
|
-
|
69
|
+
def center_year_number(year)
|
70
|
+
year.year_number.to_s.center(61)
|
136
71
|
end
|
137
72
|
|
138
|
-
#
|
73
|
+
# Renders a list of months
|
139
74
|
#
|
140
75
|
# @api private
|
141
|
-
# @
|
76
|
+
# @param [Array<Month>] months The list of months to be rendered
|
77
|
+
# @return [Array<RenderedMonth>]
|
142
78
|
#
|
143
|
-
def
|
144
|
-
|
79
|
+
def render_months(months)
|
80
|
+
months.map { |month| month_renderer.render(month) }
|
145
81
|
end
|
146
82
|
end
|
147
83
|
end
|
data/lib/calendario/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: calendario
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wilson Silva
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-06-
|
11
|
+
date: 2020-06-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler-audit
|
@@ -291,6 +291,9 @@ files:
|
|
291
291
|
- lib/calendario.rb
|
292
292
|
- lib/calendario/calendar.rb
|
293
293
|
- lib/calendario/month.rb
|
294
|
+
- lib/calendario/rendered_month.rb
|
295
|
+
- lib/calendario/rendered_year.rb
|
296
|
+
- lib/calendario/renderers/month_renderer.rb
|
294
297
|
- lib/calendario/renderers/year_renderer.rb
|
295
298
|
- lib/calendario/version.rb
|
296
299
|
- lib/calendario/year.rb
|