matiox 0.0.0.9 → 0.0.0.10

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: f930992ab09baea5f1f0d0dfb7f891ce9a161bab31ff5435757c05a6f823bff4
4
- data.tar.gz: cd8b66cf5994a0b7eb10eafe146368595e544e353097b1d9184f75d74192ebf1
3
+ metadata.gz: 5a29677df3a23cf4c00f30b66abcdf7653726b70027fe7dca1690c7e578def3b
4
+ data.tar.gz: 3a6c5987a7ed704b4886853465ef2a3498d637ec9dc2aa15549a1ce20cda965e
5
5
  SHA512:
6
- metadata.gz: 45eaa6c0d1ba1a1b3e2e8403edb19046cb237b715e2181ce3cccc17ac60653d022bf24c0395841e482032beee25a497f5e9a31028334407709c5b1e973c12c92
7
- data.tar.gz: 45186628cf5407ad00938d1a47990ae2b38dc5b6ea37c84fc9b57949ecce0e66426807383acdd872b47c7ae50e81655a802f68d1885173c64f498611665745a8
6
+ metadata.gz: b28bc22e99625f50ae37fc67a7d53a5cf2c225bb0242897d11b1f56b79fec351658c0178509315ff956993b97845c8ba271547f7f4eda8d4d42125b02229780f
7
+ data.tar.gz: 6720446cea830bf0620043cfa62e794fa8eb5a5622ba3b07d9950d1e6bc47cc7cce8c27d6bd1e2e397b62d88bf5b1b8c3b37a7b293a2cbf85c1cbe742c82d5fc
@@ -8,6 +8,7 @@ class Matiox
8
8
 
9
9
  attr_reader :gregorian
10
10
 
11
- include Initializers
11
+ include Initializer::Default
12
+ extend Initializer::Gregorian
12
13
 
13
14
  end
@@ -1,8 +1,12 @@
1
1
  class Matiox
2
2
  module Error
3
+ class NotYetImplemented < StandardError; end
3
4
  module GregorianDate
4
- class NotYetImplemented < StandardError; end
5
- class IncorrectlyFormatted < StandardError; end
5
+ class IncorrectlyFormatted < StandardError
6
+ class YMD < StandardError; end
7
+ class YMDHMS < StandardError; end
8
+ class ISO8601 < StandardError; end
9
+ end
6
10
  end
7
11
  end
8
12
  end
@@ -1,52 +1,54 @@
1
1
  class Matiox
2
- module Initializers
2
+ module Initializer
3
+ module Default
3
4
 
4
- def initialize(date=nil)
5
+ def initialize(date=nil)
5
6
 
6
- case date
7
+ case date
7
8
 
8
- when DateTime
9
+ when DateTime
9
10
 
10
- @gregorian = date
11
+ @gregorian = date
11
12
 
12
- when Time
13
+ when Time
13
14
 
14
- seconds = date.sec + Rational(date.usec, 10**6)
15
- offset = Rational(date.utc_offset, 60 * 60 * 24)
16
- @gregorian = DateTime.new(
17
- date.year,
18
- date.month,
19
- date.day,
20
- date.hour,
21
- date.min,
22
- seconds,
23
- offset
24
- )
25
-
15
+ seconds = date.sec + Rational(date.usec, 10**6)
16
+ offset = Rational(date.utc_offset, 60 * 60 * 24)
17
+ @gregorian = DateTime.new(
18
+ date.year,
19
+ date.month,
20
+ date.day,
21
+ date.hour,
22
+ date.min,
23
+ seconds,
24
+ offset
25
+ )
26
+
26
27
 
27
- #de TODO: Move these into their own self.from_ methods and invoke in general initializer here:
28
- #de TODO: Use Regular expressions?
29
- when String
28
+ #de TODO: Move these into their own self.from_ methods and invoke in general initializer here:
29
+ #de TODO: Use Regular expressions?
30
+ when String
30
31
 
31
- begin
32
- @gregorian = DateTime.strptime(date, '%Y-%m-%dT%H:%M:%S%z')
33
- rescue
34
32
  begin
35
- @gregorian = DateTime.strptime(date, '%Y-%m-%d %H:%M:%S')
33
+ @gregorian = DateTime.strptime(date, '%Y-%m-%dT%H:%M:%S%z')
36
34
  rescue
37
35
  begin
38
- @gregorian = DateTime.strptime(date, '%Y-%m-%d')
36
+ @gregorian = DateTime.strptime(date, '%Y-%m-%d %H:%M:%S')
39
37
  rescue
40
- raise Matiox::Error::GregorianDate::IncorrectlyFormatted.new("Bad date string: #{date}")
38
+ begin
39
+ @gregorian = DateTime.strptime(date, '%Y-%m-%d')
40
+ rescue
41
+ raise Matiox::Error::GregorianDate::IncorrectlyFormatted.new("Bad date string: #{date}")
42
+ end
41
43
  end
42
44
  end
45
+
46
+ else
47
+ @gregorian = DateTime.now
43
48
  end
44
49
 
45
- else
46
- @gregorian = DateTime.now
47
50
  end
48
51
 
49
52
  end
50
-
51
53
  end
52
54
  end
@@ -1,17 +1,26 @@
1
1
  class Matiox
2
- module Initializers
3
- class << self
2
+ module Initializer
3
+ module Gregorian
4
4
 
5
5
  def from_ymdhms(date)
6
6
  raise Error::NotYetImplemented
7
+ #de TODO: Convert to DateTime beforehand... after regular expression validation.
8
+ converted = DateTime.strptime(date, "FORMAT")
9
+ new(converted)
7
10
  end
8
11
 
9
12
  def from_ymd(date)
10
13
  raise Error::NotYetImplemented
14
+ #de TODO: Convert to DateTime beforehand... after regular expression validation.
15
+ converted = DateTime.strptime(date, "FORMAT")
16
+ new(converted)
11
17
  end
12
18
 
13
19
  def from_iso8601(date)
14
20
  raise Error::NotYetImplemented
21
+ #de TODO: Convert to DateTime beforehand... after regular expression validation.
22
+ converted = DateTime.strptime(date, "FORMAT")
23
+ new(converted)
15
24
  end
16
25
 
17
26
  end
@@ -1,3 +1,3 @@
1
1
  class Matiox
2
- VERSION = '0.0.0.9'.freeze
2
+ VERSION = '0.0.0.10'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: matiox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0.9
4
+ version: 0.0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Donovan Keme