Skip to content
This repository has been archived by the owner on Nov 5, 2018. It is now read-only.

Commit

Permalink
- Fixed a bunch of tests
Browse files Browse the repository at this point in the history
 - Add an explicit dependency on nokogiri 1.4.1, which still works, later versions break prism
 - Changed the way datetime.rb interprets some dates. Certain date-like strings (phone numbers)
	could be interpreted as dates, which is not something we want.
  • Loading branch information
Nimlhug committed Apr 13, 2011
1 parent 2cc9244 commit 13dc4fb
Show file tree
Hide file tree
Showing 23 changed files with 184 additions and 148 deletions.
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
source :gemcutter

gem 'nokogiri'
gem 'nokogiri', '= 1.4.1'

group :test do
gem 'rake'
gem 'contest'
gem 'redgreen'
gem 'fakeweb'
gem 'jeweler'
end
end
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ begin
gemspec.homepage = "http://github.com/mwunsch/prism"
gemspec.authors = ["Mark Wunsch"]
gemspec.email = ["[email protected]"]
gemspec.add_dependency 'nokogiri'
gemspec.add_dependency 'nokogiri', '= 1.4.1'
gemspec.add_development_dependency "bundler", ">= 0.9.7"
end
Jeweler::GemcutterTasks.new
Expand All @@ -51,4 +51,4 @@ end
desc "Open an irb session preloaded with this library"
task :console do
sh "irb -rubygems -I lib -r prism"
end
end
4 changes: 2 additions & 2 deletions lib/prism.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require 'nokogiri'

module Prism
VERSION = "0.1.0"
VERSION = "0.1.1"
PRODID = "-//markwunsch.com//Prism #{VERSION}//EN"

# Convenience method for Prism::Microformat.find method
Expand Down Expand Up @@ -132,4 +132,4 @@ def parse_first(document)

require 'prism/pattern'
require 'prism/posh'
require 'prism/microformat'
require 'prism/microformat'
23 changes: 20 additions & 3 deletions lib/prism/pattern/datetime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,33 @@ def self.time(timestring)
hour = datetime[:hour]
min = datetime[:min] || 0
sec = datetime[:sec] || 0
zone = datetime[:zone] || local.utc_offset
zone = datetime[:zone] || local.zone
"T#{hour}:#{min}:#{sec}#{zone}"
end
end

# Build a normalized iso8601 datetime string
def self.iso8601(datetime)
# Extra validation added by Nimlhug: If the date contains 1 space, date and time are required.
# If more than one space is present, it's invalid. Without this extra step certain other numbers
# like phone numbers could be considered dates. Bad.
# Note that these only apply if the dates are all-"numeric" ^(\+|-)?[0-9 :_-]+$

datestamp = date(datetime) || ''
timestamp = time(datetime) || ''
datestamp + timestamp

if datetime =~ /^(\+|-)?[0-9 :_-]+$/ then
spaces = datetime.strip.count(' ')
if spaces > 1 then
return ''
end

if spaces == 1 && (datestamp.nil? || timestamp.nil?) then
return ''
end
end

datestamp + timestamp
end

validate do |datetime|
Expand All @@ -72,4 +89,4 @@ def self.iso8601(datetime)

end
end
end
end
217 changes: 118 additions & 99 deletions prism.gemspec
Original file line number Diff line number Diff line change
@@ -1,132 +1,151 @@
# Generated by jeweler
# DO NOT EDIT THIS FILE DIRECTLY
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
# -*- encoding: utf-8 -*-

