labtime 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9df5928a6e0a89b97214af314f4887ebe3c534f42b7a8b474c7063f9dfb3cbb4
4
+ data.tar.gz: 7e3c201ec39bf0eb48c040e6cbb23a5d3bbdc816ec2757d2b391c5129d5ed3ae
5
+ SHA512:
6
+ metadata.gz: 40f06438d4e409d853181106e44722300e83db0e270c9406afe20660720405b3241af31b4cb5fc8e58aa51418c96071baa350b636c96692cdfd7628d94412810
7
+ data.tar.gz: 993fc77a68da862c1a404745e29797f5fc978a1bf050c68b2b6d41879d40836f17bcf8cfe60eab5032b61736de5a85ce52a30c8c1cd73066d061f252f38210db
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.1
5
+ before_install: gem install bundler -v 1.16.2
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in labtime.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,50 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ labtime (0.1.0)
5
+ activesupport (~> 4.2.0)
6
+ thor
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (4.2.10)
12
+ i18n (~> 0.7)
13
+ minitest (~> 5.1)
14
+ thread_safe (~> 0.3, >= 0.3.4)
15
+ tzinfo (~> 1.1)
16
+ concurrent-ruby (1.0.5)
17
+ diff-lcs (1.3)
18
+ i18n (0.9.5)
19
+ concurrent-ruby (~> 1.0)
20
+ minitest (5.11.3)
21
+ rake (10.5.0)
22
+ rspec (3.7.0)
23
+ rspec-core (~> 3.7.0)
24
+ rspec-expectations (~> 3.7.0)
25
+ rspec-mocks (~> 3.7.0)
26
+ rspec-core (3.7.1)
27
+ rspec-support (~> 3.7.0)
28
+ rspec-expectations (3.7.0)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.7.0)
31
+ rspec-mocks (3.7.0)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.7.0)
34
+ rspec-support (3.7.1)
35
+ thor (0.20.0)
36
+ thread_safe (0.3.6)
37
+ tzinfo (1.2.5)
38
+ thread_safe (~> 0.1)
39
+
40
+ PLATFORMS
41
+ ruby
42
+
43
+ DEPENDENCIES
44
+ bundler (~> 1.16)
45
+ labtime!
46
+ rake (~> 10.0)
47
+ rspec (~> 3.0)
48
+
49
+ BUNDLED WITH
50
+ 1.16.2
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Piotr Mankowski
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,36 @@
1
+ # Labtime
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/Labtime`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'Labtime'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install Labtime
21
+
22
+ ## Usage
23
+
24
+ ## Development
25
+
26
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
27
+
28
+ 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).
29
+
30
+ ## Contributing
31
+
32
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/Labtime.
33
+
34
+ ## License
35
+
36
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "labtime"
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/labtime ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'labtime'
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1 @@
1
+ CLI.start(ARGV)
data/exe/labtime ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "labtime"
4
+ Labtime::CLI.start(ARGV)
@@ -0,0 +1,8 @@
1
+ {
2
+ "folders": [
3
+ {
4
+ "path": "."
5
+ }
6
+ ],
7
+ "settings": {}
8
+ }
data/labtime.gemspec ADDED
@@ -0,0 +1,31 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "labtime/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "labtime"
8
+ spec.version = Labtime::VERSION
9
+ spec.authors = ["Piotr Mankowski"]
10
+ spec.email = ["pmanko@uw.edu"]
11
+
12
+ spec.summary = %q{Labtime conversion tool and CLI}
13
+ spec.homepage = "https://github.com/bwhsleepamu/labtime"
14
+ spec.license = "MIT"
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.16"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+
29
+ spec.add_dependency "activesupport", "~> 4.2.0"
30
+ spec.add_dependency "thor"
31
+ end
File without changes
@@ -0,0 +1,120 @@
1
+ # https://bundler.io/v1.16/guides/creating_gem.html
2
+ # https://www.rubydoc.info/gems/yard/file/docs/GettingStarted.md
3
+ require 'active_support'
4
+ require 'active_support/time'
5
+ module Labtime
6
+
7
+ class Labtime
8
+ include Comparable
9
+
10
+ attr_accessor :year, :hour, :min, :sec, :time_zone
11
+ DEFAULT_TIME_ZONE = ActiveSupport::TimeZone.new("Eastern Time (US & Canada)")
12
+
13
+ # Class Methods
14
+ def self.parse(realtime)
15
+ # Return nil if nil parameter
16
+ return nil if realtime.nil?
17
+
18
+ # Make sure datetime is an ActiveSupport:TimeWithZone object
19
+ unless realtime.is_a?(ActiveSupport::TimeWithZone)
20
+ raise ArgumentError, "realtime class #{realtime.class} is not ActiveSupport::TimeWithZone"
21
+ end
22
+
23
+ year = realtime.year
24
+
25
+ # Use the start of the given year as a reference for finding Labtime
26
+ Time.zone = realtime.time_zone
27
+ reference_time = Time.zone.local(year)
28
+
29
+ # find difference between the reference time and the time sent to the method
30
+ difference_in_seconds = realtime.to_i - reference_time.to_i
31
+
32
+ # convert difference in seconds to labtime
33
+ hour = difference_in_seconds / 3600
34
+ min = (difference_in_seconds - (hour * 3600)) / 60
35
+ sec = (difference_in_seconds - (hour * 3600) - (min * 60))
36
+
37
+
38
+ self.new(year, hour, min, sec, realtime.time_zone)
39
+ end
40
+
41
+ def self.from_decimal(decimal_labtime, year, time_zone = ActiveSupport::TimeZone.new("Eastern Time (US & Canada)"))
42
+ raise ArguementError, "No year supplied!" if year.blank?
43
+
44
+ hour = decimal_labtime.to_i
45
+ remainder = decimal_labtime - hour.to_f
46
+
47
+ minute_labtime = 6.0 * remainder
48
+ minute = minute_labtime.to_i
49
+
50
+ remainder = minute_labtime - minute.to_f
51
+ sec = (60 * remainder).round.to_i
52
+
53
+ self.new(year, hour, minute, sec, time_zone)
54
+ end
55
+
56
+ def self.from_seconds(sec_time, year, time_zone = DEFAULT_TIME_ZONE)
57
+ hour = (sec_time / 3600.0).to_i
58
+ sec_time = sec_time - (hour * 3600)
59
+ min = (sec_time / 60.0).to_i
60
+ sec_time = sec_time - (min * 60)
61
+ sec = sec_time
62
+
63
+ self.new(year, hour, min, sec, time_zone)
64
+ end
65
+
66
+ def self.from_s(str, time_params = {}, time_zone = DEFAULT_TIME_ZONE)
67
+ time_captures = /(\d+)\:(\d{1,2})(\:(\d{1,2}))?(\s(\d\d\d\d))?\z/.match(str).captures
68
+
69
+ time_params[:hour] ||= time_captures[0]
70
+ time_params[:min] ||= time_captures[1]
71
+ time_params[:sec] ||= time_captures[3]
72
+ time_params[:year] ||= time_captures[5]
73
+
74
+ self.new(time_params[:year], time_params[:hour], time_params[:min], time_params[:sec], time_zone)
75
+ end
76
+
77
+ # Constructor
78
+ def initialize(year, hour, min, sec, time_zone = nil)
79
+ @year = year.to_i
80
+ @hour = hour.to_i
81
+ @min = min.to_i
82
+ @sec = sec.to_i
83
+ @time_zone = time_zone || DEFAULT_TIME_ZONE
84
+ end
85
+
86
+ # Convert Labtime to real time
87
+ def to_time
88
+ reference_time = time_zone.local(year)
89
+ reference_time + time_in_seconds
90
+ end
91
+
92
+ # For Comparable
93
+ def <=>(other)
94
+ to_time <=> other.to_time
95
+ end
96
+
97
+ def to_s
98
+ "#{year} #{hour}:#{min}:#{sec} #{time_zone.to_s}"
99
+ end
100
+
101
+ def to_short_s
102
+ "#{hour}:#{min}:#{sec}"
103
+ end
104
+
105
+ def time_in_seconds
106
+ hour * 3600 + min * 60 + sec
107
+ end
108
+
109
+ def add_seconds(sec)
110
+ self.class.from_seconds(self.time_in_seconds + sec, self.year, self.time_zone)
111
+ end
112
+
113
+ def to_decimal
114
+ hour.to_f + (min.to_f/60.0) + (sec.to_f/3600.0)
115
+ end
116
+
117
+ private
118
+
119
+ end
120
+ end
@@ -0,0 +1,3 @@
1
+ module Labtime
2
+ VERSION = "0.1.0"
3
+ end
data/lib/labtime.rb ADDED
@@ -0,0 +1,23 @@
1
+ require "labtime/version"
2
+ require 'thor'
3
+ require 'labtime/cli'
4
+ require 'labtime/labtime'
5
+
6
+ module Labtime
7
+ class CLI < Thor
8
+ desc "hello [name]", "say my name"
9
+ def hello(name)
10
+ if name == "Heisenberg"
11
+ puts "you are goddman right"
12
+ else
13
+ puts "say my name"
14
+ end
15
+ end
16
+
17
+ desc "convert_decimal [decimal_labtime] [year]", "Convert a decimal labtime in a given year to real time in string format"
18
+ def convert_decimal(decimal, year)
19
+ puts Labtime.from_decimal(decimal.to_f,year.to_i).to_time.to_s
20
+ end
21
+
22
+ end
23
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: labtime
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Piotr Mankowski
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-08-03 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
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 4.2.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 4.2.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: thor
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
85
+ - pmanko@uw.edu
86
+ executables:
87
+ - convert_labtime
88
+ - labtime
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - ".gitignore"
93
+ - ".rspec"
94
+ - ".travis.yml"
95
+ - Gemfile
96
+ - Gemfile.lock
97
+ - LICENSE
98
+ - LICENSE.txt
99
+ - README.md
100
+ - Rakefile
101
+ - bin/console
102
+ - bin/labtime
103
+ - bin/setup
104
+ - exe/convert_labtime
105
+ - exe/labtime
106
+ - labtime.code-workspace
107
+ - labtime.gemspec
108
+ - lib/labtime.rb
109
+ - lib/labtime/cli.rb
110
+ - lib/labtime/labtime.rb
111
+ - lib/labtime/version.rb
112
+ homepage: https://github.com/bwhsleepamu/labtime
113
+ licenses:
114
+ - MIT
115
+ metadata: {}
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubyforge_project:
132
+ rubygems_version: 2.7.6
133
+ signing_key:
134
+ specification_version: 4
135
+ summary: Labtime conversion tool and CLI
136
+ test_files: []