Class: Datte::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/datte/parser.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{
  locale: 'ja_JP'
}

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Parser

Returns a new instance of Parser.



20
21
22
# File 'lib/datte/parser.rb', line 20

def initialize(options = {})
  @options = self.class.default_options.merge(options)
end

Class Attribute Details

.default_optionsObject



15
16
17
# File 'lib/datte/parser.rb', line 15

def default_options
  @default_options ||= DEFAULT_OPTIONS.dup
end

.localeObject



10
11
12
# File 'lib/datte/parser.rb', line 10

def locale
  @locale || :ja
end

Instance Method Details

#parse_date(body) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/datte/parser.rb', line 24

def parse_date(body)
  body = TextConverter.new().kan_num(body)
  date = DateParser.new(body).parse
  p date
  return yield(date) if block_given? && !date.nil?
  return date
end

#to_dateObject



32
33
34
# File 'lib/datte/parser.rb', line 32

def to_date
  @date
end