lib/nin/parser.rb in nin-1.0.1 vs lib/nin/parser.rb in nin-1.2.0

- old
+ new

@@ -1,28 +1,30 @@ module Nin class Parser def initialize(desc) @desc = desc - @date = extract_date - @tags = extract_tags end def call - [@desc, @date, @tags] + [@desc, extract_date, extract_tags] end private def extract_date - date_pattern = /@[A-Z0-9.,-]+/i + date_pattern = /@[A-Z0-9,-\/]+/i date = @desc.scan(date_pattern).last return nil if date.nil? date.gsub!('@', '') strip_tags(date_pattern) - Chronic.parse(date).strftime('%Y-%m-%d') + begin + Chronic.parse(date).to_date + rescue NoMethodError + raise InvalidDateFormatError + end end def extract_tags tag_pattern = /#[A-Z0-9_]+/i tags = @desc.scan(tag_pattern).map { |tag| tag.gsub!('#', '') }