Gem::Specification.new do |s|
s.name = %q{prism}
s.version = "0.1.0"
s.version = "0.1.1"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Mark Wunsch"]
s.date = %q{2010-02-24}
s.default_executable = %q{prism}
s.date = %q{2011-04-13}
s.description = %q{A Ruby microformat parser and HTML toolkit powered by Nokogiri}
s.email = ["[email protected]"]
s.executables = ["prism"]
s.extra_rdoc_files = [
"LICENSE",
"README.md"
"README.md"
]
s.files = [
".gitignore",
"Gemfile",
"Gemfile.lock",
"LICENSE",
"README.md",
"Rakefile",
"bin/prism",
"lib/prism.rb",
"lib/prism/microformat.rb",
"lib/prism/microformat/adr.rb",
"lib/prism/microformat/geo.rb",
"lib/prism/microformat/hcard.rb",
"lib/prism/microformat/rellicense.rb",
"lib/prism/microformat/reltag.rb",
"lib/prism/microformat/votelinks.rb",
"lib/prism/microformat/xfn.rb",
"lib/prism/microformat/xmdp.rb",
"lib/prism/microformat/xoxo.rb",
"lib/prism/pattern.rb",
"lib/prism/pattern/abbr.rb",
"lib/prism/pattern/datetime.rb",
"lib/prism/pattern/typevalue.rb",
"lib/prism/pattern/url.rb",
"lib/prism/pattern/valueclass.rb",
"lib/prism/posh.rb",
"lib/prism/posh/anchor.rb",
"lib/prism/posh/base.rb",
"lib/prism/posh/definition_list.rb",
"prism.gemspec",
"test/fixtures/hcard/commercenet.html",
"test/fixtures/hcard/geo.html",
"test/fixtures/huffduffer.html",
"test/fixtures/likeorhate.html",
"test/fixtures/rel_license.html",
"test/fixtures/test-fixture/hcard/hcard1.html",
"test/fixtures/test-fixture/hcard/hcard11.html",
"test/fixtures/test-fixture/hcard/hcard12.html",
"test/fixtures/test-fixture/hcard/hcard17.html",
"test/fixtures/test-fixture/hcard/hcard2.html",
"test/fixtures/test-fixture/hcard/hcard3.html",
"test/fixtures/test-fixture/hcard/hcard4.html",
"test/fixtures/test-fixture/hcard/hcard5.html",
"test/fixtures/test-fixture/hcard/hcard6.html",
"test/fixtures/test-fixture/hcard/hcard7.html",
"test/fixtures/test-fixture/hcard/hcard8.html",
"test/fixtures/test-fixture/hcard/hcard9.html",
"test/fixtures/test-fixture/hcard/hcard99.html",
"test/fixtures/test-fixture/value-class-date-time/value-dt-test-YYYY-MM-DD--HH-MM.html",
"test/fixtures/test-fixture/value-class-date-time/value-dt-test-abbr-YYYY-MM-DD--HH-MM.html",
"test/fixtures/xfn.html",
"test/fixtures/xmdp.html",
"test/fixtures/xoxo.html",
"test/microformat/adr_test.rb",
"test/microformat/geo_test.rb",
"test/microformat/hcard_test.rb",
"test/microformat/rellicense_test.rb",
"test/microformat/reltag_test.rb",
"test/microformat/votelinks_test.rb",
"test/microformat/xfn_test.rb",
"test/microformat/xmdp_test.rb",
"test/microformat/xoxo_test.rb",
"test/microformat_test.rb",
"test/pattern/date_time_test.rb",
"test/pattern/value_class_test.rb",
"test/pattern_test.rb",
"test/posh/anchor_test.rb",
"test/posh/base_test.rb",
"test/posh/definition_list_test.rb",
"test/prism_test.rb",
"test/test_helper.rb"
"Gemfile",
"LICENSE",
"README.md",
"Rakefile",
"bin/prism",
"lib/prism.rb",
"lib/prism/microformat.rb",
"lib/prism/microformat/adr.rb",
"lib/prism/microformat/geo.rb",
"lib/prism/microformat/hcalendar.rb",
"lib/prism/microformat/hcard.rb",
"lib/prism/microformat/rellicense.rb",
"lib/prism/microformat/reltag.rb",
"lib/prism/microformat/votelinks.rb",
"lib/prism/microformat/xfn.rb",
"lib/prism/microformat/xmdp.rb",
"lib/prism/microformat/xoxo.rb",
"lib/prism/pattern.rb",
"lib/prism/pattern/abbr.rb",
"lib/prism/pattern/datetime.rb",
"lib/prism/pattern/typevalue.rb",
"lib/prism/pattern/url.rb",
"lib/prism/pattern/valueclass.rb",
"lib/prism/posh.rb",
"lib/prism/posh/anchor.rb",
"lib/prism/posh/base.rb",
"lib/prism/posh/definition_list.rb",
"prism.gemspec",
"test/fixtures/hcard/commercenet.html",
"test/fixtures/hcard/geo.html",
"test/fixtures/huffduffer.html",
"test/fixtures/likeorhate.html",
"test/fixtures/rel_license.html",
"test/fixtures/test-fixture/hcalendar/hcalendar1.html",
"test/fixtures/test-fixture/hcalendar/hcalendar2.html",
"test/fixtures/test-fixture/hcard/hcard1.html",
"test/fixtures/test-fixture/hcard/hcard11.html",
"test/fixtures/test-fixture/hcard/hcard12.html",
"test/fixtures/test-fixture/hcard/hcard17.html",
"test/fixtures/test-fixture/hcard/hcard2.html",
"test/fixtures/test-fixture/hcard/hcard3.html",
"test/fixtures/test-fixture/hcard/hcard4.html",
"test/fixtures/test-fixture/hcard/hcard5.html",
"test/fixtures/test-fixture/hcard/hcard6.html",
"test/fixtures/test-fixture/hcard/hcard7.html",
"test/fixtures/test-fixture/hcard/hcard8.html",
"test/fixtures/test-fixture/hcard/hcard9.html",
"test/fixtures/test-fixture/hcard/hcard99.html",
"test/fixtures/test-fixture/value-class-date-time/value-dt-test-YYYY-DDD--HH-MM-SS.html",
"test/fixtures/test-fixture/value-class-date-time/value-dt-test-YYYY-MM-DD--0Ham-EEam.html",
"test/fixtures/test-fixture/value-class-date-time/value-dt-test-YYYY-MM-DD--12am-12pm.html",
"test/fixtures/test-fixture/value-class-date-time/value-dt-test-YYYY-MM-DD--H-MM-SSpm-EE-NN-UUpm.html",
"test/fixtures/test-fixture/value-class-date-time/value-dt-test-YYYY-MM-DD--H-MMam-Epm.html",
"test/fixtures/test-fixture/value-class-date-time/value-dt-test-YYYY-MM-DD--HH-MM-SS-XXYY--EE-NN--Z.html",
"test/fixtures/test-fixture/value-class-date-time/value-dt-test-YYYY-MM-DD--HH-MM-XX--EE-NN-UU--Y.html",
"test/fixtures/test-fixture/value-class-date-time/value-dt-test-YYYY-MM-DD--HH-MM-XX-YY--EE-NN-UU--XXYY.html",
"test/fixtures/test-fixture/value-class-date-time/value-dt-test-YYYY-MM-DD--HH-MM.html",
"test/fixtures/test-fixture/value-class-date-time/value-dt-test-YYYY-MM-DD--HH-MMZ-EE-NN-UUZ.html",
"test/fixtures/test-fixture/value-class-date-time/value-dt-test-YYYY-MM-DD--HHpm.html",
"test/fixtures/test-fixture/value-class-date-time/value-dt-test-YYYY-MM-DD--Hpm-EEpm.html",
"test/fixtures/test-fixture/value-class-date-time/value-dt-test-YYYY-MM-DD--abbr-HH-MMpm.html",
"test/fixtures/test-fixture/value-class-date-time/value-dt-test-abbr-YYYY-MM-DD--HH-MM.html",
"test/fixtures/test-fixture/value-class-date-time/value-dt-test-abbr-YYYY-MM-DD-abbr-HH-MM.html",
"test/fixtures/xfn.html",
"test/fixtures/xmdp.html",
"test/fixtures/xoxo.html",
"test/microformat/adr_test.rb",
"test/microformat/geo_test.rb",
"test/microformat/hcalendar_test.rb",
"test/microformat/hcard_test.rb",
"test/microformat/rellicense_test.rb",
"test/microformat/reltag_test.rb",
"test/microformat/votelinks_test.rb",
"test/microformat/xfn_test.rb",
"test/microformat/xmdp_test.rb",
"test/microformat/xoxo_test.rb",
"test/microformat_test.rb",
"test/pattern/date_time_test.rb",
"test/pattern/value_class_test.rb",
"test/pattern_test.rb",
"test/posh/anchor_test.rb",
"test/posh/base_test.rb",
"test/posh/definition_list_test.rb",
"test/prism_test.rb",
"test/test_helper.rb"
]
s.homepage = %q{http://github.com/mwunsch/prism}
s.rdoc_options = ["--charset=UTF-8"]
s.require_paths = ["lib"]
s.rubygems_version = %q{1.3.6}
s.rubygems_version = %q{1.7.2}
s.summary = %q{Ruby microformat parser and HTML toolkit}
s.test_files = [
"test/microformat/adr_test.rb",
"test/microformat/geo_test.rb",
"test/microformat/hcard_test.rb",
"test/microformat/rellicense_test.rb",
"test/microformat/reltag_test.rb",
"test/microformat/votelinks_test.rb",
"test/microformat/xfn_test.rb",
"test/microformat/xmdp_test.rb",
"test/microformat/xoxo_test.rb",
"test/microformat_test.rb",
"test/pattern/date_time_test.rb",
"test/pattern/value_class_test.rb",
"test/pattern_test.rb",
"test/posh/anchor_test.rb",
"test/posh/base_test.rb",
"test/posh/definition_list_test.rb",
"test/prism_test.rb",
"test/test_helper.rb"
"test/microformat/geo_test.rb",
"test/microformat/hcalendar_test.rb",
"test/microformat/hcard_test.rb",
"test/microformat/rellicense_test.rb",
"test/microformat/reltag_test.rb",
"test/microformat/votelinks_test.rb",
"test/microformat/xfn_test.rb",
"test/microformat/xmdp_test.rb",
"test/microformat/xoxo_test.rb",
"test/microformat_test.rb",
"test/pattern/date_time_test.rb",
"test/pattern/value_class_test.rb",
"test/pattern_test.rb",
"test/posh/anchor_test.rb",
"test/posh/base_test.rb",
"test/posh/definition_list_test.rb",
"test/prism_test.rb",
"test/test_helper.rb"
]

if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 3

if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<nokogiri>, ["= 1.4.1"])
s.add_runtime_dependency(%q<nokogiri>, ["= 1.4.1"])
s.add_development_dependency(%q<bundler>, [">= 0.9.7"])
else
s.add_dependency(%q<nokogiri>, [">= 0"])
s.add_dependency(%q<nokogiri>, ["= 1.4.1"])
s.add_dependency(%q<nokogiri>, ["= 1.4.1"])
s.add_dependency(%q<bundler>, [">= 0.9.7"])
end
else
s.add_dependency(%q<nokogiri>, [">= 0"])
s.add_dependency(%q<nokogiri>, ["= 1.4.1"])
s.add_dependency(%q<nokogiri>, ["= 1.4.1"])
s.add_dependency(%q<bundler>, [">= 0.9.7"])
end
end

