datey 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/datey.rb +2 -2
  3. data/lib/datey/formatter.rb +11 -6
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ab3c2439b0aed6242f6fb27a7629c592d426d081
4
- data.tar.gz: bd46309c4ad4fa17ef2dd06bf4b84d4a1d67eb02
3
+ metadata.gz: 4c021b138f9ffc9f5120511ea6475344f9d5a857
4
+ data.tar.gz: 9104ed36edc2508bf3528273e6351df06a2b8081
5
5
  SHA512:
6
- metadata.gz: 6eb8ef6d1d567d3544b1a311374f3645181733cd6e3d80af84ea0904dc898750ce213e314d0122b245bc80254397745ed8532eff1da03fa61e97f8912ced997f
7
- data.tar.gz: 94e6799a6490352c57c836073ea6f1b01b7c7b3a8e431fdfde48e30c0e6bc211fa021e7fc10bd3692351a4b83469b44fd96187514dd0029115a2a20cc6cea1da
6
+ metadata.gz: 27a9baed1791e3ff02905d3556372bb1fe1e1ffdf399ccbf90ee1d60a4f0da7e000a853bdf64d4cb8d8db024a9a8b37140c34daf78373751df02e051510d396a
7
+ data.tar.gz: 8c7a17904134ec19e0d9eda890386c4fae44a44a5d59b4de3b25f3bce688200163d17e9d16fcc292d5942af34156d4c42bdf7ea9f70dc8cdcf3942bae0636bc4
data/lib/datey.rb CHANGED
@@ -3,8 +3,8 @@ require 'datey/interrogator'
3
3
 
4
4
  module Datey
5
5
 
6
- def self.format(date)
7
- Formatter.new(date)
6
+ def self.format(date, context = :past)
7
+ Formatter.new(date, context)
8
8
  end
9
9
 
10
10
  def self.interrogate(date)
@@ -4,15 +4,16 @@ require 'datey/interrogator'
4
4
  module Datey
5
5
  class Formatter
6
6
 
7
- def initialize(time)
7
+ def initialize(time, context = :past)
8
8
  @time = time
9
+ @context = context
9
10
  end
10
11
 
11
12
  #
12
13
  # Return the date and time
13
14
  #
14
15
  def date_and_time
15
- "#{date} at #{time}"
16
+ @time.is_a?(Time) ? "#{date} at #{time}" : date
16
17
  end
17
18
 
18
19
  #
@@ -36,11 +37,15 @@ module Datey
36
37
  "Yesterday"
37
38
  elsif interrogator.tomorrow?
38
39
  "Tomorrow"
39
- elsif interrogator.last_x_days?(7)
40
- "Last #{name_of_day}"
41
- elsif interrogator.next_x_days?(6)
40
+ elsif @context == :future && interrogator.next_x_days?(6)
41
+ name_of_day
42
+ elsif @context == :future && interrogator.next_week?
43
+ "Next #{name_of_day}"
44
+ elsif @context == :past && interrogator.last_x_days?(6)
42
45
  name_of_day
43
- elsif interrogator.next_week?
46
+ elsif @context == :past && interrogator.last_x_days?(12)
47
+ "Last #{name_of_day}"
48
+ elsif @context == :past && interrogator.next_x_days?(6)
44
49
  "Next #{name_of_day}"
45
50
  else
46
51
  string = "#{name_of_day} #{day_of_month} #{name_of_month}"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datey
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Cooke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-16 00:00:00.000000000 Z
11
+ date: 2014-10-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A Ruby library for formatting & interrogating dates & times
14
14
  email: