Skip to content

Commit

Permalink
Enable after_parse hook for date parser
Browse files Browse the repository at this point in the history
  • Loading branch information
markiz committed Jul 27, 2012
1 parent c694822 commit 2fa4518
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/harvester/parser/date.rb
Expand Up @@ -5,7 +5,7 @@ def _parse(node)
node.search(*selectors).map do |checked_node|
if (match = match_any(checked_node.text, regex))
time_string = prepare_time_string(match[regex_capture_group])
DateParser.parse(time_string, locale)
after_parse(checked_node, DateParser.parse(time_string, locale))
end
end.compact.first
end
Expand Down
6 changes: 6 additions & 0 deletions spec/harvester/parser/date_spec.rb
Expand Up @@ -20,6 +20,12 @@
subject.options[:selectors] = "//span"
subject._parse(doc).should be_within(24*3600).of(Time.utc(2012, 3, 5, 22, 30))
end

it "allows for after_parse hook" do
time = Time.now - 3600*30
subject.options[:after_parse] = proc { time }
subject._parse(doc).should == time
end
end

describe "with russian locale" do
Expand Down

0 comments on commit 2fa4518

Please sign in to comment.