wrxer 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.travis.yml +9 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +120 -0
- data/Rakefile +7 -0
- data/lib/wrxer.rb +36 -0
- data/lib/wrxer/attribute.rb +7 -0
- data/lib/wrxer/author.rb +10 -0
- data/lib/wrxer/category.rb +8 -0
- data/lib/wrxer/coercion.rb +60 -0
- data/lib/wrxer/comment.rb +16 -0
- data/lib/wrxer/comment_collection.rb +7 -0
- data/lib/wrxer/document.rb +17 -0
- data/lib/wrxer/image.rb +8 -0
- data/lib/wrxer/parser.rb +20 -0
- data/lib/wrxer/post.rb +24 -0
- data/lib/wrxer/post_collection.rb +6 -0
- data/lib/wrxer/postmeta.rb +7 -0
- data/lib/wrxer/postmeta_collection.rb +6 -0
- data/lib/wrxer/uri_parser.rb +20 -0
- data/lib/wrxer/version.rb +3 -0
- data/lib/wrxer/wrxer_collection.rb +48 -0
- data/lib/wrxer/wrxer_object.rb +52 -0
- data/spec/fixtures/missing_fields.xml +155 -0
- data/spec/fixtures/wrx.xml +159 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/wrxer/author_spec.rb +13 -0
- data/spec/wrxer/category_spec.rb +35 -0
- data/spec/wrxer/document_spec.rb +29 -0
- data/spec/wrxer/image_spec.rb +13 -0
- data/spec/wrxer/parser_spec.rb +14 -0
- data/spec/wrxer/post_collection_spec.rb +25 -0
- data/spec/wrxer/post_spec.rb +82 -0
- data/spec/wrxer/postmeta_collection_spec.rb +17 -0
- data/spec/wrxer/postmeta_spec.rb +18 -0
- data/spec/wrxer/uri_parser_spec.rb +14 -0
- data/spec/wrxer_spec.rb +14 -0
- data/wrxer.gemspec +26 -0
- metadata +168 -0
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Wrxer::Author do
|
4
|
+
describe "valid document" do
|
5
|
+
let(:filename) { fixture('wrx.xml') }
|
6
|
+
let(:document) { Nokogiri::XML(filename.read).at_xpath('//channel') }
|
7
|
+
subject { described_class.call(document) }
|
8
|
+
|
9
|
+
it 'has a login' do
|
10
|
+
expect(subject.login).to eq "wrxernews"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Wrxer::Category do
|
4
|
+
describe "valid document" do
|
5
|
+
let(:filename) { fixture('wrx.xml') }
|
6
|
+
let(:document) { Nokogiri::XML(filename.read).xpath('//channel').at_xpath('item').at_xpath('category') }
|
7
|
+
subject { described_class.call(document) }
|
8
|
+
|
9
|
+
it 'has a domain' do
|
10
|
+
expect(subject.domain).to eq "category"
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'has a nicename' do
|
14
|
+
expect(subject.nicename).to eq "wrxer-news"
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'has a body' do
|
18
|
+
expect(subject.body).to eq "Wrxer News"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "invalid document" do
|
23
|
+
let(:filename) { fixture('missing_fields.xml') }
|
24
|
+
let(:document) { Nokogiri::XML(filename.read).xpath('//channel').at_xpath('item').at_xpath('category')}
|
25
|
+
subject { described_class.new(document) }
|
26
|
+
|
27
|
+
it 'returns nil for element attribute' do
|
28
|
+
expect(subject.domain).to eq nil
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'returns nil for child attribute' do
|
32
|
+
expect(subject.body).to eq nil
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Wrxer::Document do
|
4
|
+
describe "valid document" do
|
5
|
+
let(:filename) { fixture('wrx.xml') }
|
6
|
+
let(:document) { Nokogiri::XML(filename.read) }
|
7
|
+
subject { described_class.call(document) }
|
8
|
+
|
9
|
+
it 'has a title' do
|
10
|
+
expect(subject.title).to eq "Wrxer News"
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'has a link' do
|
14
|
+
expect(subject.link).to eq "https://wrxernews.wordpress.com"
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'has an author' do
|
18
|
+
expect(subject.author).to be_a Wrxer::Author
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'has an image' do
|
22
|
+
expect(subject.image).to be_a Wrxer::Image
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'has posts' do
|
26
|
+
expect(subject.posts.first).to be_a Wrxer::Post
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Wrxer::Image do
|
4
|
+
describe "valid document" do
|
5
|
+
let(:filename) { fixture('wrx.xml') }
|
6
|
+
let(:document) { Nokogiri::XML(filename.read).at_xpath('//channel') }
|
7
|
+
subject { described_class.call(document) }
|
8
|
+
|
9
|
+
it 'has a url' do
|
10
|
+
expect(subject.url).to eq "https://secure.gravatar.com/blavatar/foobar"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Wrxer::Parser do
|
4
|
+
let(:filename) { fixture('wrx.xml') }
|
5
|
+
subject { described_class.new(filename) }
|
6
|
+
|
7
|
+
it 'loads xml document' do
|
8
|
+
expect(subject).to be_an Wrxer::Parser
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'returns a wrxer document' do
|
12
|
+
expect(subject.call).to be_an Wrxer::Document
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Wrxer::PostCollection do
|
4
|
+
let(:filename) { fixture('wrx.xml') }
|
5
|
+
let(:document) { Nokogiri::XML(filename.read) }
|
6
|
+
subject { described_class.call(document) }
|
7
|
+
|
8
|
+
describe 'collection' do
|
9
|
+
it 'has an enumerator' do
|
10
|
+
expect(subject.data).to be_an Enumerator
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'returns a post' do
|
14
|
+
expect(subject.first).to be_a Wrxer::Post
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'returns first post' do
|
18
|
+
expect(subject.first.title).to eq "Welcome To Wrxer News."
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'returns second post' do
|
22
|
+
expect(subject.entries[1].title).to eq "Wrxer on the Radio"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Wrxer::Post do
|
4
|
+
context 'valid document' do
|
5
|
+
let(:filename) { fixture('wrx.xml') }
|
6
|
+
let(:document) { Nokogiri::XML(filename.read).xpath('//channel').at_xpath('item')}
|
7
|
+
subject { described_class.call(document) }
|
8
|
+
|
9
|
+
it 'has an id' do
|
10
|
+
expect(subject.id).to eq 3
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'has a title' do
|
14
|
+
expect(subject.title).to eq "Welcome To Wrxer News."
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'has a content' do
|
18
|
+
expect(subject.content).to match /Welcome to/
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'has an excerpt' do
|
22
|
+
expect(subject.excerpt).to eq "Excerpt Text"
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'has a slug' do
|
26
|
+
expect(subject.name).to eq "welcome-to-wrxer-news"
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'has a post date' do
|
30
|
+
expect(subject.published_at).to eq Time.parse("2007-11-17 21:30:51")
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'has a category' do
|
34
|
+
expect(subject.category).to be_a Wrxer::Category
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'has is_sticky' do
|
38
|
+
expect(subject.is_sticky).to eq 0
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'has postmetas' do
|
42
|
+
expect(subject.postmetas.first).to be_a Wrxer::Postmeta
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'has comments' do
|
46
|
+
expect(subject.comments.first).to be_a Wrxer::Comment
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'does not have a not foo' do
|
50
|
+
expect { subject.foo }.to raise_error(
|
51
|
+
NoMethodError, "undefined method 'foo' for Wrxer::Post")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "nil attribute case" do
|
56
|
+
let(:filename) { fixture('missing_fields.xml') }
|
57
|
+
let(:document) { Nokogiri::XML(filename.read).xpath('//channel').at_xpath('item')}
|
58
|
+
subject { described_class.call(document) }
|
59
|
+
|
60
|
+
it 'returns nil for nil integer' do
|
61
|
+
expect(subject.id).to eq nil
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'returns nil for text' do
|
65
|
+
expect(subject.name).to eq nil
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'returns nil for time' do
|
69
|
+
expect(subject.published_at).to eq nil
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context "for missing node" do
|
74
|
+
let(:filename) { fixture('missing_fields.xml') }
|
75
|
+
let(:document) { Nokogiri::XML(filename.read).xpath('//channel').xpath('item')[1]}
|
76
|
+
subject { described_class.new(document) }
|
77
|
+
|
78
|
+
it 'returns nil for category' do
|
79
|
+
expect(subject.category).to eq nil
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Wrxer::PostmetaCollection do
|
4
|
+
describe "valid document" do
|
5
|
+
let(:filename) { fixture('wrx.xml') }
|
6
|
+
let(:document) { Nokogiri::XML(filename.read).xpath('//channel').at_xpath('item') }
|
7
|
+
subject { described_class.call(document) }
|
8
|
+
|
9
|
+
it 'has an enumerator' do
|
10
|
+
expect(subject.data).to be_an Enumerator
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'returns a postmeta' do
|
14
|
+
expect(subject.first).to be_a Wrxer::Postmeta
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Wrxer::Postmeta do
|
4
|
+
describe "valid document" do
|
5
|
+
let(:filename) { fixture('wrx.xml') }
|
6
|
+
let(:document) { Nokogiri::XML(filename.read).xpath('//channel').at_xpath('item').at_xpath('wp:postmeta')}
|
7
|
+
subject { described_class.call(document) }
|
8
|
+
|
9
|
+
it 'has a key' do
|
10
|
+
expect(subject.key).to eq "_wpas_skip_4017882"
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'has a value' do
|
14
|
+
expect(subject.value).to eq 1
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Wrxer::URIParser do
|
4
|
+
let(:uri) { "https://raw.githubusercontent.com/bullfight/wrxer/master/spec/fixtures/wrx.xml" }
|
5
|
+
subject { described_class.new(uri) }
|
6
|
+
|
7
|
+
it 'loads xml document' do
|
8
|
+
expect(subject).to be_an Wrxer::URIParser
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'returns a wrxer document' do
|
12
|
+
expect(subject.call).to be_an Wrxer::Document
|
13
|
+
end
|
14
|
+
end
|
data/spec/wrxer_spec.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Wrxer do
|
4
|
+
let(:filename) { fixture('wrx.xml') }
|
5
|
+
subject { described_class }
|
6
|
+
|
7
|
+
it 'has a version number' do
|
8
|
+
expect(Wrxer::VERSION).not_to be nil
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'parses a file' do
|
12
|
+
expect(subject.parse(filename)).to be_an Wrxer::Document
|
13
|
+
end
|
14
|
+
end
|
data/wrxer.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'wrxer/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "wrxer"
|
8
|
+
spec.version = Wrxer::VERSION
|
9
|
+
spec.authors = ["Patrick Schmitz"]
|
10
|
+
spec.email = ["p.schmitz@gmail.com"]
|
11
|
+
spec.summary = %q{Parse a wordpress WRX export document}
|
12
|
+
spec.homepage = "https://github.com/bullfight/wrxer"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency "nokogiri"
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec"
|
25
|
+
spec.add_development_dependency "pry"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,168 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wrxer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Patrick Schmitz
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.7'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- p.schmitz@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- .gitignore
|
91
|
+
- .rspec
|
92
|
+
- .travis.yml
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- lib/wrxer.rb
|
98
|
+
- lib/wrxer/attribute.rb
|
99
|
+
- lib/wrxer/author.rb
|
100
|
+
- lib/wrxer/category.rb
|
101
|
+
- lib/wrxer/coercion.rb
|
102
|
+
- lib/wrxer/comment.rb
|
103
|
+
- lib/wrxer/comment_collection.rb
|
104
|
+
- lib/wrxer/document.rb
|
105
|
+
- lib/wrxer/image.rb
|
106
|
+
- lib/wrxer/parser.rb
|
107
|
+
- lib/wrxer/post.rb
|
108
|
+
- lib/wrxer/post_collection.rb
|
109
|
+
- lib/wrxer/postmeta.rb
|
110
|
+
- lib/wrxer/postmeta_collection.rb
|
111
|
+
- lib/wrxer/uri_parser.rb
|
112
|
+
- lib/wrxer/version.rb
|
113
|
+
- lib/wrxer/wrxer_collection.rb
|
114
|
+
- lib/wrxer/wrxer_object.rb
|
115
|
+
- spec/fixtures/missing_fields.xml
|
116
|
+
- spec/fixtures/wrx.xml
|
117
|
+
- spec/spec_helper.rb
|
118
|
+
- spec/wrxer/author_spec.rb
|
119
|
+
- spec/wrxer/category_spec.rb
|
120
|
+
- spec/wrxer/document_spec.rb
|
121
|
+
- spec/wrxer/image_spec.rb
|
122
|
+
- spec/wrxer/parser_spec.rb
|
123
|
+
- spec/wrxer/post_collection_spec.rb
|
124
|
+
- spec/wrxer/post_spec.rb
|
125
|
+
- spec/wrxer/postmeta_collection_spec.rb
|
126
|
+
- spec/wrxer/postmeta_spec.rb
|
127
|
+
- spec/wrxer/uri_parser_spec.rb
|
128
|
+
- spec/wrxer_spec.rb
|
129
|
+
- wrxer.gemspec
|
130
|
+
homepage: https://github.com/bullfight/wrxer
|
131
|
+
licenses:
|
132
|
+
- MIT
|
133
|
+
metadata: {}
|
134
|
+
post_install_message:
|
135
|
+
rdoc_options: []
|
136
|
+
require_paths:
|
137
|
+
- lib
|
138
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ! '>='
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ! '>='
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
requirements: []
|
149
|
+
rubyforge_project:
|
150
|
+
rubygems_version: 2.4.5
|
151
|
+
signing_key:
|
152
|
+
specification_version: 4
|
153
|
+
summary: Parse a wordpress WRX export document
|
154
|
+
test_files:
|
155
|
+
- spec/fixtures/missing_fields.xml
|
156
|
+
- spec/fixtures/wrx.xml
|
157
|
+
- spec/spec_helper.rb
|
158
|
+
- spec/wrxer/author_spec.rb
|
159
|
+
- spec/wrxer/category_spec.rb
|
160
|
+
- spec/wrxer/document_spec.rb
|
161
|
+
- spec/wrxer/image_spec.rb
|
162
|
+
- spec/wrxer/parser_spec.rb
|
163
|
+
- spec/wrxer/post_collection_spec.rb
|
164
|
+
- spec/wrxer/post_spec.rb
|
165
|
+
- spec/wrxer/postmeta_collection_spec.rb
|
166
|
+
- spec/wrxer/postmeta_spec.rb
|
167
|
+
- spec/wrxer/uri_parser_spec.rb
|
168
|
+
- spec/wrxer_spec.rb
|