simple-period 0.1.1 → 1.0.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: 109e1043f7b4a0ceb5f567e9f27140d68d9cd264cdb409e956d59db5082fd17e
4
- data.tar.gz: 98f88570fb4aeec8317583162a19fd39ef312fac666341acaac9262d579b25bd
3
+ metadata.gz: c7431f831a5924833fbbe9c5d2fec6067ab99f4607cfd131c1f746fd52902fb8
4
+ data.tar.gz: 55a6f373c9c93d37aff4f08a11dc71bd1addf32d9394d93714c9683f44f16355
5
5
  SHA512:
6
- metadata.gz: 3c57a6ab9ca2b608c6a91ef974794d9d3a765b1d3e07ba302f1bccf1076455388472db56015344e86aca09e007ec393ef1075ea6851ff9c88d4704a5a315bd7f
7
- data.tar.gz: 6daea1383d1829158542e6987508e81f1921c7313729ce987336ec95c08d50d6885b2d6d14dad259bd0eba3c4cb5135fcc74f32d13ce0d81d0d163b0b75acaf2
6
+ metadata.gz: eb557f7fd73e461541ae8fcc21d634cffaee04c7a7e66380c53f3af35fefe91ee09c0f08feb44ec99291909e6f8bd827b938ff451a384df56702aa402cc865da
7
+ data.tar.gz: 34593dbc236ad94d8f416dce2efc9fdc7dd2de018f86398fe7fce8e0eb95f55ce6fdbb6df8be5d38367d11938809e571fbd262fbab02446a5c65c98e3f7c43bc
data/lib/simple_period.rb CHANGED
@@ -1,5 +1,32 @@
1
- require "simple_period/version"
1
+ require 'simple_period/version'
2
+ require 'simple_period/format'
2
3
 
3
4
  module SimplePeriod
4
- # Your code goes here...
5
+ MIN_SEC = 60
6
+ HOUR_SEC = 60 * MIN_SEC
7
+ DAY_SEC = 24 * HOUR_SEC
8
+ WEEK_SEC = 7 * DAY_SEC
9
+ MONTH_SEC = 30 * DAY_SEC
10
+ YEAR_SEC = 365 * DAY_SEC
11
+
12
+ class << self
13
+ def second(period)
14
+ case period
15
+ when Format.min_proc
16
+ period.to_i * MIN_SEC
17
+ when Format.hour_proc
18
+ period.to_i * HOUR_SEC
19
+ when Format.day_proc
20
+ period.to_i * DAY_SEC
21
+ when Format.week_proc
22
+ period.to_i * WEEK_SEC
23
+ when Format.month_proc
24
+ period.to_i * MONTH_SEC
25
+ when Format.year_proc
26
+ period.to_i * YEAR_SEC
27
+ else
28
+ period
29
+ end
30
+ end
31
+ end
5
32
  end
@@ -0,0 +1,25 @@
1
+ require 'simple_period'
2
+
3
+ module SimplePeriod
4
+ module Format
5
+ PROC_REGEX = /_proc\z/
6
+
7
+ MIN_REGEX = /\A\d+min\z/
8
+ HOUR_REGEX = /\A\d+h\z/
9
+ DAY_REGEX = /\A\d+d\z/
10
+ WEEK_REGEX = /\A\d+w\z/
11
+ MONTH_REGEX = /\A\d+M\z/
12
+ YEAR_REGEX = /\A\d+y\z/
13
+
14
+ class << self
15
+ def method_missing(name)
16
+ return super if name !~ PROC_REGEX
17
+
18
+ match_data = name.match(PROC_REGEX)
19
+ const_name = match_data.pre_match.upcase
20
+ regex = const_get("#{const_name}_REGEX", false)
21
+ lambda { |txt| txt =~ regex }
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,3 +1,3 @@
1
1
  module SimplePeriod
2
- VERSION = '0.1.1'
2
+ VERSION = '1.0.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple-period
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - nishisuke
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-02-03 00:00:00.000000000 Z
11
+ date: 2018-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -53,6 +53,7 @@ files:
53
53
  - bin/console
54
54
  - bin/setup
55
55
  - lib/simple_period.rb
56
+ - lib/simple_period/format.rb
56
57
  - lib/simple_period/version.rb
57
58
  - simple_period.gemspec
58
59
  homepage: https://github.com/nishisuke/simple-period