Class: Dalt::Parser

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

Overview

Parser is used to parse the date and will return alternate text if failed

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(date_string, alt: nil) ⇒ Parser

Returns a new instance of Parser.



6
7
8
9
10
# File 'lib/dalt/parser.rb', line 6

def initialize(date_string, alt: nil)
  @date = nil
  @date_string = date_string
  @alternate = alt
end

Instance Attribute Details

#alternateObject

Returns the value of attribute alternate.



4
5
6
# File 'lib/dalt/parser.rb', line 4

def alternate
  @alternate
end

#dateObject

Returns the value of attribute date.



4
5
6
# File 'lib/dalt/parser.rb', line 4

def date
  @date
end

Instance Method Details

#parseObject



12
13
14
15
16
17
18
# File 'lib/dalt/parser.rb', line 12

def parse
  @date = Date.parse(@date_string)
rescue StandardError
  raise ::Dalt::Error::WithoutAlternate if alternate.nil?

  alternate
end