distance_in_weeks 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in distance_in_weeks.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Ankita kanitkar
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # DistanceInWeeks
2
+
3
+ DistanceInWeeks is a simple gem to calculate the distance of a given date from today's date in weeks and returns the distance in plain english language.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'distance_in_weeks'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install distance_in_weeks
18
+
19
+ ## Usage
20
+
21
+ Examples :
22
+
23
+ DistanceInWeeks.weeks_in_words((Date.today - 2).strftime('%d-%m-%Y'))
24
+
25
+ => less than a week ago
26
+
27
+ DistanceInWeeks.weeks_in_words((Date.today - 15).strftime('%d-%m-%Y'))
28
+
29
+ => about 2 weeks ago
30
+
31
+ DistanceInWeeks.weeks_in_words((Date.today + 3).strftime('%d-%m-%Y'))
32
+
33
+ => about a week from now
34
+
35
+ DistanceInWeeks.weeks_in_words((Date.today + 25).strftime('%d-%m-%Y'))
36
+
37
+ => about 4 weeks from now
38
+
39
+ ## Todos
40
+
41
+ 1. Restrict the usage for only 1 week to 4 weeks rest all to be handled in either no. of days or months.
42
+ 2. A way to implement Internationalization.
43
+
44
+ ## Contributing
45
+
46
+ 1. Fork it ( http://github.com/<my-github-username>/distance_in_weeks/fork )
47
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
48
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
49
+ 4. Push to the branch (`git push origin my-new-feature`)
50
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'distance_in_weeks/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "distance_in_weeks"
8
+ spec.version = DistanceInWeeks::VERSION
9
+ spec.authors = ["Nayana Bhagat,Vaibhav Kholi,Ankita Kanitkar,Milind Singh,Prabhat Thapa,Swarup Mitra"]
10
+ spec.email = ["ankitakanitkar@gmail.com"]
11
+ spec.summary = %q{returns distance of time in weeks}
12
+ spec.description = %q{returns distance of time in weeks}
13
+ spec.homepage = "https://github.com/Gemathon-Lapidarists/distance_in_weeks"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "week_calc"
25
+ end
@@ -0,0 +1,19 @@
1
+ require "distance_in_weeks/version"
2
+ require "week_calc"
3
+
4
+ module DistanceInWeeks
5
+
6
+ def self.weeks_in_words(date)
7
+ weeks = Date.weeks_till_now(date)
8
+ msg = ["less than a week" , "about a week" , "about #{weeks} weeks"]
9
+ if Date.strptime(date , "%d-%m-%Y") > Date.today
10
+ return "#{msg[0]} from now" if weeks == 0
11
+ return "#{msg[1]} from now" if weeks == 1
12
+ return "#{msg[2]} from now" if weeks > 1
13
+ else
14
+ return "#{msg[0]} ago" if weeks == 0
15
+ return "#{msg[1]} ago" if weeks == 1
16
+ return "#{msg[2]} ago" if weeks > 1
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module DistanceInWeeks
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,30 @@
1
+ require 'distance_in_weeks'
2
+
3
+ describe DistanceInWeeks do
4
+
5
+ it "should return less than a week ago if difference of days is less than 7" do
6
+ week_in_words = DistanceInWeeks.weeks_in_words((Date.today - 2).strftime('%d-%m-%Y'))
7
+ week_in_words.should == "less than a week ago"
8
+ end
9
+ it "should return about a week ago if difference of days is greater than a week and less than 2 weeks" do
10
+ week_in_words = DistanceInWeeks.weeks_in_words((Date.today - 10).strftime('%d-%m-%Y'))
11
+ week_in_words.should == "about a week ago"
12
+ end
13
+ it "should return about 2 weeks ago if difference of days is greater than two weeks and less than 3 weeks" do
14
+ week_in_words = DistanceInWeeks.weeks_in_words((Date.today - 15).strftime('%d-%m-%Y'))
15
+ week_in_words.should == "about 2 weeks ago"
16
+ end
17
+ it "should return about a week from now if the date is less than a week from now" do
18
+ week_in_words = DistanceInWeeks.weeks_in_words((Date.today + 3).strftime('%d-%m-%Y'))
19
+ week_in_words.should == "about a week from now"
20
+ end
21
+ it "should return about 2 weeks from now if the date is greater than a week and less than 2 weeks from now" do
22
+ week_in_words = DistanceInWeeks.weeks_in_words((Date.today + 8).strftime('%d-%m-%Y'))
23
+ week_in_words.should == "about 2 weeks from now"
24
+ end
25
+ it "should return about 4 weeks from now if the date is greater than 3 weeks and less than 4 weeks from now" do
26
+ week_in_words = DistanceInWeeks.weeks_in_words((Date.today + 25).strftime('%d-%m-%Y'))
27
+ week_in_words.should == "about 4 weeks from now"
28
+ end
29
+
30
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: distance_in_weeks
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Nayana Bhagat,Vaibhav Kholi,Ankita Kanitkar,Milind Singh,Prabhat Thapa,Swarup Mitra
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-02-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: &81670460 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.5'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *81670460
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &81669630 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *81669630
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &81666140 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *81666140
47
+ - !ruby/object:Gem::Dependency
48
+ name: week_calc
49
+ requirement: &81682670 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *81682670
58
+ description: returns distance of time in weeks
59
+ email:
60
+ - ankitakanitkar@gmail.com
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - .gitignore
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - distance_in_weeks.gemspec
71
+ - lib/distance_in_weeks.rb
72
+ - lib/distance_in_weeks/version.rb
73
+ - spec/distance_in_weeks_spec.rb
74
+ homepage: https://github.com/Gemathon-Lapidarists/distance_in_weeks
75
+ licenses:
76
+ - MIT
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 1.8.17
96
+ signing_key:
97
+ specification_version: 3
98
+ summary: returns distance of time in weeks
99
+ test_files:
100
+ - spec/distance_in_weeks_spec.rb