Class: NightTime::Jst

Inherits:
Object
  • Object
show all
Defined in:
lib/night-time/jst.rb

Defined Under Namespace

Classes: Build

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ Jst

Returns a new instance of Jst.



20
21
22
23
# File 'lib/night-time/jst.rb', line 20

def initialize(text)
  @text  = NKF.nkf('-Wwxm0Z0', text).gsub(/\s+/m,' ').strip
  @build = Build.new
end

Class Method Details

.parse(text, now = nil) ⇒ Object



6
7
8
# File 'lib/night-time/jst.rb', line 6

def self.parse(text, now = nil)
  new(text).time(now)
end

Instance Method Details

#parseObject



30
31
32
# File 'lib/night-time/jst.rb', line 30

def parse
  parsedate
end

#parse!Object



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/night-time/jst.rb', line 51

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

#parsedateObject



25
26
27
28
# File 'lib/night-time/jst.rb', line 25

def parsedate
  build!
  @build.to_array
end

#time(now = nil) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/night-time/jst.rb', line 34

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