spok 1.0.0 → 1.1.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: 81c3ccce2886f257f49bbb8ddd91d8758594cc799eefd975e34c563f958bed71
4
- data.tar.gz: bfffef121638849c52dd3f25cb1712c1accc9bcf2288c2ad5077c3f9a2628045
3
+ metadata.gz: a19af02d276f5c0ac98d97658ebe07421f5fbacfd012fb74536af5b39547cc8f
4
+ data.tar.gz: 811ccc44e1dcf14ff6a8f7cb2fe1cf49b8a64d205c4c6a511a1f3a6054436713
5
5
  SHA512:
6
- metadata.gz: f4c39525eb0c22b85cdd4906f34f290c802dc4a27afc9aaa0a6f61858c3f29a49baf007e6ede03e3eed0993a30cfa9e24e3295af437a7f570df26d822785b7fe
7
- data.tar.gz: f39f10f38183cd427ddc579c09189daefdff7640cdd94e8796d5e2a9109fc2e7bbd2e66adf1762554a4e0fa03e148e779a555734d5fe3672fade587fa0e0a928
6
+ metadata.gz: 451e183abf5655749b8f6f6b317842e864484eec03a11b754682bcac96293c31e7b6c2f434b0feb297760fde31cd473269f5721b9d5dfce75c0310da421c1ef8
7
+ data.tar.gz: 9d558e1edbf7c05db5a5ff2f86f943af0983201b9a157977e67e9f9da0cd96064768cb64977dc3811ca47c89950d2a11de67ee35e91ca6971dccae8d19178870
@@ -3,5 +3,9 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project adheres to [Semantic Versioning](http://semver.org/).
5
5
 
6
+ ## [1.1.0] - 2018-10-02
7
+ - Add calendars for Canada, Costa Rica, Indonesia, Mexico, Netherlands, Poland, Portugal, Spain and Vietnam.
8
+ - Create configuration for defining a default calendar.
9
+
6
10
  ## [1.0.0] - 2018-09-14
7
11
  - First public release.
@@ -1,6 +1,27 @@
1
1
  ## Contributing to Spok
2
2
 
3
- Before contributing, please read our [Code of Conduct](https://github.com/magnetis/spok/blob/master/CODE_OF_CONDUCT.md) and [License](https://github.com/magnetis/spok/blob/master/LICENSE.txt).
3
+ Thank you for your interest in contributing to Spok! We want to encourage you
4
+ to contribute with documentation, bug reports, code and ideas.
5
+
6
+ Before contributing, please read our [Code of Conduct](CODE_OF_CONDUCT.md) and [License](LICENSE.txt).
7
+
8
+ ### Table of Contents
9
+
10
+ * [Documentation](#documentation)
11
+ * [Did you find a bug?](#did-you-find-a-bug)
12
+ * [Contributing with code](#contributing-with-code)
13
+ * [Contributing with ideas](#contributing-with-ideas)
14
+ * [Do you have questions about the source code?](#do-you-have-questions-about-the-source-code)
15
+
16
+
17
+ #### **Documentation**
18
+
19
+ The project uses the [RDoc tool](https://ruby.github.io/rdoc/) to generate documentation.
20
+ Spok uses the [TomDoc](http://tomdoc.org/) style for writing docs. You can read
21
+ the [existing docs](https://www.rubydoc.info/gems/spok/) for more information.
22
+
23
+ Documentation is a very important portion of software. We want to always improve
24
+ our communication using it.
4
25
 
5
26
  #### **Did you find a bug?**
6
27
 
@@ -8,6 +29,28 @@ Before contributing, please read our [Code of Conduct](https://github.com/magnet
8
29
 
9
30
  * If you're unable to find an open issue addressing the problem, [open a new one](https://github.com/magnetis/spok/issues/new). Please, be sure to include a **title and clear description**, as much relevant information as possible.
10
31
 
32
+ #### **Contributing with code**
33
+
34
+ To contribute with code you should follow these steps:
35
+
36
+ 1. Fork the project;
37
+ 2. Clone your fork using the project URL (git or https);
38
+ 3. Create a new branch to implement your functionality or code. This can be done with the command: `git checkout -b your-branch-name-here`;
39
+ 4. Make your changes and add a new commit with a clear message saying why this change is being made;
40
+ 5. Make sure the tests are passing. To run the tests use the command: `rake spec`;
41
+ 5. Push your code with the command: `git push -u origin your-branch-name-here`;
42
+ 6. Go to your fork page at Github;
43
+ 7. Open a new Pull request.
44
+
45
+ If you want ideas on what you can do, check the
46
+ [open issues](https://github.com/magnetis/spok/issues).
47
+
48
+ #### **Contributing with ideas**
49
+
50
+ To contribute with ideas you can
51
+ [open a new issue](https://github.com/magnetis/spok/issues/new). Please write a
52
+ clear description of your suggestion, along with motivations and examples.
53
+
11
54
  #### **Do you have questions about the source code?**
12
55
 
13
56
  * You can contact us on dev@magnetis.com.br
data/README.md CHANGED
@@ -1,6 +1,11 @@
1
1
  # Spok
2
2
 
3
- TODO: Write a gem description
3
+ By [Magnetis](https://magnetis.com.br)
4
+
5
+ [![Build Status](https://travis-ci.org/magnetis/spok.svg?branch=master)](https://travis-ci.org/magnetis/spok)
6
+
7
+ Spok is a tool for dealing with workdays and restdays in an easy way.
8
+ It also provides functionalities for working with periods of dates.
4
9
 
5
10
  ## Installation
6
11
 
@@ -18,7 +23,72 @@ Or install it yourself as:
18
23
 
19
24
  ## Usage
20
25
 
21
- TODO: Write usage instructions here
26
+ ### Dealing with workdays
27
+
28
+ You can use the `Spok::Workday` module to check if a date is either a restday or a workday:
29
+
30
+ ```ruby
31
+ require 'spok'
32
+
33
+ Spok::Workday.workday?(Date.new(2012, 12, 24))
34
+ # => true
35
+ ```
36
+
37
+ Spok also supports different calendars for checking if a date is a workday or a
38
+ restday
39
+
40
+ ```ruby
41
+ require 'spok'
42
+
43
+ Spok::Workday.workday?(Date.new(2012, 12, 24), calendar: :bovespa)
44
+ # => false
45
+ ```
46
+
47
+ If `calendar` is not informed, it will default to the `:brasil` calendar.
48
+
49
+ The available calendars are defined with `.yml` files [here](lib/spok/config/).
50
+
51
+ ### Working with periods of dates
52
+
53
+ Objects from the `Spok` class can be used to work with periods of dates. You can
54
+ initialize a new object passing the start and end date for your period to the
55
+ `new` method:
56
+
57
+ ```ruby
58
+ require 'spok'
59
+
60
+ period = Spok.new(Date.new(2018, 9, 14), Date.new(2018, 10, 14))
61
+ another_period = Spok.new(Date.today, Date.today + 10.days)
62
+ ```
63
+
64
+ You can also use the `Spok.parse` method to initialize a new object using a string:
65
+
66
+ ```ruby
67
+ require 'spok'
68
+
69
+ parsed_period = Spok.parse('20180901-20180903')
70
+ ```
71
+
72
+ With the object, you can check for all the workdays in that period of dates:
73
+
74
+ ```ruby
75
+ require 'spok'
76
+
77
+ period = Spok.new(Date.new(2018, 10, 10), Date.new(2018, 10, 14))
78
+ period.workdays
79
+ # => [Wed, 10 Oct 2018, Thu, 11 Oct 2018]
80
+ ```
81
+
82
+ ### Set default calendar
83
+ ```ruby
84
+ Spok.default_calendar = :bovespa
85
+ ```
86
+
87
+ ## Documentation
88
+
89
+ The complete documentation in the RDoc format is available here:
90
+
91
+ https://www.rubydoc.info/gems/spok
22
92
 
23
93
  ## Contributing
24
94
 
@@ -26,5 +96,5 @@ Please read our [Contributing](CONTRIBUTING.md) guide for more information.
26
96
 
27
97
  ## License
28
98
 
29
- This project is licensed under the terms of the Apache 2. Copyright 2014-2017 Magnetis http://www.magnetis.com.br
99
+ This project is licensed under the terms of the Apache 2. Copyright 2014-2018 Magnetis http://www.magnetis.com.br
30
100
  See the [LICENSE](LICENSE.txt) file for license rights and limitations (Apache 2).
@@ -1,13 +1,18 @@
1
- require "spok/version"
1
+ require 'spok/version'
2
2
  require 'spok/workday'
3
3
 
4
4
  # Public: Class responsible for dealing with periods of Dates, considering
5
5
  # workdays and restdays.
6
6
  class Spok
7
7
  # Internal: String specifying format for dates in the period.
8
- DATE_FORMAT = '%Y%m%d'
8
+ DATE_FORMAT = '%Y%m%d'.freeze
9
+
9
10
  attr_reader :start_date, :end_date
10
11
 
12
+ mattr_reader :default_calendar
13
+
14
+ @@default_calendar = :brasil
15
+
11
16
  # Public: Parses a string into a Spok.
12
17
  #
13
18
  # dates_string - String containing the start and end dates for a period of
@@ -28,10 +33,10 @@ class Spok
28
33
  start_date, end_date = dates_string.split('-')
29
34
 
30
35
  if start_date && end_date
31
- Spok.new(::Date.parse(start_date), ::Date.parse(end_date))
32
- else
33
- nil
36
+ return Spok.new(::Date.parse(start_date), ::Date.parse(end_date))
34
37
  end
38
+
39
+ nil
35
40
  end
36
41
 
37
42
  # Public: Initialize a Spok.
@@ -93,19 +98,19 @@ class Spok
93
98
  #
94
99
  # spok.workdays
95
100
  # # => [Mon, 02 Jan 2012, Tue, 03 Jan 2012]
96
- def workdays(calendar = :brasil)
101
+ def workdays(calendar = Spok.default_calendar)
97
102
  (@start_date..@end_date).to_a.delete_if{ |date| Workday.restday?(date, calendar: calendar) }
98
103
  end
99
104
 
100
105
  # Public: Returns a Spok containing the same dates in a different calendar.
101
106
  #
102
- # calendar - Symbol informing calendar for new Spok (default: :bovespa).
107
+ # calendar - Symbol informing calendar for new Spok (default: :brasil).
103
108
  #
104
109
  # Examples
105
110
  #
106
- # spok.to_calendar(:bovespa)
111
+ # spok.to_calendar(:brasil)
107
112
  # # => #<Spok:0x00007fbf122dba08 ...>
108
- def to_calendar(calendar = :bovespa)
113
+ def to_calendar(calendar = Spok.default_calendar)
109
114
  Spok.new(
110
115
  Workday.last_workday(@start_date, calendar: calendar),
111
116
  Workday.last_workday(@end_date, calendar: calendar)
@@ -169,18 +174,18 @@ class Spok
169
174
  # equal when they are both instances of Spok, and have the same start and
170
175
  # end dates.
171
176
  #
172
- # other_spok - Spok to be checked against.
177
+ # other - Spok to be checked against.
173
178
  #
174
179
  # Examples
175
180
  #
176
- # spok == other_spok
181
+ # spok == other
177
182
  # # => false
178
183
  #
179
184
  # Returns a boolean.
180
- def ==(other_spok)
181
- other_spok.class == self.class &&
182
- other_spok.start_date == @start_date &&
183
- other_spok.end_date == @end_date
185
+ def ==(other)
186
+ other.class == self.class &&
187
+ other.start_date == @start_date &&
188
+ other.end_date == @end_date
184
189
  end
185
190
 
186
191
  # Public: Returns a range containing the Dates in the Spok.
@@ -193,6 +198,12 @@ class Spok
193
198
  (@start_date..@end_date)
194
199
  end
195
200
 
201
+ class << self
202
+ def default_calendar=(calendar)
203
+ class_variable_set(:@@default_calendar, calendar)
204
+ end
205
+ end
206
+
196
207
  private
197
208
 
198
209
  def as_string(date)
@@ -204,10 +215,11 @@ class Spok
204
215
  end
205
216
 
206
217
  def validate!
207
- raise ArgumentError.new("Start date must be present.") unless @start_date
208
- raise ArgumentError.new("End date must be present.") unless @end_date
218
+ raise ArgumentError, 'Start date must be present.' unless @start_date
219
+ raise ArgumentError, 'End date must be present.' unless @end_date
220
+
209
221
  if @start_date > @end_date
210
- raise ArgumentError.new("End date (#{@end_date}) must be greater or equal to start date (#{@start_date})")
222
+ raise ArgumentError, "End date (#{@end_date}) must be greater or equal to start date (#{@start_date})"
211
223
  end
212
224
  end
213
225
  end
@@ -0,0 +1,246 @@
1
+ ---
2
+ canada:
3
+ - 1993-01-01
4
+ - 1993-04-09
5
+ - 1993-05-24
6
+ - 1993-07-01
7
+ - 1993-09-06
8
+ - 1993-10-11
9
+ - 1993-11-11
10
+ - 1993-12-24
11
+ - 1993-12-25
12
+ - 1994-01-01
13
+ - 1994-01-03
14
+ - 1994-04-01
15
+ - 1994-05-23
16
+ - 1994-07-01
17
+ - 1994-10-10
18
+ - 1994-11-11
19
+ - 1994-12-25
20
+ - 1994-12-26
21
+ - 1995-01-01
22
+ - 1995-01-02
23
+ - 1995-04-14
24
+ - 1995-05-22
25
+ - 1995-07-01
26
+ - 1995-09-04
27
+ - 1995-10-09
28
+ - 1995-11-11
29
+ - 1995-12-25
30
+ - 1996-01-01
31
+ - 1996-04-05
32
+ - 1996-05-20
33
+ - 1996-07-01
34
+ - 1996-09-02
35
+ - 1996-10-14
36
+ - 1996-11-11
37
+ - 1996-12-25
38
+ - 1997-01-01
39
+ - 1997-03-28
40
+ - 1997-05-19
41
+ - 1997-07-01
42
+ - 1997-09-01
43
+ - 1997-10-13
44
+ - 1997-11-11
45
+ - 1997-12-25
46
+ - 1998-01-01
47
+ - 1998-04-10
48
+ - 1998-05-18
49
+ - 1998-07-01
50
+ - 1998-09-07
51
+ - 1998-10-12
52
+ - 1998-11-11
53
+ - 1998-12-25
54
+ - 1999-01-01
55
+ - 1999-04-02
56
+ - 1999-05-24
57
+ - 1999-07-01
58
+ - 1999-09-06
59
+ - 1999-10-11
60
+ - 1999-11-11
61
+ - 1999-12-24
62
+ - 1999-12-25
63
+ - 2000-01-01
64
+ - 2000-03-03
65
+ - 2000-04-21
66
+ - 2000-05-22
67
+ - 2000-07-01
68
+ - 2000-09-04
69
+ - 2000-10-09
70
+ - 2000-11-11
71
+ - 2000-12-25
72
+ - 2001-01-01
73
+ - 2001-04-13
74
+ - 2001-05-21
75
+ - 2001-07-01
76
+ - 2001-07-02
77
+ - 2001-09-03
78
+ - 2001-10-08
79
+ - 2001-11-11
80
+ - 2001-11-12
81
+ - 2001-12-25
82
+ - 2002-01-01
83
+ - 2002-03-29
84
+ - 2002-05-20
85
+ - 2002-07-01
86
+ - 2002-09-02
87
+ - 2002-10-14
88
+ - 2002-11-11
89
+ - 2002-12-25
90
+ - 2003-01-01
91
+ - 2003-04-18
92
+ - 2003-05-19
93
+ - 2003-07-01
94
+ - 2003-09-01
95
+ - 2003-10-13
96
+ - 2003-11-11
97
+ - 2003-12-25
98
+ - 2004-01-01
99
+ - 2004-04-09
100
+ - 2004-05-24
101
+ - 2004-07-01
102
+ - 2004-10-11
103
+ - 2004-11-11
104
+ - 2004-12-24
105
+ - 2004-12-25
106
+ - 2005-01-01
107
+ - 2005-01-03
108
+ - 2005-03-25
109
+ - 2005-05-23
110
+ - 2005-07-01
111
+ - 2005-09-05
112
+ - 2005-10-10
113
+ - 2005-11-11
114
+ - 2005-12-25
115
+ - 2006-01-01
116
+ - 2006-01-02
117
+ - 2006-04-14
118
+ - 2006-05-22
119
+ - 2006-07-01
120
+ - 2006-09-04
121
+ - 2006-10-09
122
+ - 2006-11-11
123
+ - 2006-12-12
124
+ - 2007-01-01
125
+ - 2007-04-06
126
+ - 2007-05-21
127
+ - 2007-07-01
128
+ - 2007-07-02
129
+ - 2007-09-03
130
+ - 2007-10-08
131
+ - 2007-11-11
132
+ - 2007-11-12
133
+ - 2007-12-25
134
+ - 2008-01-01
135
+ - 2008-03-21
136
+ - 2008-05-19
137
+ - 2008-07-01
138
+ - 2008-09-01
139
+ - 2008-10-13
140
+ - 2008-11-11
141
+ - 2008-12-25
142
+ - 2009-01-01
143
+ - 2009-04-10
144
+ - 2009-05-18
145
+ - 2009-07-01
146
+ - 2009-09-07
147
+ - 2009-10-12
148
+ - 2009-11-11
149
+ - 2009-12-25
150
+ - 2010-01-01
151
+ - 2010-04-02
152
+ - 2010-05-24
153
+ - 2010-07-01
154
+ - 2010-09-06
155
+ - 2010-10-11
156
+ - 2010-11-11
157
+ - 2010-12-24
158
+ - 2010-12-25
159
+ - 2011-01-01
160
+ - 2011-01-03
161
+ - 2011-04-22
162
+ - 2011-05-23
163
+ - 2011-07-01
164
+ - 2011-09-05
165
+ - 2011-10-10
166
+ - 2011-11-11
167
+ - 2011-12-25
168
+ - 2011-12-26
169
+ - 2012-01-01
170
+ - 2012-01-02
171
+ - 2012-04-06
172
+ - 2012-05-21
173
+ - 2012-07-01
174
+ - 2012-07-02
175
+ - 2012-09-03
176
+ - 2012-10-08
177
+ - 2012-11-11
178
+ - 2012-11-12
179
+ - 2012-12-25
180
+ - 2013-01-01
181
+ - 2013-03-29
182
+ - 2013-05-20
183
+ - 2013-07-01
184
+ - 2013-09-02
185
+ - 2013-10-14
186
+ - 2013-11-11
187
+ - 2013-12-25
188
+ - 2014-01-01
189
+ - 2014-04-18
190
+ - 2014-05-19
191
+ - 2014-07-01
192
+ - 2014-09-01
193
+ - 2014-10-13
194
+ - 2014-11-11
195
+ - 2014-12-25
196
+ - 2015-01-01
197
+ - 2015-04-03
198
+ - 2015-05-18
199
+ - 2015-07-01
200
+ - 2015-09-07
201
+ - 2015-10-12
202
+ - 2015-11-11
203
+ - 2015-12-25
204
+ - 2016-01-01
205
+ - 2016-03-25
206
+ - 2016-05-23
207
+ - 2016-07-01
208
+ - 2016-09-05
209
+ - 2016-10-10
210
+ - 2016-11-11
211
+ - 2016-12-25
212
+ - 2016-12-26
213
+ - 2017-01-01
214
+ - 2017-01-02
215
+ - 2017-04-14
216
+ - 2017-05-22
217
+ - 2017-07-01
218
+ - 2017-09-04
219
+ - 2017-10-09
220
+ - 2017-11-11
221
+ - 2017-12-25
222
+ - 2018-01-01
223
+ - 2018-03-30
224
+ - 2018-05-21
225
+ - 2018-07-01
226
+ - 2018-07-02
227
+ - 2018-03-09
228
+ - 2018-10-08
229
+ - 2018-11-11
230
+ - 2018-11-12
231
+ - 2018-12-25
232
+ - 2019-01-01
233
+ - 2019-04-19
234
+ - 2019-05-20
235
+ - 2019-07-01
236
+ - 2019-09-02
237
+ - 2019-10-14
238
+ - 2019-11-11
239
+ - 2019-12-25
240
+ - 2020-01-01
241
+ - 2020-04-10
242
+ - 2020-05-18
243
+ - 2020-07-01
244
+ - 2020-10-12
245
+ - 2020-11-11
246
+ - 2020-12-25