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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 81f47d8695ce0888db7ef05ef042afeb552c66ba
4
- data.tar.gz: 7dd6724306d9511fc88c497c1d431d3c1a9e6e85
3
+ metadata.gz: f9e2ae373791a67913f562e62be256fb232b6175
4
+ data.tar.gz: 542f60fd6c9a6cfc3d58e8e9785598e806def02e
5
5
  SHA512:
6
- metadata.gz: e32b93a89493f3064803be8978de95cabf5748a0da7367aefb4920cf7bdd1c6c2c0c3c817cae6ae7f4127059031b05f296611eb65782f61fd55606deb0299d9c
7
- data.tar.gz: f5daf135c4606b2630078fdb85e8eed97bab3fcd9ec2e7b1a9dfa16f4573c51d42331a77bb6eb5d1a7b6bc79847be1f296683c6d0b447faa9cca91ff3738fdf7
6
+ metadata.gz: 6c5c5152d50cfdd166463bbeefffb5401d77a1a5a7ee17159a4d4084d054a1cbabfd2d4d0d2c0a1b3683f06759140b40e4e23993937c780ca5fd33d0f9126f7e
7
+ data.tar.gz: 7e1a8ae52c6dc57ed063d29408e65c8d852a7e7760006d68ae038f24fe1cf9490c117720e76f6c39908f10fafde769b65a0d6ab2c4dea4621b473f01401ea7f9
@@ -0,0 +1,18 @@
1
+ engines:
2
+ rubocop:
3
+ enabled: true
4
+ channel: rubocop-0-48
5
+ markdownlint:
6
+ enabled: true
7
+ bundler-audit:
8
+ enabled: true
9
+ fixme:
10
+ enabled: true
11
+
12
+ ratings:
13
+ paths:
14
+ - bin/**
15
+ - lib/**
16
+ - "**.rb"
17
+ exclude_paths:
18
+ - test/**
@@ -0,0 +1,12 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.2
3
+ Style/StringLiterals:
4
+ EnforcedStyle: double_quotes
5
+ Style/UnneededCapitalW:
6
+ Enabled: false
7
+ Style/MethodDefParentheses:
8
+ Enabled: false
9
+ Metrics/MethodLength:
10
+ Max: 20
11
+ Metrics/AbcSize:
12
+ Enabled: false
@@ -1,5 +1,20 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.4.1
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
+ [![Build Status](https://travis-ci.org/at-shakil/rtime.svg?branch=master)](https://travis-ci.org/at-shakil/rtime)
4
+ [![Gem Version](https://badge.fury.io/rb/rtime.svg)](https://badge.fury.io/rb/rtime)
5
+ [![Dependency Status](https://gemnasium.com/badges/github.com/at-shakil/rtime.svg)](https://gemnasium.com/github.com/at-shakil/rtime)
6
+ [![Test Coverage](https://codeclimate.com/github/at-shakil/rtime/badges/coverage.svg)](https://codeclimate.com/github/at-shakil/rtime/coverage)
7
+ [![Inline docs](http://inch-ci.org/github/at-shakil/rtime.svg?branch=master)](http://inch-ci.org/github/at-shakil/rtime)
8
+ [![Code Climate](https://codeclimate.com/github/at-shakil/rtime/badges/gpa.svg)](https://codeclimate.com/github/at-shakil/rtime)
9
+ [![Issue Count](https://codeclimate.com/github/at-shakil/rtime/badges/issue_count.svg)](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
- $ gem install rtime
21
+ gem install rtime
12
22
 
13
- If you eventually develop a taste for `rtime`'s tiny API, you may want to follow the steps below.
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
- $ bundle
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
@@ -18,4 +18,4 @@ Rake::TestTask.new(:test) do |t|
18
18
  t.test_files = FileList["test/**/*_test.rb"]
19
19
  end
20
20
 
21
- task :default => :test
21
+ task default: :test
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 :night_only, aliases: ["-n"], type: :boolean,
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
- Example: rtime gen 20170417 20170423 85%
19
- MESSAGE
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 ["gen", "g"] => :generate
30
+ map %W[gen g] => :generate
28
31
  end
29
32
  end
30
33
 
@@ -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 = if options[:night_only]
9
- ((20..23).to_a + (0..5).to_a).sample
10
- else
11
- (0..23).to_a.sample
12
- end
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
- 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"
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 = self._parse_date date1
46
+ year, month, day = _parse_date date1
45
47
  date1 = Time.new year, month, day
46
- year, month, day = self._parse_date date2
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 = self._time_for(options)
54
- range.push Time.new(tmp_date.year, tmp_date.month,
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(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
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
@@ -1,4 +1,4 @@
1
1
  module RTime
2
2
  # Gem version specifier
3
- VERSION = "0.1.0".freeze
3
+ VERSION = "0.1.1".freeze
4
4
  end
@@ -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 = %q{RTime is a random timestamp generator}
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", "~> 10.0"
27
+ spec.add_development_dependency "rake", "~> 12.0"
27
28
  spec.add_development_dependency "minitest", "~> 5.0"
28
- spec.add_development_dependency "simplecov", "~> 0.14"
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.0
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-13 00:00:00.000000000 Z
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: '10.0'
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: '10.0'
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.14'
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.14'
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.6.11
138
+ rubygems_version: 2.4.5
123
139
  signing_key:
124
140
  specification_version: 4
125
141
  summary: RTime is a random timestamp generator