tempora 0.1.3 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: df646739fb8d7d27a0bb3eed5a3981c668b300e7f105245cb340a233bf447a54
4
- data.tar.gz: 45821e6f2200f5dc69838086ab76bcedfee33773bf7883dfd5fa82fb9a736195
3
+ metadata.gz: 829bad4acfece329fa910614c27da039a46933e2da7246d091df30fd1463cee5
4
+ data.tar.gz: 6d2d1e27e904b76d6f2661fb8328b8a3bceb83c142ffe376f76d261e66fdea07
5
5
  SHA512:
6
- metadata.gz: 3bce9a11d0bc1fedc9f975392c629ebe449a3ddae1ed50584941d0f3256d4b09729a69da168f7fed2cd04cd34d33457788a3cb00a511e9256687d25a51a76fc1
7
- data.tar.gz: d44541c8c7894193804b6d1fce6adf731c8acfa14ffe2d528487f4c839d66e85d2a01992f7209184d1d9323f4fa32ebbcb79be05364b424f03999d4d0ec0eb4e
6
+ metadata.gz: ff6c9aec13bd9eb4ce86085043887f750101a722d64a30d6b8af43e7e52962632e91b8dbb74561cf0df02d05acb7928234ab892eafbe3fe1930bbe6f05cf64cb
7
+ data.tar.gz: '08cc00d8bbac916783277803a0ef3279a7db353bd3a9e5743d2a0576824939e0b1b1039bea1143120068cf995060ac4bb0d827b553d73a2a368e902d69bbd40a'
data/lib/month.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  require_relative 'timeperiod'
2
- require_relative 'initialization'
3
- require_relative 'week'
2
+ require_relative 'tempora/initialization'
3
+ require_relative 'tempora/has_weeks'
4
4
 
5
- class Month
6
- include TimePeriod
5
+ class Month < TimePeriod
7
6
  extend Initialization
7
+ include HasWeeks
8
8
 
9
9
  def initialize(year, month)
10
10
  @year = Integer(year)
@@ -38,14 +38,6 @@ class Month
38
38
  self.class.from(start_date.prev_month) # @start_date << 1
39
39
  end
40
40
 
41
- def weeks
42
- Week.from(start_date)..Week.from(end_date)
43
- end
44
-
45
- def each_week(&block)
46
- weeks.each(&block)
47
- end
48
-
49
41
  alias_method :month, :number
50
42
  alias_method :succ, :next
51
43
  alias_method :pred, :prev
data/lib/quarter.rb CHANGED
@@ -1,11 +1,12 @@
1
1
  require_relative 'timeperiod'
2
- require_relative 'initialization'
3
- require_relative 'month'
4
- require_relative 'week'
2
+ require_relative 'tempora/initialization'
3
+ require_relative 'tempora/has_months'
4
+ require_relative 'tempora/has_weeks'
5
5
 
6
- class Quarter
7
- include TimePeriod
6
+ class Quarter < TimePeriod
8
7
  extend Initialization
8
+ include HasMonths
9
+ include HasWeeks
9
10
 
10
11
  def initialize(year, quarter)
11
12
  @year = Integer(year)
@@ -34,19 +35,14 @@ class Quarter
34
35
 
35
36
  alias_method :succ, :next
36
37
  alias_method :pred, :prev
37
-
38
- def months
39
- Month.from(start_date)..Month.from(end_date)
40
- end
41
-
42
- def weeks
43
- Week.from(start_date)..Week.from(end_date)
44
- end
45
38
 
46
39
  private
47
40
 
48
41
  def self.initialization_parameter(date)
49
- quarter = ((date.month - 1) / 3) + 1
50
- [date.year, quarter]
42
+ [date.year, quarter_from_date(date)]
43
+ end
44
+
45
+ def self.quarter_from_date(date)
46
+ ((date.month - 1) / 3) + 1
51
47
  end
52
48
  end
@@ -0,0 +1,9 @@
1
+ module HasMonths
2
+ def months
3
+ Month.from(start_date)..Month.from(end_date)
4
+ end
5
+
6
+ def each_month(&block)
7
+ months.each(&block)
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ require 'week'
2
+
3
+ module HasWeeks
4
+ def weeks
5
+ Week.from(start_date)..Week.from(end_date)
6
+ end
7
+
8
+ def each_week(&block)
9
+ weeks.each(&block)
10
+ end
11
+ end
@@ -1,5 +1,3 @@
1
- require 'date'
2
-
3
1
  module Initialization