4 changes: 2 additions & 2 deletions test/microformat/adr_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.join(File.dirname(__FILE__), '..', 'test_helper')
require File.join(File.dirname(File.absolute_path(__FILE__)),'..','test_helper')

class AdrTest < Test::Unit::TestCase
setup do
Expand Down Expand Up @@ -44,4 +44,4 @@ class AdrTest < Test::Unit::TestCase
assert @adr.has_property?(:country_name)
assert_equal 'U.S.A.', @adr.country_name[0]
end
end
end
4 changes: 2 additions & 2 deletions test/microformat/geo_test.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# encoding: utf-8
require File.join(File.dirname(__FILE__), '..', 'test_helper')
require File.join(File.dirname(File.absolute_path(__FILE__)),'..','test_helper')

class GeoTest < Test::Unit::TestCase
setup do
Expand Down Expand Up @@ -64,4 +64,4 @@ class GeoTest < Test::Unit::TestCase
assert_equal '37.77', geo.lat
assert_equal '-122.41', geo.long
end
end
end
4 changes: 2 additions & 2 deletions test/microformat/hcalendar_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.join(File.dirname(__FILE__), '..', 'test_helper')
require File.join(File.dirname(File.absolute_path(__FILE__)),'..','test_helper')

class HCalendarTest < Test::Unit::TestCase
@@klass = Prism::Microformat::HCalendar
Expand Down Expand Up @@ -120,4 +120,4 @@ def self.before_all
end

end
end
end
4 changes: 2 additions & 2 deletions test/microformat/hcard_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.join(File.dirname(__FILE__), '..', 'test_helper')
require File.join(File.dirname(File.absolute_path(__FILE__)),'..','test_helper')

class HCardTest < Test::Unit::TestCase
@@klass = Prism::Microformat::HCard
Expand Down Expand Up @@ -507,4 +507,4 @@ def self.before_all
end
end

end
end
Loading

0 comments on commit 13dc4fb

Please sign in to comment.