hour-ruby 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +16 -3
  3. data/lib/hour.rb +17 -5
  4. data/spec/hour_spec.rb +3 -0
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b037de6a208ce2bf419a9e1cf5558ecbfc8885e3ee28c58e0f958242c0a75764
4
- data.tar.gz: eec358d6872bc3414c6a5789db74a688cc211381aead80b12cad3eca0601b57f
3
+ metadata.gz: 0a1be05c48e54df485856e200079e23f03e93ccdc785b9c5f20253cab6ef1918
4
+ data.tar.gz: 949992e1b0c54a94a17f964f4ad7114791ec95b83bd4ff3a8c6f15026be4ebb2
5
5
  SHA512:
6
- metadata.gz: aa59a5c611500afb23db52439e8f43754f8e857f96dfd6b209352bb57328668421722e7be59268fd19fd6caa50b0d2b291bd5d3e7242555ff03a40885a7c82c5
7
- data.tar.gz: c70a2bf14a4f3bddf1e3cdbb69a0c391041549b85d2b26a60806cdd94edbd73511e6629ebb94e740599ff610e1d078b4b5cb68d386a68f6f70d9ef6a6504f315
6
+ metadata.gz: 99b789a3f010f5c95acff8bfae7d8a71a88a68d18261287d53b8b01859cdc84c0ee99dd7229c4a4a9e2d2329e3a761bf0eb17074081497bf731231238b79d668
7
+ data.tar.gz: 8bcba1a83adb64a842d9f4c51b802c003502239d93542b735508e7ef86670dd08db5de3e701c1653832d73915e5545a4cbc9f6c47cf3b455f74187bd0dbdf868
data/README.md CHANGED
@@ -1,7 +1,12 @@
1
1
  # About
2
+
3
+ [![Gem version][GV img]][Gem version]
2
4
  [![Build status][BS img]][Build status]
5
+ [![Coverage status][CS img]][Coverage status]
6
+ [![CodeClimate status][CC img]][CodeClimate status]
7
+ [![YARD documentation][YD img]][YARD documentation]
3
8
 
4
- Hour class to work with hours, minutes and seconds, convert between various units and format the output.
9
+ Hour class to work with hours, minutes and seconds, convert between various units and format the output. _Here's version of this library for Crystal: [hour-crystal](https://github.com/botanicus/hour-crystal)._
5
10
 
6
11
  # Installation
7
12
 
@@ -11,7 +16,7 @@ gem install hour-ruby
11
16
 
12
17
  # Usage
13
18
 
14
- ```crystal
19
+ ```ruby
15
20
  require "hour"
16
21
 
17
22
  hour = Hour.from(minutes: 85)
@@ -27,8 +32,16 @@ puts "The system time is #{Hour.now}!"
27
32
 
28
33
  - Rubocop.
29
34
  - Travis.
30
- - Link hour-crystal.
31
35
  - Release version 0.1.
32
36
 
37
+ [Gem version]: https://rubygems.org/gems/hour-ruby
33
38
  [Build status]: https://travis-ci.org/botanicus/hour-ruby
39
+ [Coverage status]: https://coveralls.io/github/botanicus/hour-ruby
40
+ [CodeClimate status]: https://codeclimate.com/github/botanicus/hour-ruby/maintainability
41
+ [YARD documentation]: http://www.rubydoc.info/github/botanicus/hour-ruby/master
42
+
43
+ [GV img]: https://badge.fury.io/rb/hour-ruby.svg
34
44
  [BS img]: https://travis-ci.org/botanicus/hour-ruby.svg?branch=master
45
+ [CS img]: https://img.shields.io/coveralls/botanicus/hour-ruby.svg
46
+ [CC img]: https://api.codeclimate.com/v1/badges/a99a88d28ad37a79dbf6/maintainability
47
+ [YD img]: http://img.shields.io/badge/yard-docs-blue.svg
data/lib/hour.rb CHANGED
@@ -62,7 +62,7 @@ class Hour
62
62
 
63
63
  # TODO: document and write tests.
64
64
  def self.from_time(time)
65
- self.new(h: time.hours, m: time.minutes, s: time.seconds)
65
+ self.new(time.hour, time.min, time.sec)
66
66
  end
67
67
 
68
68
  # Build an hour instance from an hour string.
@@ -71,12 +71,12 @@ class Hour
71
71
  # Hour.parse("1:00", "%h:%m?") # Will work with "1:00" or just "1".
72
72
  #
73
73
  # TODO: Implement me, test me and document me.
74
- def self.parse(string, formatting_string = nil)
75
- argument_array = serialised_hour.split(':').map(&:to_i)
74
+ def self.parse(serialised_hour, formatting_string = nil)
75
+ args = serialised_hour.split(':').map(&:to_i)
76
76
 
77
- case argument_array.size
77
+ case args.length
78
78
  when 3
79
- self.new(*argument_array)
79
+ self.new(*args)
80
80
  when (0..2)
81
81
  # TODO: if formatting_string ...
82
82
  raise ArgumentError.new("If format is not H:M:S, formatting string must be provided.")
@@ -174,6 +174,18 @@ class Hour
174
174
  Time.new(today.year, today.month, today.day, self.hours, self.minutes_over_the_hour)
175
175
  end
176
176
 
177
+ [:==, :eql?, :<, :<=, :>, :>=, :<=>].each do |method_name|
178
+ define_method(method_name) do |anotherHour|
179
+ if anotherHour.is_a?(self.class)
180
+ self.seconds.total.send(method_name, anotherHour.seconds.total)
181
+ # elsif anotherHour.is_a?(Time)
182
+ # self.send(method_name, Hour.now)
183
+ else
184
+ raise TypeError.new("#{self.class}##{method_name} expects #{self.class} or Time object.")
185
+ end
186
+ end
187
+ end
188
+
177
189
  private
178
190
  def initialize_from_keyword_args(h: 0, m: 0, s: 0)
179
191
  @h, @m, @s = h, m, s
data/spec/hour_spec.rb CHANGED
@@ -1,4 +1,7 @@
1
1
  require "hour"
2
+ require "coveralls"
3
+
4
+ Coveralls.wear!
2
5
 
3
6
  describe Hour do
4
7
  describe ".parse" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hour-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - James C Russell