human_speakable 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fd8418c6b677810026cb0e363a6c8575d3a331cf25cd66a74c074997114cc0c1
4
- data.tar.gz: 14245cabbdb6b7ac48c71d642c64830fdc09dd5a0b2036fadbda7b303b93ad68
3
+ metadata.gz: 97e4144f2c34bab88cc49e417d2c5164ba7ab08abda4219092ddf137e8f67e7a
4
+ data.tar.gz: cf2975a14c960b0cdce14aef458502cda065803079d280c9c36faef6557e41be
5
5
  SHA512:
6
- metadata.gz: fc4eaf2d791bb45fc4c97e994d72b344a2c22918d09000fe20b08d7795f8e794e51673f73db290424a035f7a00e864fe7cbfc9ce4a72a7dffbf102141f0b967e
7
- data.tar.gz: 0aab2dc80211becfe3d3212b91fba5960c455d12c52489b8db0ffdf220df2ef7134ffab90cdf19fe7e21797e18dca52d01c4d9b9db33239f1507223daa712ec0
6
+ metadata.gz: af088c88e5947cc0dcaf6d3edad00f7d961f58ee6a0effde516c4699de04cb16d8ddb77853c5d29d2a49419ef929ee65ca6f0ea742fc992b58690375e26585a0
7
+ data.tar.gz: 37fb2f9014b31eab73044d5772ce43b8b27bfbb7ff809edd74546e0161ab310076d97cb2dafb5b10a3269328a0ad29d1fad7c5fabb5583c45534288b2ac219ae
checksums.yaml.gz.sig CHANGED
Binary file
@@ -2,8 +2,8 @@
2
2
 
3
3
  # file: human_speakable.rb
4
4
 
5
- module HumanSpeakable
6
-
5
+ module Ordinals
6
+
7
7
  refine Integer do
8
8
 
9
9
  def ordinal
@@ -12,6 +12,34 @@ module HumanSpeakable
12
12
  end
13
13
 
14
14
  end
15
+
16
+ end
17
+
18
+ module HumanSpeakable
19
+ using Ordinals
20
+
21
+ def self.format_date(date)
22
+
23
+ case (date - Date.today).to_i
24
+ when (0) then 'today'
25
+ when (1) then 'tomorrow'
26
+ when (2..6) then 'this ' + Date::DAYNAMES[date.wday]
27
+ when (7..10) then 'next ' + Date::DAYNAMES[date.wday]
28
+ when (11..14)
29
+ ['next', Date::DAYNAMES[date.wday], 'the', (date.day.ordinal), 'of',
30
+ Date::MONTHNAMES[date.month]].join(' ')
31
+ when (15..21)
32
+ [Date::DAYNAMES[date.wday], 'the', (date.day.ordinal), 'of',
33
+ Date::MONTHNAMES[date.month]].join(' ')
34
+ else
35
+ ['on the', (date.day.ordinal), 'of',
36
+ Date::MONTHNAMES[date.month]].join(' ')
37
+ end
38
+ end
39
+
40
+ def self.format_time(time)
41
+ time.strftime("%-I:%M%P")
42
+ end
15
43
 
16
44
  refine String do
17
45
 
@@ -19,8 +47,7 @@ module HumanSpeakable
19
47
 
20
48
  def humanize()
21
49
  date = Date.parse(self)
22
- [Date::DAYNAMES[date.wday], 'the', date.day.ordinal, 'of',
23
- Date::MONTHNAMES[date.month]].join(' ')
50
+ HumanSpeakable.format_date(date)
24
51
  end
25
52
 
26
53
  end
@@ -29,10 +56,18 @@ module HumanSpeakable
29
56
 
30
57
  def humanize()
31
58
  date = self
32
- [Date::DAYNAMES[date.wday], 'the', date.day.ordinal, 'of',
33
- Date::MONTHNAMES[date.month]].join(' ')
59
+ HumanSpeakable.format_date(date)
34
60
  end
35
61
 
36
62
  end
63
+
64
+ refine Time do
65
+
66
+ def humanize()
67
+ time = self
68
+ HumanSpeakable.format_time(time)
69
+ end
70
+
71
+ end
37
72
 
38
73
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: human_speakable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -66,5 +66,5 @@ requirements: []
66
66
  rubygems_version: 3.0.1
67
67
  signing_key:
68
68
  specification_version: 4
69
- summary: human_speakable
69
+ summary: Makes it convenient to format a date as it would be spoken in English.
70
70
  test_files: []
metadata.gz.sig CHANGED
Binary file