rfilemaker 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +74 -0
- data/Rakefile +46 -0
- data/VERSION +1 -0
- data/lib/rfilemaker.rb +13 -0
- data/lib/rfilemaker/field.rb +35 -0
- data/lib/rfilemaker/record.rb +22 -0
- data/lib/rfilemaker/result_set.rb +37 -0
- data/lib/rfilemaker/row.rb +20 -0
- data/rfilemaker.gemspec +68 -0
- data/spec/full_parse_test_spec.rb +58 -0
- data/spec/rfilemaker/field_spec.rb +57 -0
- data/spec/rfilemaker/result_set_spec.rb +57 -0
- data/spec/rfilemaker_spec.rb +27 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +11 -0
- metadata +111 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Bart Zonneveld
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
= rfilemaker
|
2
|
+
|
3
|
+
Heavily inspired by lardawge-rfm, see http://github.com/lardawge/rfm.
|
4
|
+
|
5
|
+
This library parses a Filemaker Pro FMPXMLRESULT type document, nothing more, nothing less
|
6
|
+
|
7
|
+
== Installation
|
8
|
+
|
9
|
+
Easy, just use:
|
10
|
+
|
11
|
+
gem install rfilemaker
|
12
|
+
|
13
|
+
== Usage
|
14
|
+
|
15
|
+
To parse a Filemaker Pro export file named 'export.xml', use:
|
16
|
+
|
17
|
+
RFilemaker.parse('export.xml')
|
18
|
+
|
19
|
+
This returns an array of hashes, each of which represent a row in your Filemaker database.
|
20
|
+
Fields are automatically converted to their ruby types.
|
21
|
+
|
22
|
+
For instance, parsing the following XML export:
|
23
|
+
|
24
|
+
<FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult">
|
25
|
+
<ERRORCODE>0</ERRORCODE>
|
26
|
+
<PRODUCT BUILD="5/23/2002" NAME="FileMaker Pro"
|
27
|
+
VERSION="7.0"/>
|
28
|
+
<DATABASE DATEFORMAT="MM/dd/yy" LAYOUT="summary"
|
29
|
+
NAME="Employees.fp7" RECORDS="23" TIMEFORMAT="hh:mm:ss"/>
|
30
|
+
<METADATA>
|
31
|
+
<FIELD EMPTYOK="NO" MAXREPEAT="1" NAME="First Name" TYPE="TEXT"/>
|
32
|
+
<FIELD EMPTYOK="NO" MAXREPEAT="1" NAME="Last Name" TYPE="TEXT"/>
|
33
|
+
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Department" TYPE="TEXT"/>
|
34
|
+
</METADATA>
|
35
|
+
<RESULTSET FOUND="2">
|
36
|
+
<ROW MODID="47" RECORDID="34">
|
37
|
+
<COL>
|
38
|
+
<DATA>Joe</DATA>
|
39
|
+
</COL>
|
40
|
+
<COL>
|
41
|
+
<DATA>Smith</DATA>
|
42
|
+
</COL>
|
43
|
+
<COL>
|
44
|
+
<DATA>Engineering</DATA>
|
45
|
+
</COL>
|
46
|
+
</ROW>
|
47
|
+
<ROW MODID="89" RECORDID="78">
|
48
|
+
<COL>
|
49
|
+
<DATA>Susan</DATA>
|
50
|
+
</COL>
|
51
|
+
<COL>
|
52
|
+
<DATA>Jones</DATA>
|
53
|
+
</COL>
|
54
|
+
<COL>
|
55
|
+
<DATA>Marketing</DATA>
|
56
|
+
</COL>
|
57
|
+
</ROW>
|
58
|
+
</RESULTSET>
|
59
|
+
</FMPXMLRESULT>
|
60
|
+
|
61
|
+
gives this Ruby hash:
|
62
|
+
|
63
|
+
[{"Last Name"=>"Smith", "Department"=>"Engineering", "First Name"=>"Joe"},
|
64
|
+
{"Last Name"=>"Jones", "Department"=>"Marketing", "First Name"=>"Susan"}]
|
65
|
+
|
66
|
+
== Note on Patches/Pull Requests
|
67
|
+
|
68
|
+
* Fork the project.
|
69
|
+
* Make your feature addition or bug fix.
|
70
|
+
* Add tests for it. This is important so I don't break it in a
|
71
|
+
future version unintentionally.
|
72
|
+
* Commit, do not mess with rakefile, version, or history.
|
73
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
74
|
+
* Send me a pull request. Bonus points for topic branches.
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "rfilemaker"
|
8
|
+
gem.summary = %Q{Ruby library to parse Filemaker Pro FMPXMLRESULT files}
|
9
|
+
gem.description = %Q{Ruby library to parse Filemaker Pro FMPXMLRESULT files}
|
10
|
+
gem.email = "loop@superinfinite.com"
|
11
|
+
gem.homepage = "http://github.com/bartzon/rfilemaker"
|
12
|
+
gem.authors = ["Bart Zonneveld"]
|
13
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
|
+
gem.add_development_dependency "nokogiri", ">= 1.4.2"
|
15
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
+
end
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'spec/rake/spectask'
|
23
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
24
|
+
spec.libs << 'lib' << 'spec'
|
25
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
26
|
+
end
|
27
|
+
|
28
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
29
|
+
spec.libs << 'lib' << 'spec'
|
30
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
31
|
+
spec.rcov = true
|
32
|
+
end
|
33
|
+
|
34
|
+
task :spec => :check_dependencies
|
35
|
+
|
36
|
+
task :default => :spec
|
37
|
+
|
38
|
+
require 'rake/rdoctask'
|
39
|
+
Rake::RDocTask.new do |rdoc|
|
40
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
41
|
+
|
42
|
+
rdoc.rdoc_dir = 'rdoc'
|
43
|
+
rdoc.title = "rfilemaker #{version}"
|
44
|
+
rdoc.rdoc_files.include('README*')
|
45
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
46
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/lib/rfilemaker.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
module RFilemaker
|
4
|
+
def self.parse(string)
|
5
|
+
doc = Nokogiri::XML.parse(string)
|
6
|
+
ResultSet.new(doc)
|
7
|
+
end
|
8
|
+
|
9
|
+
autoload :ResultSet, 'rfilemaker/result_set'
|
10
|
+
autoload :Field, 'rfilemaker/field'
|
11
|
+
autoload :Row, 'rfilemaker/row'
|
12
|
+
autoload :Record, 'rfilemaker/record'
|
13
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module RFilemaker
|
2
|
+
class Field
|
3
|
+
attr_reader :name, :type
|
4
|
+
|
5
|
+
def initialize(xml, result_set)
|
6
|
+
@name = xml['NAME']
|
7
|
+
@type = xml['TYPE'] ? xml['TYPE'].downcase.to_sym : :none
|
8
|
+
@empty_ok = xml['EMPTYOK'] == 'YES'
|
9
|
+
@result_set = result_set
|
10
|
+
end
|
11
|
+
|
12
|
+
def coerce(value)
|
13
|
+
return nil if value.nil? || value == ''
|
14
|
+
|
15
|
+
case type
|
16
|
+
when :date
|
17
|
+
Date.strptime(value, @result_set.date_format) unless @empty_ok
|
18
|
+
when :time
|
19
|
+
DateTime.strptime("1/1/-4712 #{value}", @result_set.time_format) unless @empty_ok
|
20
|
+
when :timestamp
|
21
|
+
DateTime.strptime(value, @result_set.time_format) unless @empty_ok
|
22
|
+
when :number
|
23
|
+
if value.include?('.')
|
24
|
+
value.to_f
|
25
|
+
elsif value.include?(',')
|
26
|
+
value.gsub(/,/, '.').to_f
|
27
|
+
else
|
28
|
+
value.to_i
|
29
|
+
end
|
30
|
+
else
|
31
|
+
value.to_s
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module RFilemaker
|
2
|
+
class Record < Hash
|
3
|
+
attr_reader :record_id, :mod_id
|
4
|
+
|
5
|
+
def initialize(row, fields)
|
6
|
+
@row = row
|
7
|
+
@record_id = @row.record_id
|
8
|
+
@mod_id = @row.mod_id
|
9
|
+
|
10
|
+
fields.each_with_index do |field, index|
|
11
|
+
data = row.columns[index]
|
12
|
+
|
13
|
+
if data.is_a?(Array)
|
14
|
+
self[field.name] = []
|
15
|
+
data.each { |d| self[field.name] << field.coerce(d) }
|
16
|
+
else
|
17
|
+
self[field.name] = field.coerce(data)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module RFilemaker
|
2
|
+
class ResultSet < Array
|
3
|
+
def self.parse_date_format(string)
|
4
|
+
string = string.gsub(/yyyy|yy/, '%y').gsub(/mm|m|MM|M/, '%m').gsub(/dd|d|DD|D/, '%d')
|
5
|
+
string.gsub(/hh|h/, '%I').gsub(/kk|k/, '%H').gsub(/mm/, '%M').gsub(/ss/, '%S').gsub(/a/, '%p')
|
6
|
+
end
|
7
|
+
|
8
|
+
attr_reader :fields, :rows
|
9
|
+
attr_reader :date_format, :time_format
|
10
|
+
|
11
|
+
def initialize(doc)
|
12
|
+
@fields = extract_fields(doc)
|
13
|
+
@rows = extract_rows(doc)
|
14
|
+
|
15
|
+
d = doc.css('DATABASE')
|
16
|
+
@date_format = ResultSet.parse_date_format(d.attribute('DATEFORMAT').to_s)
|
17
|
+
@time_format = ResultSet.parse_date_format(d.attribute('TIMEFORMAT').to_s)
|
18
|
+
|
19
|
+
@rows.each do |row|
|
20
|
+
self << Record.new(row, fields)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
def extract_fields(doc)
|
26
|
+
doc.css('METADATA FIELD').collect do |xml|
|
27
|
+
Field.new(xml, self)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def extract_rows(doc)
|
32
|
+
doc.css('RESULTSET ROW').collect do |xml|
|
33
|
+
Row.new(xml)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module RFilemaker
|
2
|
+
class Row
|
3
|
+
attr_reader :record_id, :mod_id, :columns
|
4
|
+
|
5
|
+
def initialize(xml)
|
6
|
+
@record_id = xml['RECORDID'].to_i
|
7
|
+
@mod_id = xml['MODID'].to_i
|
8
|
+
|
9
|
+
@columns = []
|
10
|
+
xml.css('COL').each do |col|
|
11
|
+
datas = col.css('DATA')
|
12
|
+
if datas.size > 1
|
13
|
+
@columns << datas.collect { |x| x.inner_text }
|
14
|
+
else
|
15
|
+
@columns << datas.inner_text
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/rfilemaker.gemspec
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{rfilemaker}
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Bart Zonneveld"]
|
12
|
+
s.date = %q{2010-06-01}
|
13
|
+
s.description = %q{Ruby library to parse Filemaker Pro FMPXMLRESULT files}
|
14
|
+
s.email = %q{loop@superinfinite.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"lib/rfilemaker.rb",
|
27
|
+
"lib/rfilemaker/field.rb",
|
28
|
+
"lib/rfilemaker/record.rb",
|
29
|
+
"lib/rfilemaker/result_set.rb",
|
30
|
+
"lib/rfilemaker/row.rb",
|
31
|
+
"rfilemaker.gemspec",
|
32
|
+
"spec/full_parse_test_spec.rb",
|
33
|
+
"spec/rfilemaker/field_spec.rb",
|
34
|
+
"spec/rfilemaker/result_set_spec.rb",
|
35
|
+
"spec/rfilemaker_spec.rb",
|
36
|
+
"spec/spec.opts",
|
37
|
+
"spec/spec_helper.rb"
|
38
|
+
]
|
39
|
+
s.homepage = %q{http://github.com/bartzon/rfilemaker}
|
40
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
41
|
+
s.require_paths = ["lib"]
|
42
|
+
s.rubygems_version = %q{1.3.6}
|
43
|
+
s.summary = %q{Ruby library to parse Filemaker Pro FMPXMLRESULT files}
|
44
|
+
s.test_files = [
|
45
|
+
"spec/full_parse_test_spec.rb",
|
46
|
+
"spec/rfilemaker/field_spec.rb",
|
47
|
+
"spec/rfilemaker/result_set_spec.rb",
|
48
|
+
"spec/rfilemaker_spec.rb",
|
49
|
+
"spec/spec_helper.rb"
|
50
|
+
]
|
51
|
+
|
52
|
+
if s.respond_to? :specification_version then
|
53
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
54
|
+
s.specification_version = 3
|
55
|
+
|
56
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
57
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
58
|
+
s.add_development_dependency(%q<nokogiri>, [">= 1.4.2"])
|
59
|
+
else
|
60
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
61
|
+
s.add_dependency(%q<nokogiri>, [">= 1.4.2"])
|
62
|
+
end
|
63
|
+
else
|
64
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
65
|
+
s.add_dependency(%q<nokogiri>, [">= 1.4.2"])
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe RFilemaker do
|
4
|
+
before(:each) do
|
5
|
+
xml = <<-eoxml
|
6
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
7
|
+
<FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult">
|
8
|
+
<ERRORCODE>0</ERRORCODE>
|
9
|
+
<PRODUCT BUILD="5/23/2002" NAME="FileMaker Pro"
|
10
|
+
VERSION="7.0"/>
|
11
|
+
<DATABASE DATEFORMAT="MM/dd/yy" LAYOUT="summary"
|
12
|
+
NAME="Employees.fp7" RECORDS="23" TIMEFORMAT="hh:mm:ss"/>
|
13
|
+
<METADATA>
|
14
|
+
<FIELD EMPTYOK="NO" MAXREPEAT="1" NAME="Name" TYPE="TEXT"/>
|
15
|
+
<FIELD EMPTYOK="NO" MAXREPEAT="1" NAME="Date joined" TYPE="DATE"/>
|
16
|
+
</METADATA>
|
17
|
+
<RESULTSET FOUND="2">
|
18
|
+
<ROW MODID="47" RECORDID="34">
|
19
|
+
<COL>
|
20
|
+
<DATA>Joe Smith</DATA>
|
21
|
+
</COL>
|
22
|
+
<COL>
|
23
|
+
<DATA>03/02/10</DATA>
|
24
|
+
<DATA>05/02/10</DATA>
|
25
|
+
</COL>
|
26
|
+
</ROW>
|
27
|
+
<ROW MODID="89" RECORDID="78">
|
28
|
+
<COL>
|
29
|
+
<DATA>Susan Jones</DATA>
|
30
|
+
</COL>
|
31
|
+
<COL>
|
32
|
+
<DATA>04/05/09</DATA>
|
33
|
+
<DATA>10/05/09</DATA>
|
34
|
+
</COL>
|
35
|
+
</ROW>
|
36
|
+
</RESULTSET>
|
37
|
+
</FMPXMLRESULT>
|
38
|
+
eoxml
|
39
|
+
|
40
|
+
@result = RFilemaker.parse(xml)
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "records" do
|
44
|
+
it "should parse the first record correctly" do
|
45
|
+
r = @result[0]
|
46
|
+
r.should == { 'Name' => 'Joe Smith', 'Date joined' => [Date.new(2010,3,2), Date.new(2010,5,2)] }
|
47
|
+
r.mod_id.should == 47
|
48
|
+
r.record_id.should == 34
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should parse the second record correctly" do
|
52
|
+
r = @result[1]
|
53
|
+
r.should == { 'Name' => 'Susan Jones', 'Date joined' => [Date.new(2009,4,5), Date.new(2009,10,5)] }
|
54
|
+
r.mod_id.should == 89
|
55
|
+
r.record_id.should == 78
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe RFilemaker::Field do
|
4
|
+
describe "coercing values" do
|
5
|
+
before(:each) do
|
6
|
+
x = Nokogiri::XML.parse('<foo/>')
|
7
|
+
rs = mock("Rfilemaker::ResultSet", :date_format => 'date_format', :time_format => 'time_format')
|
8
|
+
@f = RFilemaker::Field.new(x, rs)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should coerce nil correctly" do
|
12
|
+
@f.coerce(nil).should be_nil
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should coerce '' correctly" do
|
16
|
+
@f.coerce('').should be_nil
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should coerce a string correctly" do
|
20
|
+
@f.stub!(:type).and_return :string
|
21
|
+
@f.coerce('foo').should == 'foo'
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should coerce a float with . correctly" do
|
25
|
+
@f.stub!(:type).and_return :number
|
26
|
+
@f.coerce('10.45').should == 10.45
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should coerce a float with , correctly" do
|
30
|
+
@f.stub!(:type).and_return :number
|
31
|
+
@f.coerce('10,45').should == 10.45
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should coerce an int correctly" do
|
35
|
+
@f.stub!(:type).and_return :number
|
36
|
+
@f.coerce('10').should == 10
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should coerce a date correctly" do
|
40
|
+
Date.should_receive(:strptime).with('foo', 'date_format').and_return 'd'
|
41
|
+
@f.stub!(:type).and_return :date
|
42
|
+
@f.coerce('foo').should == 'd'
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should coerce a time correctly" do
|
46
|
+
DateTime.should_receive(:strptime).with('1/1/-4712 foo', 'time_format').and_return 't'
|
47
|
+
@f.stub!(:type).and_return :time
|
48
|
+
@f.coerce('foo').should == 't'
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should coerce a timestamp correctly" do
|
52
|
+
DateTime.should_receive(:strptime).with('foo', 'time_format').and_return 't'
|
53
|
+
@f.stub!(:type).and_return :timestamp
|
54
|
+
@f.coerce('foo').should == 't'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe RFilemaker::ResultSet do
|
4
|
+
describe "parsing" do
|
5
|
+
def parse(str)
|
6
|
+
RFilemaker::ResultSet.parse_date_format(str)
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "date formats" do
|
10
|
+
it "should parse 'mm/dd/yy' correctly" do
|
11
|
+
parse('mm/dd/yy').should == '%m/%d/%y'
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should parse 'mm/dd/yyyy' correctly" do
|
15
|
+
parse('mm/dd/yyyy').should == '%m/%d/%y'
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should parse 'MM/dd/yy' correctly" do
|
19
|
+
parse('MM/dd/yy').should == '%m/%d/%y'
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should parse 'M/dd/yy' correctly" do
|
23
|
+
parse('M/dd/yy').should == '%m/%d/%y'
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should parse 'mm/dd/yy' correctly" do
|
27
|
+
parse('mm/d/yy').should == '%m/%d/%y'
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should parse 'D-m-yyyy' correctly" do
|
31
|
+
parse('D-m-yyyy').should == '%d-%m-%y'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "time formats" do
|
36
|
+
it "should parse 'hh:mm:ss' correctly" do
|
37
|
+
parse('hh:mm:ss').should == '%I:%m:%S'
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should parse 'h:mm:ss' correctly" do
|
41
|
+
parse('h:mm:ss').should == '%I:%m:%S'
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should parse 'hh:mm:ss a' correctly" do
|
45
|
+
parse('hh:mm:ss a').should == '%I:%m:%S %p'
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should parse 'kk:mm:ss' correctly" do
|
49
|
+
parse('kk:mm:ss').should == '%H:%m:%S'
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should parse 'k:mm:ss' correctly" do
|
53
|
+
parse('k:mm:ss').should == '%H:%m:%S'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe RFilemaker do
|
4
|
+
before(:each) do
|
5
|
+
@xml = "<foo></foo>"
|
6
|
+
RFilemaker::ResultSet.stub!(:new).and_return 'result set'
|
7
|
+
Nokogiri::XML.stub!(:parse).and_return 'xml'
|
8
|
+
end
|
9
|
+
|
10
|
+
def parse
|
11
|
+
RFilemaker.parse(@xml)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should parse a string using nokogiri" do
|
15
|
+
Nokogiri::XML.should_receive(:parse).with(@xml)
|
16
|
+
parse
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should initialize a resultset with the parsed xml" do
|
20
|
+
RFilemaker::ResultSet.should_receive(:new).with('xml')
|
21
|
+
parse
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should return the resultset" do
|
25
|
+
parse.should == 'result set'
|
26
|
+
end
|
27
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
require 'rfilemaker'
|
4
|
+
require 'spec'
|
5
|
+
require 'spec/autorun'
|
6
|
+
|
7
|
+
Dir.glob(File.join(File.dirname(__FILE__), '*_spec.rb')).each { |f| require f }
|
8
|
+
|
9
|
+
Spec::Runner.configure do |config|
|
10
|
+
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rfilemaker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Bart Zonneveld
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-06-01 00:00:00 +02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rspec
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 2
|
30
|
+
- 9
|
31
|
+
version: 1.2.9
|
32
|
+
type: :development
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: nokogiri
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 1
|
43
|
+
- 4
|
44
|
+
- 2
|
45
|
+
version: 1.4.2
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id002
|
48
|
+
description: Ruby library to parse Filemaker Pro FMPXMLRESULT files
|
49
|
+
email: loop@superinfinite.com
|
50
|
+
executables: []
|
51
|
+
|
52
|
+
extensions: []
|
53
|
+
|
54
|
+
extra_rdoc_files:
|
55
|
+
- LICENSE
|
56
|
+
- README.rdoc
|
57
|
+
files:
|
58
|
+
- .document
|
59
|
+
- .gitignore
|
60
|
+
- LICENSE
|
61
|
+
- README.rdoc
|
62
|
+
- Rakefile
|
63
|
+
- VERSION
|
64
|
+
- lib/rfilemaker.rb
|
65
|
+
- lib/rfilemaker/field.rb
|
66
|
+
- lib/rfilemaker/record.rb
|
67
|
+
- lib/rfilemaker/result_set.rb
|
68
|
+
- lib/rfilemaker/row.rb
|
69
|
+
- rfilemaker.gemspec
|
70
|
+
- spec/full_parse_test_spec.rb
|
71
|
+
- spec/rfilemaker/field_spec.rb
|
72
|
+
- spec/rfilemaker/result_set_spec.rb
|
73
|
+
- spec/rfilemaker_spec.rb
|
74
|
+
- spec/spec.opts
|
75
|
+
- spec/spec_helper.rb
|
76
|
+
has_rdoc: true
|
77
|
+
homepage: http://github.com/bartzon/rfilemaker
|
78
|
+
licenses: []
|
79
|
+
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options:
|
82
|
+
- --charset=UTF-8
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
segments:
|
90
|
+
- 0
|
91
|
+
version: "0"
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
segments:
|
97
|
+
- 0
|
98
|
+
version: "0"
|
99
|
+
requirements: []
|
100
|
+
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 1.3.6
|
103
|
+
signing_key:
|
104
|
+
specification_version: 3
|
105
|
+
summary: Ruby library to parse Filemaker Pro FMPXMLRESULT files
|
106
|
+
test_files:
|
107
|
+
- spec/full_parse_test_spec.rb
|
108
|
+
- spec/rfilemaker/field_spec.rb
|
109
|
+
- spec/rfilemaker/result_set_spec.rb
|
110
|
+
- spec/rfilemaker_spec.rb
|
111
|
+
- spec/spec_helper.rb
|