Class: NightTime::Jst
- Inherits:
-
Object
show all
- Defined in:
- lib/night-time/jst.rb
Defined Under Namespace
Classes: Build, Changed, Completed
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(text) ⇒ Jst
36
37
38
39
40
|
# File 'lib/night-time/jst.rb', line 36
def initialize(text)
@text = NKF.nkf('-Wwxm0Z0', text).gsub(/\s+/m,' ').strip
@build = Build.new
@trace = []
end
|
Class Method Details
.parse(text, now = nil) ⇒ Object
9
10
11
|
# File 'lib/night-time/jst.rb', line 9
def self.parse(text, now = nil)
new(text).time(now)
end
|
.parsedate(text) ⇒ Object
13
14
15
|
# File 'lib/night-time/jst.rb', line 13
def self.parsedate(text)
new(text).parse
end
|
Instance Method Details
#parse ⇒ Object
47
48
49
50
|
# File 'lib/night-time/jst.rb', line 47
def parse
build!
@build.to_a
end
|
#parse! ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/night-time/jst.rb', line 69
def parse!
build!
if @build.full?
return @build.to_time
elsif @build.date?
build = @build.dup
build.year ||= Time.now.year
return build.to_time
else
return nil
end
end
|
#time(now = nil) ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/night-time/jst.rb', line 52
def time(now = nil)
unless now
now = Time.now
now = Time.mktime(now.year, now.month, now.day)
end
build!
b = @build.dup
b.year ||= now.year
b.month ||= now.month
b.day ||= now.day
b.hour ||= now.hour
b.min ||= now.min
b.sec ||= now.sec
return b.to_time
end
|
#trace ⇒ Object
42
43
44
45
|
# File 'lib/night-time/jst.rb', line 42
def trace
build!
return @trace
end
|