menstruacion 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
+ SHA1:
3
+ metadata.gz: fcff29b16d3f4259edec0d26ba6747942bf6c7ad
4
+ data.tar.gz: ac3e4a2bec4e78d72ab67295c1697b809e03875b
5
+ SHA512:
6
+ metadata.gz: ce0071536dd351c86b4931ab6d803365d56ff6b3ed82e5559f6bc203e591c4633c0ae1fd99e01287554a2385080f8a6e745ad5da5756fde6cb4098b774b2f343
7
+ data.tar.gz: 61b1fab53050ad6da6e8d7dcfe462cd2159d269c92584939f196c34ebb5d9f759d93147955002cb64b63c843a2ee32a4cb98306636ca42868e5463b37b7e0b37
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --require spec-helper
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - "2.2"
5
+
6
+ before_install: gem install bundler
7
+
8
+ script: bundle exec rspec
9
+
10
+ git:
11
+ submodules: false
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'rspec', require: false
6
+ gem 'simplecov', require: false
7
+ gem 'coveralls', require: false
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 mrubi
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,53 @@
1
+ # Menstruación
2
+
3
+ A simple DSL to do stuff with time periods.
4
+
5
+ It feels natural. Period.
6
+
7
+ ## Status
8
+
9
+ [![Gem Version](https://badge.fury.io/rb/menstruacion.svg)](https://badge.fury.io/rb/menstruacion)
10
+ [![Build Status](https://travis-ci.org/cabeza-de-termo/menstruacion.svg?branch=master)](https://travis-ci.org/cabeza-de-termo/menstruacion)
11
+ [![Coverage Status](https://coveralls.io/repos/github/cabeza-de-termo/menstruacion/badge.svg?branch=master)](https://coveralls.io/github/cabeza-de-termo/menstruacion?branch=master)
12
+
13
+ ## Installation
14
+
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem 'menstruacion', '~> 0.1'
20
+ ```
21
+
22
+
23
+ ## Usage
24
+
25
+ Wanna have a taste of `menstruación`? I know I do. Here it is:
26
+
27
+ ```ruby
28
+ period = CdT::Days[1] + CdT::Hours[3] + CdT::Minutes[30]
29
+ period.as_hours.to_f
30
+ period.as_minutes.to_f
31
+ period.as_seconds.to_f
32
+
33
+ period < CdT::Hours[5] + CdT::Minutes[15]
34
+ ```
35
+
36
+ See? It's bloody simple. It flows naturally. Just flow with it.
37
+
38
+
39
+ ## Wait... I mean... you really... you know... like... why should I... dafaq dude?!
40
+
41
+ Why shouldn't you?
42
+
43
+ And yes. I really do. And I love it.
44
+
45
+
46
+ ## Contributing
47
+
48
+ Bug reports and pull requests are welcome on GitHub at https://github.com/cabeza-de-termo/menstruacion.
49
+
50
+
51
+ ## License
52
+
53
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,9 @@
1
+ module CdT
2
+ class Days < TimeDuration
3
+ CONVERTION_CONSTANT = Hours::CONVERTION_CONSTANT * 24
4
+
5
+ def units
6
+ :days
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module CdT
2
+ class Hours < TimeDuration
3
+ CONVERTION_CONSTANT = Minutes::CONVERTION_CONSTANT * 60
4
+
5
+ def units
6
+ :hours
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module CdT
2
+ class Minutes < TimeDuration
3
+ CONVERTION_CONSTANT = Seconds::CONVERTION_CONSTANT * 60
4
+
5
+ def units
6
+ :minutes
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module CdT
2
+ class Seconds < TimeDuration
3
+ CONVERTION_CONSTANT = 1
4
+
5
+ def units
6
+ :seconds
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,110 @@
1
+ module CdT
2
+ class TimeDuration
3
+ # Creating instances
4
+
5
+ def self.from_seconds(amount_of_seconds)
6
+ self.new(0).tap { |duration|
7
+ duration.set_amount_of_seconds(amount_of_seconds)
8
+ }.freeze
9
+ end
10
+
11
+ def self.from(from_date_time, to:)
12
+ from_seconds( (to - from_date_time) * Days::CONVERTION_CONSTANT)
13
+ end
14
+
15
+ def self.[](amount)
16
+ self.new(amount).freeze
17
+ end
18
+
19
+ # Initializing
20
+
21
+ def initialize(amount)
22
+ @amount_of_seconds = amount * self.class::CONVERTION_CONSTANT
23
+ end
24
+
25
+ # Accessing
26
+
27
+ def amount_of_seconds
28
+ @amount_of_seconds
29
+ end
30
+
31
+ def units
32
+ CdT.subclass_responsibility
33
+ end
34
+
35
+ # Converting
36
+
37
+ def to_f()
38
+ amount_of_seconds.to_f / self.class::CONVERTION_CONSTANT
39
+ end
40
+
41
+ def to_i()
42
+ to_f.to_i
43
+ end
44
+
45
+ def as_seconds()
46
+ Seconds.from_seconds(amount_of_seconds)
47
+ end
48
+
49
+ def as_minutes()
50
+ Minutes.from_seconds(amount_of_seconds)
51
+ end
52
+
53
+ def as_hours()
54
+ Hours.from_seconds(amount_of_seconds)
55
+ end
56
+
57
+ def as_days()
58
+ Days.from_seconds(amount_of_seconds)
59
+ end
60
+
61
+ def as_weeks()
62
+ Weeks.from_seconds(amount_of_seconds)
63
+ end
64
+
65
+ # Arithmetic
66
+
67
+ def +(time_duration)
68
+ self.class.from_seconds(amount_of_seconds + time_duration.amount_of_seconds)
69
+ end
70
+
71
+ def -(time_duration)
72
+ self.class.from_seconds(amount_of_seconds - time_duration.amount_of_seconds)
73
+ end
74
+
75
+ def *(scalar)
76
+ self.class.from_seconds(amount_of_seconds * scalar)
77
+ end
78
+
79
+ def /(scalar)
80
+ self.class.from_seconds(amount_of_seconds.to_f / scalar)
81
+ end
82
+
83
+ # Comparing
84
+
85
+ def <(time_duration)
86
+ amount_of_seconds < time_duration.amount_of_seconds
87
+ end
88
+
89
+ def <=(time_duration)
90
+ amount_of_seconds <= time_duration.amount_of_seconds
91
+ end
92
+
93
+ def >(time_duration)
94
+ amount_of_seconds > time_duration.amount_of_seconds
95
+ end
96
+
97
+ def >=(time_duration)
98
+ amount_of_seconds >= time_duration.amount_of_seconds
99
+ end
100
+
101
+ def ==(time_duration)
102
+ amount_of_seconds == time_duration.amount_of_seconds
103
+ end
104
+
105
+ # Private - Set the amount of seconds
106
+ def set_amount_of_seconds(amount_of_seconds)
107
+ @amount_of_seconds = amount_of_seconds
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,5 @@
1
+ module CdT
2
+ module Menstruacion
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ module CdT
2
+ class Weeks < TimeDuration
3
+ CONVERTION_CONSTANT = Days::CONVERTION_CONSTANT * 7
4
+
5
+ def units
6
+ :weeks
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ require 'cdt/utilities'
2
+ require 'menstruacion/version'
3
+ require 'menstruacion/time-duration'
4
+ require 'menstruacion/seconds'
5
+ require 'menstruacion/minutes'
6
+ require 'menstruacion/hours'
7
+ require 'menstruacion/days'
8
+ require 'menstruacion/weeks'
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'menstruacion/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "menstruacion"
8
+ spec.version = CdT::Menstruacion::VERSION
9
+ spec.authors = ["Martin Rubi"]
10
+ spec.email = ["martinrubi@gmail.com"]
11
+
12
+ spec.summary = %q{A natural DSL to handle time durations. Period.}
13
+ spec.homepage = "https://github.com/cabeza-de-termo/menstruacion"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "cdt-utilities", "~> 0.4"
22
+ spec.add_development_dependency "bundler", "~> 1.11"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: menstruacion
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Martin Rubi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-05-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: cdt-utilities
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.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.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.11'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.11'
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
+ description:
56
+ email:
57
+ - martinrubi@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - lib/menstruacion.rb
70
+ - lib/menstruacion/days.rb
71
+ - lib/menstruacion/hours.rb
72
+ - lib/menstruacion/minutes.rb
73
+ - lib/menstruacion/seconds.rb
74
+ - lib/menstruacion/time-duration.rb
75
+ - lib/menstruacion/version.rb
76
+ - lib/menstruacion/weeks.rb
77
+ - menstruacion.gemspec
78
+ homepage: https://github.com/cabeza-de-termo/menstruacion
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.6.3
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: A natural DSL to handle time durations. Period.
102
+ test_files: []