rtime 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 81f47d8695ce0888db7ef05ef042afeb552c66ba
4
+ data.tar.gz: 7dd6724306d9511fc88c497c1d431d3c1a9e6e85
5
+ SHA512:
6
+ metadata.gz: e32b93a89493f3064803be8978de95cabf5748a0da7367aefb4920cf7bdd1c6c2c0c3c817cae6ae7f4127059031b05f296611eb65782f61fd55606deb0299d9c
7
+ data.tar.gz: f5daf135c4606b2630078fdb85e8eed97bab3fcd9ec2e7b1a9dfa16f4573c51d42331a77bb6eb5d1a7b6bc79847be1f296683c6d0b447faa9cca91ff3738fdf7
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /rdoc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.15.1
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Tahmid Shakil
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.
@@ -0,0 +1,51 @@
1
+ # RTime
2
+
3
+ RTime is a random timestamp generator.
4
+
5
+ ## Installation
6
+
7
+ This app is intended to be used as a command-line utility.
8
+
9
+ Installation is as simple as,
10
+
11
+ $ gem install rtime
12
+
13
+ If you eventually develop a taste for `rtime`'s tiny API, you may want to follow the steps below.
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'rtime'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ ## Usage
26
+
27
+ ```sh
28
+ rtime generate <start_date> <end_date> <coverage> [--night-only]
29
+ ```
30
+
31
+ Here's an example use case:
32
+
33
+ ```sh
34
+ $ rtime g 20170127 20170203 60% --night
35
+
36
+ 2017-01-28 20:48:48 +0000
37
+
38
+ 2017-01-29 03:51:15 +0000
39
+
40
+ 2017-01-31 01:15:47 +0000
41
+
42
+ 2017-02-03 23:41:54 +0000
43
+ ```
44
+
45
+ ## Contributing
46
+
47
+ If you are interested in contributing, please [submit a pull request](https://help.github.com/articles/about-pull-requests/).
48
+
49
+ ## License
50
+
51
+ [MIT](http://opensource.org/licenses/MIT)
@@ -0,0 +1,21 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+ require "rdoc/task"
4
+
5
+ RDoc::Task.new(:rdoc) do |rdoc|
6
+ rdoc.main = "README.md"
7
+ rdoc.rdoc_dir = "rdoc"
8
+ rdoc.title = "RTime"
9
+ rdoc.markup = "markdown"
10
+ rdoc.options << "--line-numbers"
11
+ rdoc.rdoc_files.include("README.md")
12
+ rdoc.rdoc_files.include("lib/**/*.rb")
13
+ end
14
+
15
+ Rake::TestTask.new(:test) do |t|
16
+ t.libs << "test"
17
+ t.libs << "lib"
18
+ t.test_files = FileList["test/**/*_test.rb"]
19
+ end
20
+
21
+ task :default => :test
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+ require "thor"
3
+ require "rtime"
4
+
5
+ module RTime
6
+ class CLI < Thor
7
+ class_option :night_only, aliases: ["-n"], type: :boolean,
8
+ desc: "Only generates timestamp between 20:00 - 06:00"
9
+
10
+ desc "generate <date1> <date2> <coverage>", "Generates random timestamp"
11
+ def generate date1, date2, coverage
12
+ date_matcher = /^\d{4}(0[1-9]|1[0-2])(0[1-9]|[12][0-9]|3[01])$/
13
+ 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
+ Example: rtime gen 20170417 20170423 85%
19
+ MESSAGE
20
+ 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
+ end
26
+
27
+ map ["gen", "g"] => :generate
28
+ end
29
+ end
30
+
31
+ RTime::CLI.start(ARGV)
@@ -0,0 +1,2 @@
1
+ require "rtime/version"
2
+ require "rtime/rts"
@@ -0,0 +1,71 @@
1
+ # The primary module for `rtime`
2
+ module RTime
3
+ # `RTS` implements random timestamp generator API
4
+ class RTS
5
+ class << self
6
+ # Returns a time segment specific to the provided options
7
+ def _time_for options
8
+ hour = if options[:night_only]
9
+ ((20..23).to_a + (0..5).to_a).sample
10
+ else
11
+ (0..23).to_a.sample
12
+ end
13
+
14
+ minute = (0..59).to_a.sample
15
+ second = (0..59).to_a.sample
16
+
17
+ [hour, minute, second]
18
+ end
19
+
20
+ # Parses date from `YYYYMMDD` format
21
+ #
22
+ # Returns a time segment
23
+ def _parse_date date
24
+ match = /^(?<year>\d{4})(?<month>\d{2})(?<day>\d{2})$/.match date
25
+ if match
26
+ group = match.named_captures
27
+ year = group["year"].to_i
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"
33
+ end
34
+ end
35
+
36
+ # Returns a count that can be selected from the total count for a
37
+ # specified coverage
38
+ def _selections_for_coverage total, coverage
39
+ (total.to_f * coverage).to_i
40
+ end
41
+
42
+ # Returns all the timestamp in a range
43
+ def _timestamps_in_range date1, date2, options
44
+ year, month, day = self._parse_date date1
45
+ date1 = Time.new year, month, day
46
+ year, month, day = self._parse_date date2
47
+ date2 = Time.new year, month, day
48
+ start_date, end_date = date1 < date2 ? [date1, date2] : [date2, date1]
49
+ range = []
50
+ tmp_date = start_date
51
+ while tmp_date <= end_date
52
+
53
+ hour, minute, second = self._time_for(options)
54
+ range.push Time.new(tmp_date.year, tmp_date.month,
55
+ tmp_date.day, hour, minute, second)
56
+ tmp_date += 60 * 60 * 24 # 1 day
57
+ end
58
+
59
+ range
60
+ end
61
+
62
+ # Returns a specified percentage of random timestamp in a range
63
+ def timestamps(date1, date2, coverage, options={night_only: false})
64
+ all_timestamps = self._timestamps_in_range date1, date2, options
65
+ selection_count = self._selections_for_coverage all_timestamps.count,
66
+ coverage
67
+ all_timestamps.sample(selection_count).sort
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,4 @@
1
+ module RTime
2
+ # Gem version specifier
3
+ VERSION = "0.1.0".freeze
4
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "rtime/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rtime"
8
+ spec.version = RTime::VERSION
9
+ spec.authors = ["Tahmid Shakil"]
10
+ spec.email = ["at.shakil.92@gmail.com"]
11
+
12
+ spec.summary = %q{RTime is a random timestamp generator}
13
+ spec.homepage = "https://github.com/at-shakil/rtime"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "bin"
20
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "thor", "~> 0.19.4"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.15"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "minitest", "~> 5.0"
28
+ spec.add_development_dependency "simplecov", "~> 0.14"
29
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rtime
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tahmid Shakil
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-06-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.19.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.19.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.15'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.15'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.14'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.14'
83
+ description:
84
+ email:
85
+ - at.shakil.92@gmail.com
86
+ executables:
87
+ - rtime
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/rtime
98
+ - lib/rtime.rb
99
+ - lib/rtime/rts.rb
100
+ - lib/rtime/version.rb
101
+ - rtime.gemspec
102
+ homepage: https://github.com/at-shakil/rtime
103
+ licenses:
104
+ - MIT
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.6.11
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: RTime is a random timestamp generator
126
+ test_files: []