fluid-time 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/README.rdoc +49 -51
  2. data/VERSION +1 -1
  3. data/fluid-time.gemspec +2 -2
  4. data/lib/fluid-time.rb +29 -23
  5. metadata +5 -5
@@ -1,64 +1,62 @@
1
- = fluid-time
1
+ == FluidTime
2
2
 
3
3
  Stop formatting time like a C-anderthal. Craft human readable time formats like building a sentence.
4
4
 
5
- ```ruby
6
- FluidTime.new.month.hour.tc.minute.tc.second
7
- FluidTime.new(Date.today).weekday.month.year
8
- ```
5
+ FluidTime.new.month.hour.colon.minute.colon.second
6
+ FluidTime.new(Date.today).weekday.month.year
7
+ FluidTime.new('04/05/2012 09:45:23').weekday.month.year
9
8
 
10
9
  Do things like strip zeros, ordinalize and change case with ease (ordinalize only works if you've included rails for now)
11
- ```ruby
12
- FluidTime.new.time.pm.zone.to_s
13
- # 09:51:29 PM PDT
14
10
 
15
- FluidTime.new.time.xz.xs.pm.down.zone.to_s
16
- # 9:51:51pm PDT
17
- ```
11
+
12
+ FluidTime.new.time.pm.zone.to_s
13
+ # 09:51:29 PM PDT
14
+
15
+ FluidTime.new.time.xz.xs.pm.down.zone.to_s
16
+ # 9:51:51pm PDT
17
+
18
18
 
19
19
  REMEMBER to end your chains with .to_s or use in a string "Today is #{FluidTime.new.weekday.upper}"
20
20
 
21
+ FluidTime.demo
21
22
 
22
- ```ruby
23
- FluidTime.demo
24
- # FluidTime.new. to_time.to_s Tue Apr 10 21:46:11 -0700 2012
25
- # FluidTime.new. to_date.to_s 2012-04-10
26
- # FluidTime.new. A.tday.weekday.to_s Tuesday Tuesday Tuesday
27
- # FluidTime.new. weekday.up.to_s TUESDAY
28
- # FluidTime.new. b.mmm.smonth.to_s Apr Apr Apr
29
- # FluidTime.new. B.month.to_s April April
30
- # FluidTime.new. c.to_s Tue Apr 10 21:46:11 2012
31
- # FluidTime.new. full.to_s Tue Apr 10 21:46:11 2012
32
- # FluidTime.new. d.day.num.dd.to_s 10 10 10 10
33
- # FluidTime.new. e.mday.to_s 10 10
34
- # FluidTime.new. mmm.d.th.year.to_s Apr 10 2012
35
- # FluidTime.new. year.mmm.d.th.to_s 2012 Apr 10
36
- # FluidTime.new. H.h24.hour24.to_s 21 21 21
37
- # FluidTime.new. I.h12.hour.hour12.to_s 09 09 09 09
38
- # FluidTime.new. l.to_s 9
39
- # FluidTime.new. j.yday.day_of_year.to_s 101 101 101
40
- # FluidTime.new. m.mm.mon.month_of_year.to_s 04 04 04 04
41
- # FluidTime.new. M.min.minute.to_s 46 46 46
42
- # FluidTime.new. p.am.pm.to_s PM PM PM
43
- # FluidTime.new. time.xs.p.down.to_s 09:46:11pm
44
- # FluidTime.new. S.sec.second.to_s 11 11 11
45
- # FluidTime.new. U.th.txt('week').to_s 15 week
46
- # FluidTime.new. W.th.tc.ts._('min').to_s 15, min
47
- # FluidTime.new. w.to_s 2
48
- # FluidTime.new. x.autodate.to_s 04/10/12 04/10/12
49
- # FluidTime.new. X.autotime.to_s 21:46:11 21:46:11
50
- # FluidTime.new. date.to_s 04/10/2012
51
- # FluidTime.new. time.to_s 09:46:11
52
- # FluidTime.new. y.yy.sy.to_s 12 12 12
53
- # FluidTime.new. Y.year.to_s 2012 2012
54
- # FluidTime.new. Z.zone.timezone.to_s PDT PDT PDT
55
- # FluidTime.new. txt('01').xz.to_s 1
56
- # FluidTime.new. txt('1:00').xz.xs.pm.lower.zone.to_s 1pm PDT
57
- # FluidTime.new. _('braces').lb.lp.lc.rc.rp.rb.to_s braces[({})]
58
- # FluidTime.new. _('symbols').lb.tp.ts.tc.ts.tn.ts.td.rb.to_s symbols[. , : -]
59
- # FluidTime.new. _('symbols').lb.sp.ss.sc.ss.sn.ss.sd.rb.to_s symbols[. , : -]
60
- # FluidTime.new. db.to_s 2012-04-10 21:09:11
61
- ```
23
+ # FluidTime.new. to_time.to_s Tue Apr 10 21:46:11 -0700 2012
24
+ # FluidTime.new. to_date.to_s 2012-04-10
25
+ # FluidTime.new. A.tday.weekday.to_s Tuesday Tuesday Tuesday
26
+ # FluidTime.new. weekday.up.to_s TUESDAY
27
+ # FluidTime.new. b.mmm.smonth.to_s Apr Apr Apr
28
+ # FluidTime.new. B.month.to_s April April
29
+ # FluidTime.new. c.to_s Tue Apr 10 21:46:11 2012
30
+ # FluidTime.new. full.to_s Tue Apr 10 21:46:11 2012
31
+ # FluidTime.new. d.day.num.dd.to_s 10 10 10 10
32
+ # FluidTime.new. e.mday.to_s 10 10
33
+ # FluidTime.new. mmm.d.th.year.to_s Apr 10 2012
34
+ # FluidTime.new. year.mmm.d.th.to_s 2012 Apr 10
35
+ # FluidTime.new. H.h24.hour24.to_s 21 21 21
36
+ # FluidTime.new. I.h12.hour.hour12.to_s 09 09 09 09
37
+ # FluidTime.new. l.to_s 9
38
+ # FluidTime.new. j.yday.day_of_year.to_s 101 101 101
39
+ # FluidTime.new. m.mm.mon.month_of_year.to_s 04 04 04 04
40
+ # FluidTime.new. M.min.minute.to_s 46 46 46
41
+ # FluidTime.new. p.am.pm.to_s PM PM PM
42
+ # FluidTime.new. time.xs.p.down.to_s 09:46:11pm
43
+ # FluidTime.new. S.sec.second.to_s 11 11 11
44
+ # FluidTime.new. U.th.txt('week').to_s 15 week
45
+ # FluidTime.new. W.th.tc.ts._('min').to_s 15, min
46
+ # FluidTime.new. w.to_s 2
47
+ # FluidTime.new. x.autodate.to_s 04/10/12 04/10/12
48
+ # FluidTime.new. X.autotime.to_s 21:46:11 21:46:11
49
+ # FluidTime.new. date.to_s 04/10/2012
50
+ # FluidTime.new. time.to_s 09:46:11
51
+ # FluidTime.new. y.yy.sy.to_s 12 12 12
52
+ # FluidTime.new. Y.year.to_s 2012 2012
53
+ # FluidTime.new. Z.zone.timezone.to_s PDT PDT PDT
54
+ # FluidTime.new. txt('01').xz.to_s 1
55
+ # FluidTime.new. txt('1:00').xz.xs.pm.lower.zone.to_s 1pm PDT
56
+ # FluidTime.new. _('braces').lb.lp.lc.rc.rp.rb.to_s braces[({})]
57
+ # FluidTime.new. _('symbols').lb.tp.ts.tc.ts.tn.ts.td.rb.to_s symbols[. , : -]
58
+ # FluidTime.new. _('symbols').lb.sp.ss.sc.ss.sn.ss.sd.rb.to_s symbols[. , : -]
59
+ # FluidTime.new. db.to_s 2012-04-10 21:09:11
62
60
 
63
61
  == Contributing to fluid-time
64
62
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.2.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{fluid-time}
8
- s.version = "0.1.4"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Steve Lawson"]
12
- s.date = %q{2012-04-10}
12
+ s.date = %q{2012-04-11}
13
13
  s.description = %q{Stop formatting time like a C-anderthal. Craft human readable time formats like building a sentence.
14
14
 
15
15
 
@@ -79,12 +79,17 @@ class FluidTime
79
79
  end
80
80
 
81
81
  def cat(str, sep = ' ')
82
- @last_was_space = ' ' == str
82
+ @last_was_space = ' ' == str.to_s
83
83
  @build += str.to_s + sep
84
84
  self
85
85
  end
86
86
  alias :txt :cat
87
87
  alias :_ :cat
88
+
89
+ def set(str, sep = ' ')
90
+ @build = str.to_s + sep
91
+ self
92
+ end
88
93
 
89
94
 
90
95
  ##### Formats
@@ -206,41 +211,36 @@ class FluidTime
206
211
  ##### Modifiers
207
212
 
208
213
  def th
209
- @build = @build.strip.split.tap do |parts|
210
- parts << parts.pop.tap { |last| last.replace(ordinalize(last)) }
211
- end.join(' ') + ' '
212
- self
214
+ set(@build.strip.split.tap do |parts|
215
+ parts << parts.pop.tap { |last| last.replace(numeric?(last) ? ordinalize(last) : last) }
216
+ end.join(' '))
213
217
  end
214
218
 
215
219
  def ytt
216
- @build = @build.gsub('-', '/').split.tap do |parts|
220
+ set(@build.gsub('-', '/').split.tap do |parts|
217
221
  parts.each_with_index do |part, index|
218
222
  date = Date.parse(part) rescue nil
219
223
  parts[index] = 'Today' if date.is_a?(Date) && date.to_s == Date.today.to_s
220
224
  parts[index] = 'Tomorrow' if date.is_a?(Date) && date.to_s == Date.tomorrow.to_s
221
225
  parts[index] = 'Yesterday' if date.is_a?(Date) && date.to_s == Date.yesterday.to_s
222
226
  end
223
- end.join(' ') + ' '
224
- self
227
+ end.join(' '))
225
228
  end
226
229
 
227
230
  def down
228
- @build = @build.split.tap { |parts| parts << parts.pop.downcase }.join(' ') + ' '
229
- self
231
+ set(@build.split.tap {|parts| parts << parts.pop.downcase}.join(' '))
230
232
  end
231
233
  alias :lower :down
232
234
 
233
235
  def up
234
- @build = @build.split.tap { |parts| parts << parts.pop.upcase }.join(' ') + ' '
235
- self
236
+ set(@build.split.tap {|parts| parts << parts.pop.upcase}.join(' '))
236
237
  end
237
238
  alias :upper :up
238
239
 
239
240
  def strip_zero
240
- @build = @build.strip.split.tap do |parts|
241
+ set(@build.strip.split.tap do |parts|
241
242
  parts << parts.pop.tap { |last| last.replace(last.gsub(/^0/,'').gsub(':00','')) }
242
- end.join(' ') + ' '
243
- self
243
+ end.join(' '))
244
244
  end
245
245
  alias :xz :strip_zero
246
246
 
@@ -273,11 +273,11 @@ class FluidTime
273
273
  ##### Presets
274
274
 
275
275
  def db
276
- self.Y.td.m.td.d.H.tn.I.tn.S
276
+ self.Y.dash.m.dash.d.H.colon.I.colon.S
277
277
  end
278
278
 
279
279
  def usdate
280
- self.mm.tl.d.tl.Y
280
+ self.mm.slash.d.slash.Y
281
281
  end
282
282
 
283
283
  def Ymd
@@ -285,15 +285,15 @@ class FluidTime
285
285
  end
286
286
 
287
287
  def Y_m_d
288
- self.Y.td.mm.td.d
288
+ self.Y.dash.mm.dash.d
289
289
  end
290
290
 
291
291
  def time
292
- self.hour.tn.minute.tn.second
292
+ self.hour.colon.minute.colon.second
293
293
  end
294
294
 
295
295
  def date
296
- self.mon.sl.day.sl.year
296
+ self.mon.slash.day.slash.year
297
297
  end
298
298
 
299
299
  #####
@@ -305,9 +305,15 @@ class FluidTime
305
305
  true if Float(string) rescue false
306
306
  end
307
307
 
308
- def ordinalize(input)
309
- numeric?(input) && input.to_i.methods.include?(:ordinalize) ? input.to_i.ordinalize : input
310
- end
308
+ def ordinalize(number)
309
+ return "#{number}th" if (11..13).include?(number.to_i % 100)
311
310
 
311
+ case number.to_i % 10
312
+ when 1; "#{number}st"
313
+ when 2; "#{number}nd"
314
+ when 3; "#{number}rd"
315
+ else "#{number}th"
316
+ end
317
+ end
312
318
 
313
319
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluid-time
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 4
10
- version: 0.1.4
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Steve Lawson
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-04-10 00:00:00 -07:00
18
+ date: 2012-04-11 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency