simple_period 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/simple_period.rb +32 -0
- data/lib/simple_period/format.rb +25 -0
- data/lib/simple_period/version.rb +3 -0
- data/simple_period.gemspec +34 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e44f062339e70e263c8d769589769172e5045741fa7c3c87160dd208de5edff3
|
4
|
+
data.tar.gz: a06c7c0e10f2710f4e3e93daf3318e429e82814c49abc9c06ff22559166d3427
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 697305ea7cd846d59064fc50065bcfb7cd20b88426b2de459cc9e83fd6ea9b869d248b96bb769223f879a8a4c2a946dafe253d5f2dc5679ed0791bb9bd69676f
|
7
|
+
data.tar.gz: 26a4e311fe60e18125597897718b7c284891f62fcb6e4fd750786bc27c30b4711d215d392d7e1c3479cbfdccb6b76e52a20c106228f78c38bc27af10277df07b
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 nishisuke
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# SimplePeriod
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/simple_period`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'simple-period'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install simple-period
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/simple-period.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "simple/period"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'simple_period/version'
|
2
|
+
require 'simple_period/format'
|
3
|
+
|
4
|
+
module SimplePeriod
|
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
|
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
|
@@ -0,0 +1,34 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'simple_period/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'simple_period'
|
7
|
+
spec.version = SimplePeriod::VERSION
|
8
|
+
spec.authors = ["nishisuke"]
|
9
|
+
spec.email = ["nishisuke13+git@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = %q{'1d' -> 86400}
|
12
|
+
spec.description = %q{Converts formatted time to second}
|
13
|
+
spec.homepage = 'https://github.com/nishisuke/simple-period'
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata["allowed_push_host"] = 'https://rubygems.org'
|
20
|
+
else
|
21
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
22
|
+
"public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
26
|
+
f.match(%r{^(test|spec|features)/})
|
27
|
+
end
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
33
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simple_period
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- nishisuke
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-02-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Converts formatted time to second
|
42
|
+
email:
|
43
|
+
- nishisuke13+git@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- bin/console
|
54
|
+
- bin/setup
|
55
|
+
- lib/simple_period.rb
|
56
|
+
- lib/simple_period/format.rb
|
57
|
+
- lib/simple_period/version.rb
|
58
|
+
- simple_period.gemspec
|
59
|
+
homepage: https://github.com/nishisuke/simple-period
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata:
|
63
|
+
allowed_push_host: https://rubygems.org
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 2.7.4
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: "'1d' -> 86400"
|
84
|
+
test_files: []
|