rtime 0.1.0 → 0.1.1
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 +4 -4
- data/.codeclimate.yml +18 -0
- data/.rubocop.yml +12 -0
- data/.travis.yml +16 -1
- data/README.md +15 -4
- data/Rakefile +1 -1
- data/bin/rtime +14 -11
- data/lib/rtime/rts.rb +25 -22
- data/lib/rtime/version.rb +1 -1
- data/rtime.gemspec +8 -3
- metadata +23 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f9e2ae373791a67913f562e62be256fb232b6175
|
4
|
+
data.tar.gz: 542f60fd6c9a6cfc3d58e8e9785598e806def02e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c5c5152d50cfdd166463bbeefffb5401d77a1a5a7ee17159a4d4084d054a1cbabfd2d4d0d2c0a1b3683f06759140b40e4e23993937c780ca5fd33d0f9126f7e
|
7
|
+
data.tar.gz: 7e1a8ae52c6dc57ed063d29408e65c8d852a7e7760006d68ae038f24fe1cf9490c117720e76f6c39908f10fafde769b65a0d6ab2c4dea4621b473f01401ea7f9
|
data/.codeclimate.yml
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
CHANGED
@@ -1,5 +1,20 @@
|
|
1
1
|
sudo: false
|
2
2
|
language: ruby
|
3
3
|
rvm:
|
4
|
-
|
4
|
+
- 2.2.7
|
5
|
+
- 2.3.4
|
6
|
+
- 2.4.1
|
5
7
|
before_install: gem install bundler -v 1.15.1
|
8
|
+
addons:
|
9
|
+
code_climate:
|
10
|
+
repo_token: 8f508f2041ed0b481b26eb1f3b62613cacc0c2052025c7161f418a262bbe2636
|
11
|
+
after_success:
|
12
|
+
- bundle exec codeclimate-test-reporter
|
13
|
+
deploy:
|
14
|
+
provider: rubygems
|
15
|
+
api_key:
|
16
|
+
secure: SHDqKtYlS55txfMTkm3u4nP9Wol12Y1KIy+Uds5aTgq4n8v0mfj8n7a0GaXgD0Yz+loIac+DXIZan72BIYqFHhowYkO83HYQRqhUwgP5p/psn+58d/RkYwYZZLuSgZtS0AXahTmcjUOeGMDa/M1XGYuHnPTMTjB1chQ7k914GYDYpqKRH8V7JZKao+pa4a8qoXTZGpjLW+IPkZTHZONjN1XvE9GereFGpIubDWs0SFIimlg0MTD1OJJHFzbjATV9blF5nmtc/bBMhwCtywYHzNdUUz+IdW2GicQpZ+YsXDxF2vJ26Oo7XilHX/fQ9xLiJDE8w1xrw4hqUIC5Bb0C+CQeAwNOB9dJrHocEfr1nZnyprmYLUkj3LuvlJZ/pQcgjYEMV7leqfzoU+gW4fLEN/w9NjdQxRHztyJ73YVx6mC2kaTENB9pBevTwhReI1Xn/YLWZvu/vlLxAyKaa3yVjGDOiFKNi2Yp0nurpOQXCi79MSVA0wP9Hrps/umLmRXMCVMvV+Vdhx2Z6Gqo0oUb+AoqsKLfhx1EwKvCGKiI2l2niwZ8OL9RIVJEaNjYrA6BIdTQ0BBabv6PPPEdTkdMb7Cc5k9+O55piHUDnLsCM99llThCGqbkTXQdKOP8Fll6/RC4473lt6cBCKlWRv87iE/ltvNt4uxxaszGjR41Ylg=
|
17
|
+
gem: rtime
|
18
|
+
on:
|
19
|
+
tags: true
|
20
|
+
repo: at-shakil/rtime
|
data/README.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
# RTime
|
2
2
|
|
3
|
+
[](https://travis-ci.org/at-shakil/rtime)
|
4
|
+
[](https://badge.fury.io/rb/rtime)
|
5
|
+
[](https://gemnasium.com/github.com/at-shakil/rtime)
|
6
|
+
[](https://codeclimate.com/github/at-shakil/rtime/coverage)
|
7
|
+
[](http://inch-ci.org/github/at-shakil/rtime)
|
8
|
+
[](https://codeclimate.com/github/at-shakil/rtime)
|
9
|
+
[](https://codeclimate.com/github/at-shakil/rtime)
|
10
|
+
|
11
|
+
## Summary
|
12
|
+
|
3
13
|
RTime is a random timestamp generator.
|
4
14
|
|
5
15
|
## Installation
|
@@ -8,9 +18,10 @@ This app is intended to be used as a command-line utility.
|
|
8
18
|
|
9
19
|
Installation is as simple as,
|
10
20
|
|
11
|
-
|
21
|
+
gem install rtime
|
12
22
|
|
13
|
-
If you eventually develop a taste for `rtime`'s tiny API,
|
23
|
+
If you eventually develop a taste for `rtime`'s tiny API,
|
24
|
+
you may want to follow the steps below.
|
14
25
|
|
15
26
|
Add this line to your application's Gemfile:
|
16
27
|
|
@@ -20,7 +31,7 @@ gem 'rtime'
|
|
20
31
|
|
21
32
|
And then execute:
|
22
33
|
|
23
|
-
|
34
|
+
bundle
|
24
35
|
|
25
36
|
## Usage
|
26
37
|
|
@@ -31,7 +42,7 @@ rtime generate <start_date> <end_date> <coverage> [--night-only]
|
|
31
42
|
Here's an example use case:
|
32
43
|
|
33
44
|
```sh
|
34
|
-
$ rtime g 20170127 20170203 60% --night
|
45
|
+
$ rtime g 20170127 20170203 60% --night-only
|
35
46
|
|
36
47
|
2017-01-28 20:48:48 +0000
|
37
48
|
|
data/Rakefile
CHANGED
data/bin/rtime
CHANGED
@@ -3,28 +3,31 @@ require "thor"
|
|
3
3
|
require "rtime"
|
4
4
|
|
5
5
|
module RTime
|
6
|
+
# RTime command-line interface base class
|
6
7
|
class CLI < Thor
|
7
|
-
class_option
|
8
|
+
class_option(
|
9
|
+
:night_only,
|
10
|
+
aliases: ["-n"], type: :boolean,
|
8
11
|
desc: "Only generates timestamp between 20:00 - 06:00"
|
12
|
+
)
|
9
13
|
|
10
14
|
desc "generate <date1> <date2> <coverage>", "Generates random timestamp"
|
11
15
|
def generate date1, date2, coverage
|
12
16
|
date_matcher = /^\d{4}(0[1-9]|1[0-2])(0[1-9]|[12][0-9]|3[01])$/
|
13
17
|
coverage_match = /^(?<coverage>\d|[1-9][0-9]|10{2})%$/.match coverage
|
14
|
-
unless date_matcher =~ date1 and date_matcher =~ date2 and coverage_match
|
15
|
-
puts <<~MESSAGE
|
16
|
-
Error: invalid argument!
|
17
18
|
|
18
|
-
|
19
|
-
|
19
|
+
if date_matcher =~ date1 && date_matcher =~ date2 && coverage_match
|
20
|
+
timestamps = RTime::RTS.timestamps(
|
21
|
+
date1, date2, coverage_match[:coverage].to_f / 100, options
|
22
|
+
)
|
23
|
+
timestamps.each { |timestamp| puts "\n#{timestamp}" }
|
24
|
+
else
|
25
|
+
puts "Error: invalid argument!\n\n\
|
26
|
+
Example: rtime gen 20170417 20170423 85%"
|
20
27
|
end
|
21
|
-
|
22
|
-
timestamps = RTime::RTS.timestamps date1, date2,
|
23
|
-
coverage_match[:coverage].to_f/100, options
|
24
|
-
timestamps.each {|timestamp| puts "\n#{timestamp}"}
|
25
28
|
end
|
26
29
|
|
27
|
-
map [
|
30
|
+
map %W[gen g] => :generate
|
28
31
|
end
|
29
32
|
end
|
30
33
|
|
data/lib/rtime/rts.rb
CHANGED
@@ -5,11 +5,12 @@ module RTime
|
|
5
5
|
class << self
|
6
6
|
# Returns a time segment specific to the provided options
|
7
7
|
def _time_for options
|
8
|
-
hour =
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
hour =
|
9
|
+
if options[:night_only]
|
10
|
+
((20..23).to_a + (0..5).to_a).sample
|
11
|
+
else
|
12
|
+
(0..23).to_a.sample
|
13
|
+
end
|
13
14
|
|
14
15
|
minute = (0..59).to_a.sample
|
15
16
|
second = (0..59).to_a.sample
|
@@ -22,15 +23,16 @@ module RTime
|
|
22
23
|
# Returns a time segment
|
23
24
|
def _parse_date date
|
24
25
|
match = /^(?<year>\d{4})(?<month>\d{2})(?<day>\d{2})$/.match date
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
month = group["month"].to_i
|
29
|
-
day = group["day"].to_i
|
30
|
-
[year, month, day]
|
31
|
-
else
|
32
|
-
raise Exception.new "Date must be provided in YYYYMMDD format"
|
26
|
+
|
27
|
+
unless match
|
28
|
+
raise(Exception, "Date must be provided in YYYYMMDD format")
|
33
29
|
end
|
30
|
+
|
31
|
+
group = match.names.zip(match.captures).to_h
|
32
|
+
year = group["year"].to_i
|
33
|
+
month = group["month"].to_i
|
34
|
+
day = group["day"].to_i
|
35
|
+
[year, month, day]
|
34
36
|
end
|
35
37
|
|
36
38
|
# Returns a count that can be selected from the total count for a
|
@@ -41,18 +43,19 @@ module RTime
|
|
41
43
|
|
42
44
|
# Returns all the timestamp in a range
|
43
45
|
def _timestamps_in_range date1, date2, options
|
44
|
-
year, month, day =
|
46
|
+
year, month, day = _parse_date date1
|
45
47
|
date1 = Time.new year, month, day
|
46
|
-
year, month, day =
|
48
|
+
year, month, day = _parse_date date2
|
47
49
|
date2 = Time.new year, month, day
|
48
50
|
start_date, end_date = date1 < date2 ? [date1, date2] : [date2, date1]
|
49
51
|
range = []
|
50
52
|
tmp_date = start_date
|
51
53
|
while tmp_date <= end_date
|
52
54
|
|
53
|
-
hour, minute, second =
|
54
|
-
range.push Time.new(
|
55
|
-
tmp_date.day, hour, minute, second
|
55
|
+
hour, minute, second = _time_for(options)
|
56
|
+
range.push Time.new(
|
57
|
+
tmp_date.year, tmp_date.month, tmp_date.day, hour, minute, second
|
58
|
+
)
|
56
59
|
tmp_date += 60 * 60 * 24 # 1 day
|
57
60
|
end
|
58
61
|
|
@@ -60,10 +63,10 @@ module RTime
|
|
60
63
|
end
|
61
64
|
|
62
65
|
# Returns a specified percentage of random timestamp in a range
|
63
|
-
def timestamps
|
64
|
-
all_timestamps =
|
65
|
-
selection_count =
|
66
|
-
coverage
|
66
|
+
def timestamps date1, date2, coverage, options = { night_only: false }
|
67
|
+
all_timestamps = _timestamps_in_range date1, date2, options
|
68
|
+
selection_count =
|
69
|
+
_selections_for_coverage all_timestamps.count, coverage
|
67
70
|
all_timestamps.sample(selection_count).sort
|
68
71
|
end
|
69
72
|
end
|
data/lib/rtime/version.rb
CHANGED
data/rtime.gemspec
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
|
2
3
|
lib = File.expand_path("../lib", __FILE__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require "rtime/version"
|
@@ -9,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
9
10
|
spec.authors = ["Tahmid Shakil"]
|
10
11
|
spec.email = ["at.shakil.92@gmail.com"]
|
11
12
|
|
12
|
-
spec.summary =
|
13
|
+
spec.summary = "RTime is a random timestamp generator"
|
13
14
|
spec.homepage = "https://github.com/at-shakil/rtime"
|
14
15
|
spec.license = "MIT"
|
15
16
|
|
@@ -23,7 +24,11 @@ Gem::Specification.new do |spec|
|
|
23
24
|
spec.add_dependency "thor", "~> 0.19.4"
|
24
25
|
|
25
26
|
spec.add_development_dependency "bundler", "~> 1.15"
|
26
|
-
spec.add_development_dependency "rake", "~>
|
27
|
+
spec.add_development_dependency "rake", "~> 12.0"
|
27
28
|
spec.add_development_dependency "minitest", "~> 5.0"
|
28
|
-
spec.add_development_dependency "simplecov", "~> 0.
|
29
|
+
spec.add_development_dependency "simplecov", "~> 0.13"
|
30
|
+
|
31
|
+
if ENV["TRAVIS"]
|
32
|
+
spec.add_development_dependency "codeclimate-test-reporter", "~> 1.0.8"
|
33
|
+
end
|
29
34
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rtime
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tahmid Shakil
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '12.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '12.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: minitest
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,14 +72,28 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '0.
|
75
|
+
version: '0.13'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0.
|
82
|
+
version: '0.13'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: codeclimate-test-reporter
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.0.8
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.0.8
|
83
97
|
description:
|
84
98
|
email:
|
85
99
|
- at.shakil.92@gmail.com
|
@@ -88,7 +102,9 @@ executables:
|
|
88
102
|
extensions: []
|
89
103
|
extra_rdoc_files: []
|
90
104
|
files:
|
105
|
+
- ".codeclimate.yml"
|
91
106
|
- ".gitignore"
|
107
|
+
- ".rubocop.yml"
|
92
108
|
- ".travis.yml"
|
93
109
|
- Gemfile
|
94
110
|
- LICENSE.txt
|
@@ -119,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
135
|
version: '0'
|
120
136
|
requirements: []
|
121
137
|
rubyforge_project:
|
122
|
-
rubygems_version: 2.
|
138
|
+
rubygems_version: 2.4.5
|
123
139
|
signing_key:
|
124
140
|
specification_version: 4
|
125
141
|
summary: RTime is a random timestamp generator
|