4
2
  def now
5
3
  from Time.now
@@ -8,7 +6,7 @@ module Initialization
8
6
  alias_method :current, :now
9
7
 
10
8
  def from(date)
11
- new *initialization_parameter(date.to_date)
9
+ new(*initialization_parameter(date.to_date))
12
10
  end
13
11
 
14
12
  private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tempora
4
- VERSION = "0.1.3"
4
+ VERSION = "0.2.0"
5
5
  end
data/lib/tempora.rb CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  require_relative "tempora/version"
4
4
  require_relative "timeperiod"
5
- require_relative "initialization"
6
5
  require_relative "year"
7
6
  require_relative "month"
8
7
  require_relative "week"
data/lib/timeperiod.rb CHANGED
@@ -1,9 +1,14 @@
1
1
  require 'date'
2
2
 
3
- module TimePeriod
3
+ class TimePeriod
4
4
  include Comparable
5
5
 
6
6
  attr_reader :start_date, :end_date, :year, :number
7
+
8
+ def initialize(start_date, end_date)
9
+ @start_date = start_date
10
+ @end_date = end_date
11
+ end
7
12
 
8
13
  def range
9
14
  start_date..end_date
@@ -26,7 +31,7 @@ module TimePeriod
26
31
  end
27
32
 
28
33
  def overlaps?(other)
29
- range.overlaps?(other.range)
34
+ range.overlap?(other.range)
30
35
  end
31
36
 
32
37
  def intersection(other)
@@ -35,7 +40,7 @@ module TimePeriod
35
40
  new_start = [start_date, other.start_date].max
36
41
  new_end = [end_date, other.end_date].min
37
42
 
38
- self.class.new(new_start, new_end)
43
+ TimePeriod.new(new_start, new_end)
39
44
  end
40
45
 
41
46
  def <=>(other)
@@ -45,5 +50,4 @@ module TimePeriod
45
50
  alias_method :begin, :start_date
46
51
  alias_method :end, :end_date
47
52
  alias_method :length, :duration
48
- end
49
-
53
+ end
data/lib/week.rb CHANGED
@@ -1,8 +1,7 @@
1
1
  require_relative 'timeperiod'
2
- require_relative 'initialization'
2
+ require_relative 'tempora/initialization'
3
3
 
4
- class Week
5
- include TimePeriod
4
+ class Week < TimePeriod
6
5
  extend Initialization
7
6
 
8
7
  def initialize(year, week)
data/lib/year.rb CHANGED
@@ -1,11 +1,12 @@
1
1
  require_relative 'timeperiod'
2
- require_relative 'initialization'
3
- require_relative 'month'
4
- require_relative 'week'
2
+ require_relative 'tempora/initialization'
3
+ require_relative 'tempora/has_months'
4
+ require_relative 'tempora/has_weeks'
5
5
 
6
- class Year
7
- include TimePeriod
6
+ class Year < TimePeriod
8
7
  extend Initialization
8
+ include HasWeeks
9
+ include HasMonths
9
10
 
10
11
  def initialize(year)
11
12
  @year = Integer(year)
@@ -29,22 +30,6 @@ class Year
29
30
  def prev
30
31
  self.class.new(year - 1)
31
32
  end
32
-
33
- def months
34
- Month.new(year, 1)..Month.new(year, 12)
35
- end
36
-
37
- def weeks
38
- Week.from(start_date)..Week.from(end_date)
39
- end
40
-
41
- def each_month(&block)
42
- months.each(&block)
43
- end
44
-
45
- def each_week(&block)
46
- weeks.each(&block)
47
- end
48
33
 
49
34
  alias_method :succ, :next
50
35
  alias_method :pred, :prev
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tempora
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Power
@@ -21,10 +21,12 @@ files:
21
21
  - README.md
22
22
  - Rakefile
23
23
  - lib/_timespan.rb
24
- - lib/initialization.rb
25
24
  - lib/month.rb
26
25
  - lib/quarter.rb
27
26
  - lib/tempora.rb
27
+ - lib/tempora/has_months.rb
28
+ - lib/tempora/has_weeks.rb
29
+ - lib/tempora/initialization.rb
28
30
  - lib/tempora/version.rb
29
31
  - lib/timeperiod.rb
30
32
  - lib/week.rb