warpera 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +0 -2
- data/README.md +32 -11
- data/lib/warpera/pair.rb +36 -1
- data/lib/warpera/version.rb +1 -1
- data/lib/warpera.rb +12 -1
- data/warpera.gemspec +32 -19
- metadata +25 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3643b139db3291db0a36370efa57df460986450bed4d9d143382b09e688d6ee9
|
4
|
+
data.tar.gz: 683c91b283a64db1987e0c577edfb01ca3c58cfd25573d3a6bb08541ef69d66a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5925947fbfd8375aec03e94b13c00dbcd3bfd99847e645b808f30ff64f370ca2fb0c0dabdf9ba838ed61c49b473510e215764ace1799ee9fe452a6e6d9871fcd
|
7
|
+
data.tar.gz: 42f8865e9650da9946ad1c9d66873ba2e8baca233f0d5bd49fb453744cc047c7c25a6c7692c0e747060062d9e89cd3aef247ac3ece9242b3a2c7ac2e50cecf2a
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,15 +1,13 @@
|
|
1
|
-
#
|
1
|
+
# Warpera
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
A gem that makes working with years in different eras palatable
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
9
7
|
Add this line to your application's Gemfile:
|
10
8
|
|
11
9
|
```ruby
|
12
|
-
gem '
|
10
|
+
gem 'warpera'
|
13
11
|
```
|
14
12
|
|
15
13
|
And then execute:
|
@@ -18,22 +16,45 @@ And then execute:
|
|
18
16
|
|
19
17
|
Or install it yourself as:
|
20
18
|
|
21
|
-
$ gem install
|
19
|
+
$ gem install warpera
|
22
20
|
|
23
21
|
## Usage
|
24
22
|
|
25
|
-
|
23
|
+
Require the gem in your files with:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
require 'warpera'
|
27
|
+
```
|
28
|
+
|
29
|
+
When working directly with the numbers and strings, use the `conv_s` and
|
30
|
+
`conv_i` methods.
|
31
|
+
|
32
|
+
When needing control over the year and era, use the `Warpera::Pair` class. This
|
33
|
+
is helpful, for instance, dealing with storing a year in a database. Instead of
|
34
|
+
potentially storing two fields for one attribute, use this to store one field
|
35
|
+
for the one attribute.
|
26
36
|
|
27
37
|
## Development
|
28
38
|
|
29
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
39
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
40
|
+
`rake spec` to run the tests. You can also run `bin/console` for an interactive
|
41
|
+
prompt that will allow you to experiment.
|
42
|
+
|
43
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To
|
44
|
+
release a new version, update the version number in `version.rb`, and then run
|
45
|
+
`bundle exec rake release`, which will create a git tag for the version, push
|
46
|
+
git commits and tags, and push the `.gem` file to [rubygems.org][1].
|
30
47
|
|
31
|
-
|
48
|
+
[1]: rubygems.org/gems/warpera
|
32
49
|
|
33
50
|
## Contributing
|
34
51
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub
|
52
|
+
Bug reports and pull requests are welcome on [the GitHub repo][2].
|
53
|
+
|
54
|
+
[2]: https://github.com/parmort/warpera
|
36
55
|
|
37
56
|
## License
|
38
57
|
|
39
|
-
The gem is available as open source under the terms of the [MIT License]
|
58
|
+
The gem is available as open source under the terms of the [MIT License][3]
|
59
|
+
|
60
|
+
[3]: https://opensource.org/licenses/MIT.
|
data/lib/warpera/pair.rb
CHANGED
@@ -1,7 +1,20 @@
|
|
1
1
|
module Warpera
|
2
|
+
# Pairs year and era together for better readability and DRYing
|
2
3
|
class Pair
|
3
|
-
attr_accessor :year, :era
|
4
4
|
|
5
|
+
# The year as a whole number
|
6
|
+
# @return [Integer] the year
|
7
|
+
attr_accessor :year
|
8
|
+
|
9
|
+
# The era
|
10
|
+
# @return [:ce, :bce]
|
11
|
+
attr_accessor :era
|
12
|
+
|
13
|
+
##
|
14
|
+
# Sets the attributes
|
15
|
+
#
|
16
|
+
# @param year [Integer] the year
|
17
|
+
# @param era [:ce, :bce] the era
|
5
18
|
def initialize(year:, era:)
|
6
19
|
@year = year
|
7
20
|
@era = era
|
@@ -10,10 +23,32 @@ module Warpera
|
|
10
23
|
raise ArgumentError, 'Era is not valid' unless valid_era?
|
11
24
|
end
|
12
25
|
|
26
|
+
##
|
27
|
+
# Format the year and era into a string
|
28
|
+
#
|
29
|
+
# @example Current Era
|
30
|
+
# >> Warpera::Pair.new(year: 2019, era: :ce).to_s
|
31
|
+
# => "2019 CE"
|
32
|
+
# @example Previous Era
|
33
|
+
# >> Warpera::Pair.new(year: 2019, era: :bce).to_s
|
34
|
+
# => "2019 BCE"
|
35
|
+
#
|
36
|
+
# @return [String] the formatted year
|
13
37
|
def to_s
|
14
38
|
"#{@year} #{@era.upcase}"
|
15
39
|
end
|
16
40
|
|
41
|
+
##
|
42
|
+
# Format the year and era into an integer
|
43
|
+
#
|
44
|
+
# @example Current Era
|
45
|
+
# >> Warpera::Pair.new(year: 2019, era: :ce).to_s
|
46
|
+
# => 2019
|
47
|
+
# @example Previous Era
|
48
|
+
# >> Warpera::Pair.new(year: 2019, era: :bce).to_s
|
49
|
+
# => -2019
|
50
|
+
#
|
51
|
+
# @return [Integer] the formatted year
|
17
52
|
def to_i
|
18
53
|
if @era == :bce
|
19
54
|
return -1 * @year
|
data/lib/warpera/version.rb
CHANGED
data/lib/warpera.rb
CHANGED
@@ -1,8 +1,14 @@
|
|
1
|
+
# Deals with years possibly spanning different eras
|
1
2
|
module Warpera
|
2
3
|
require 'warpera/pair'
|
3
4
|
|
5
|
+
##
|
6
|
+
# Convert an integer-formatted year into a string-formatted year
|
7
|
+
#
|
8
|
+
# @param year [Integer] the integer-formatted year
|
9
|
+
# @return [String] the string-formatted year
|
4
10
|
def self.conv_s(year)
|
5
|
-
raise ArgumentError, 'Argument is not
|
11
|
+
raise ArgumentError, 'Argument is not an integer' unless year.is_a? Integer
|
6
12
|
|
7
13
|
if year < 0
|
8
14
|
"#{-1 * year} BCE"
|
@@ -11,6 +17,11 @@ module Warpera
|
|
11
17
|
end
|
12
18
|
end
|
13
19
|
|
20
|
+
##
|
21
|
+
# Convert a string-formatted year into an integer-formatted year
|
22
|
+
#
|
23
|
+
# @param year [String] the string-formatted year
|
24
|
+
# @return [Integer] the integer-formatted year
|
14
25
|
def self.conv_i(year)
|
15
26
|
raise ArgumentError, 'Argument is not a string' unless year.is_a? String
|
16
27
|
|
data/warpera.gemspec
CHANGED
@@ -2,26 +2,39 @@ lib = File.expand_path("../lib", __FILE__)
|
|
2
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
3
|
require "warpera/version"
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
module GemSpec
|
6
|
+
def self.load_git_files
|
7
|
+
Dir.chdir(File.expand_path('..', __FILE__)) do
|
8
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
|
13
|
+
Gem::Specification.new do |s|
|
14
|
+
s.name = "warpera"
|
15
|
+
s.version = Warpera::VERSION
|
16
|
+
s.author = "Nolan Prochnau"
|
17
|
+
s.email = ["parvus.mortalis@gmail.com"]
|
18
|
+
s.summary = "A gem that makes working with years in different eras palatable"
|
19
|
+
s.homepage = "https://github.com/parmort/warpera"
|
20
|
+
s.license = "MIT"
|
21
|
+
s.files = GemSpec.load_git_files
|
22
|
+
s.bindir = "exe"
|
23
|
+
s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
s.require_paths = ["lib"]
|
25
|
+
s.required_ruby_version = '~> 2'
|
26
|
+
s.extra_rdoc_files = ['README.md']
|
14
27
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
spec.require_paths = ["lib"]
|
28
|
+
s.metadata = {
|
29
|
+
"bug_tracker_uri" => "https://github.com/parmort/warpera/issues",
|
30
|
+
"changelog_uri" => "https://github.com/parmort/warpera/blob/master/CHANGELOG.md",
|
31
|
+
"documentation_uri" => "https://www.example.info/gems/bestgemever/0.0.1",
|
32
|
+
"homepage_uri" => "https://github.com/parmort/warpera",
|
33
|
+
"source_code_uri" => "https://github.com/parmort/warpera"
|
34
|
+
}
|
23
35
|
|
24
|
-
|
25
|
-
|
26
|
-
|
36
|
+
s.add_development_dependency "bundler", "~> 2.0"
|
37
|
+
s.add_development_dependency "rake", "~> 10.0"
|
38
|
+
s.add_development_dependency "rspec", "~> 3.0"
|
39
|
+
s.add_development_dependency "fivemat"
|
27
40
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: warpera
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nolan Prochnau
|
@@ -52,12 +52,27 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: fivemat
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
description:
|
56
70
|
email:
|
57
71
|
- parvus.mortalis@gmail.com
|
58
72
|
executables: []
|
59
73
|
extensions: []
|
60
|
-
extra_rdoc_files:
|
74
|
+
extra_rdoc_files:
|
75
|
+
- README.md
|
61
76
|
files:
|
62
77
|
- ".gitignore"
|
63
78
|
- ".rspec"
|
@@ -81,16 +96,21 @@ files:
|
|
81
96
|
homepage: https://github.com/parmort/warpera
|
82
97
|
licenses:
|
83
98
|
- MIT
|
84
|
-
metadata:
|
99
|
+
metadata:
|
100
|
+
bug_tracker_uri: https://github.com/parmort/warpera/issues
|
101
|
+
changelog_uri: https://github.com/parmort/warpera/blob/master/CHANGELOG.md
|
102
|
+
documentation_uri: https://www.example.info/gems/bestgemever/0.0.1
|
103
|
+
homepage_uri: https://github.com/parmort/warpera
|
104
|
+
source_code_uri: https://github.com/parmort/warpera
|
85
105
|
post_install_message:
|
86
106
|
rdoc_options: []
|
87
107
|
require_paths:
|
88
108
|
- lib
|
89
109
|
required_ruby_version: !ruby/object:Gem::Requirement
|
90
110
|
requirements:
|
91
|
-
- - "
|
111
|
+
- - "~>"
|
92
112
|
- !ruby/object:Gem::Version
|
93
|
-
version: '
|
113
|
+
version: '2'
|
94
114
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
115
|
requirements:
|
96
116
|
- - ">="
|