taw 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +28 -0
- data/LICENSE +21 -0
- data/README.md +53 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/taw.rb +97 -0
- data/lib/taw/version.rb +3 -0
- data/taw.gemspec +26 -0
- metadata +113 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b3b9a19c55e5617db5db2515ac68aea8ee0b11d79dfc7020c5acb5238e388166
|
4
|
+
data.tar.gz: 52b4fe9f40ee42375290ac0c482f93aa54616d8e261a427fab5881d522bb1381
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ac42d4fca0c8b983350c9d86fb8c15875dcb49218f7fa72eaacc66c64f057a7aeed39f0d879a57f29b2e083c9c8fae98db5a858e0991d2969f7f59e12ee52c37
|
7
|
+
data.tar.gz: 0e37234d8a401c648cbd3fecc5a2666869389f98eb5566ef4ddb5dad60194b1546774bd1a30e808cbee60679bea9308c2c39f101b4f66e214de4f9c4cd556465
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at shime@twobucks.co. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
taw (1.0.0pre)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
coderay (1.1.2)
|
10
|
+
method_source (0.9.0)
|
11
|
+
minitest (5.11.3)
|
12
|
+
pry (0.11.3)
|
13
|
+
coderay (~> 1.1.0)
|
14
|
+
method_source (~> 0.9.0)
|
15
|
+
rake (10.5.0)
|
16
|
+
|
17
|
+
PLATFORMS
|
18
|
+
ruby
|
19
|
+
|
20
|
+
DEPENDENCIES
|
21
|
+
bundler (~> 1.16)
|
22
|
+
minitest (~> 5.0)
|
23
|
+
pry
|
24
|
+
rake (~> 10.0)
|
25
|
+
taw!
|
26
|
+
|
27
|
+
BUNDLED WITH
|
28
|
+
1.16.1
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Hrvoje Šimić
|
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
|
+
# Taw
|
2
|
+
|
3
|
+
**T**ime **A**go in **W**ords helper for non Rails projects.
|
4
|
+
No dependencies. No assumptions about your codebase.
|
5
|
+
|
6
|
+
## Usage
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
require "taw"
|
10
|
+
|
11
|
+
Taw.time_ago_in_words(Time.now - 60 * 60 * 2) + " ago"
|
12
|
+
# => "2 hours ago"
|
13
|
+
|
14
|
+
Taw.time_ago_in_words(Time.now - 63) + " ago"
|
15
|
+
# => "1 minute and 3 seconds ago"
|
16
|
+
|
17
|
+
Taw.time_ago_in_words(Time.now - 60 * 60 * 2 - 63) + " ago"
|
18
|
+
# => "2 hours and 1 minute and 3 seconds ago"
|
19
|
+
```
|
20
|
+
|
21
|
+
## Installation
|
22
|
+
|
23
|
+
Add this line to your application's Gemfile:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
gem 'taw'
|
27
|
+
```
|
28
|
+
|
29
|
+
And then execute:
|
30
|
+
|
31
|
+
$ bundle
|
32
|
+
|
33
|
+
Or install it yourself as:
|
34
|
+
|
35
|
+
$ gem install taw
|
36
|
+
|
37
|
+
## Development
|
38
|
+
|
39
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
40
|
+
|
41
|
+
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).
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
46
|
+
|
47
|
+
## Code of Conduct
|
48
|
+
|
49
|
+
Everyone interacting in the Taw project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/shime/taw/blob/master/CODE_OF_CONDUCT.md).
|
50
|
+
|
51
|
+
## License
|
52
|
+
|
53
|
+
[MIT](/LICENSE)
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "taw"
|
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/setup
ADDED
data/lib/taw.rb
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
require "taw/version"
|
2
|
+
|
3
|
+
module Taw
|
4
|
+
MINUTE_IN_SECONDS = 60
|
5
|
+
HOUR_IN_SECONDS = MINUTE_IN_SECONDS * 60
|
6
|
+
DAY_IN_SECONDS = HOUR_IN_SECONDS * 24
|
7
|
+
WEEK_IN_SECONDS = DAY_IN_SECONDS * 7
|
8
|
+
MONTH_IN_SECONDS = DAY_IN_SECONDS * 30
|
9
|
+
YEAR_IN_SECONDS = MONTH_IN_SECONDS * 12
|
10
|
+
|
11
|
+
def self.time_ago_in_words(time)
|
12
|
+
Calculator.new.time_ago_in_words(time)
|
13
|
+
end
|
14
|
+
|
15
|
+
class Calculator
|
16
|
+
def time_ago_in_words(time)
|
17
|
+
self.distance = Time.now - time
|
18
|
+
calculate_distance
|
19
|
+
output_distance
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
attr_accessor :distance,
|
25
|
+
:seconds,
|
26
|
+
:minutes,
|
27
|
+
:hours,
|
28
|
+
:days,
|
29
|
+
:weeks,
|
30
|
+
:months,
|
31
|
+
:years
|
32
|
+
|
33
|
+
def calculate_distance
|
34
|
+
while distance > 0
|
35
|
+
if distance < MINUTE_IN_SECONDS
|
36
|
+
build_seconds
|
37
|
+
elsif distance < HOUR_IN_SECONDS
|
38
|
+
build_minutes
|
39
|
+
elsif distance < DAY_IN_SECONDS
|
40
|
+
build_hours
|
41
|
+
elsif distance < WEEK_IN_SECONDS
|
42
|
+
build_days
|
43
|
+
elsif distance < MONTH_IN_SECONDS
|
44
|
+
build_weeks
|
45
|
+
elsif distance < YEAR_IN_SECONDS
|
46
|
+
build_months
|
47
|
+
else
|
48
|
+
build_years
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def build_seconds
|
54
|
+
self.seconds, self.distance = distance.to_i, 0
|
55
|
+
end
|
56
|
+
|
57
|
+
def build_minutes
|
58
|
+
self.minutes, self.distance = distance.divmod(MINUTE_IN_SECONDS)
|
59
|
+
end
|
60
|
+
|
61
|
+
def build_hours
|
62
|
+
self.hours, self.distance = distance.divmod(HOUR_IN_SECONDS)
|
63
|
+
end
|
64
|
+
|
65
|
+
def build_days
|
66
|
+
self.days, self.distance = distance.divmod(DAY_IN_SECONDS)
|
67
|
+
end
|
68
|
+
|
69
|
+
def build_weeks
|
70
|
+
self.weeks, self.distance = distance.divmod(WEEK_IN_SECONDS)
|
71
|
+
end
|
72
|
+
|
73
|
+
def build_months
|
74
|
+
self.months, self.distance = distance.divmod(MONTH_IN_SECONDS)
|
75
|
+
end
|
76
|
+
|
77
|
+
def build_years
|
78
|
+
self.years, self.distance = distance.divmod(YEAR_IN_SECONDS)
|
79
|
+
end
|
80
|
+
|
81
|
+
def output_distance
|
82
|
+
[
|
83
|
+
("#{years} #{pluralize(years, "year", "years")}" if years && years > 0),
|
84
|
+
("#{months} #{pluralize(months, "month", "months")}" if months && months > 0),
|
85
|
+
("#{weeks} #{pluralize(weeks, "week", "weeks")}" if weeks && weeks > 0),
|
86
|
+
("#{days} #{pluralize(days, "day", "days")}" if days && days > 0),
|
87
|
+
("#{hours} #{pluralize(hours, "hour", "hours")}" if hours && hours > 0),
|
88
|
+
("#{minutes} #{pluralize(minutes, "minute", "minutes")}" if minutes && minutes > 0),
|
89
|
+
("#{seconds} #{pluralize(seconds, "second", "seconds")}" if seconds && seconds > 0)
|
90
|
+
].compact.join(" and ")
|
91
|
+
end
|
92
|
+
|
93
|
+
def pluralize(count, singular, plural)
|
94
|
+
count > 1 ? plural : singular
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
data/lib/taw/version.rb
ADDED
data/taw.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "taw/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "taw"
|
7
|
+
spec.version = Taw::VERSION
|
8
|
+
spec.authors = ["Hrvoje Šimić"]
|
9
|
+
spec.email = ["shime@twobucks.co"]
|
10
|
+
|
11
|
+
spec.summary = %q{Time ago in words helper for non Rails projects.}
|
12
|
+
spec.homepage = "https://github.com/shime/taw"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
17
|
+
end
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
25
|
+
spec.add_development_dependency "pry"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: taw
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hrvoje Šimić
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-01-28 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: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
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'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- shime@twobucks.co
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".travis.yml"
|
78
|
+
- CODE_OF_CONDUCT.md
|
79
|
+
- Gemfile
|
80
|
+
- Gemfile.lock
|
81
|
+
- LICENSE
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
86
|
+
- lib/taw.rb
|
87
|
+
- lib/taw/version.rb
|
88
|
+
- taw.gemspec
|
89
|
+
homepage: https://github.com/shime/taw
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.7.3
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: Time ago in words helper for non Rails projects.
|
113
|
+
test_files: []
|