mida 0.3.9 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +8 -3
- data/lib/mida/datatype/enumeration.rb +2 -4
- data/lib/mida/datatype/generic.rb +1 -3
- data/lib/mida/datatype/iso8601date.rb +1 -1
- data/lib/mida/document.rb +1 -1
- data/lib/mida/version.rb +1 -1
- data/mida.gemspec +2 -3
- data/spec/datatype/boolean_spec.rb +8 -8
- data/spec/datatype/enumeration_spec.rb +3 -3
- data/spec/datatype/float_spec.rb +3 -3
- data/spec/datatype/generic_spec.rb +9 -9
- data/spec/datatype/integer_spec.rb +4 -4
- data/spec/datatype/iso8601date_spec.rb +3 -3
- data/spec/datatype/number_spec.rb +3 -3
- data/spec/datatype/text_spec.rb +2 -2
- data/spec/datatype/url_spec.rb +4 -4
- data/spec/document_spec.rb +30 -23
- data/spec/item_spec.rb +80 -80
- data/spec/itemprop_spec.rb +13 -12
- data/spec/itemscope_spec.rb +21 -21
- data/spec/propertydesc_spec.rb +6 -6
- data/spec/vocabulary_spec.rb +35 -35
- metadata +7 -22
- data/Gemfile.lock +0 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce860318419bb6c7035970ea76944a6b163760c1
|
4
|
+
data.tar.gz: e7dd59518fe23b26b56e6da0bf5c7fb75f6b242b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb8a525521ad35f8fc5bcde98361d163d891b95535403b150bb251c5635f297d554f10192b8e2de38d8e5ee2cc2ff0c68bb48bcc3b47a5b61668c306574855a7
|
7
|
+
data.tar.gz: 7077836f38c96eeedc201ad945d8e2eff1a6495f1547fe301f19061122f6f958633d55cf2494def351c87ef7d0bf7222f1cfab3a906da1472b5714c194d2e70b
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -11,15 +11,13 @@ module Mida
|
|
11
11
|
# [[DataType, Regexp], [DataType, Regexp]]
|
12
12
|
class Enumeration < Generic
|
13
13
|
|
14
|
-
Enumeration.reveal(:class)
|
15
|
-
|
16
14
|
# Raises +ArgumentError+ if value not valid value
|
17
15
|
def initialize(value)
|
18
|
-
value_is_valid = self.
|
16
|
+
value_is_valid = (class << self; self end).superclass::VALID_VALUES.any? do |valid_value|
|
19
17
|
@parsedValue = valid_value[0].parse(value)
|
20
18
|
@parsedValue.to_s =~ valid_value[1]
|
21
19
|
end
|
22
|
-
raise ArgumentError unless value_is_valid
|
20
|
+
raise ::ArgumentError unless value_is_valid
|
23
21
|
end
|
24
22
|
|
25
23
|
end
|
data/lib/mida/document.rb
CHANGED
@@ -16,7 +16,7 @@ module Mida
|
|
16
16
|
# [page_url] The url of target used for form absolute urls. This must
|
17
17
|
# include the filename, e.g. index.html.
|
18
18
|
def initialize(target, page_url=nil)
|
19
|
-
@doc = Nokogiri(target)
|
19
|
+
@doc = target.kind_of?(Nokogiri::XML::Document) ? target : Nokogiri(target)
|
20
20
|
@page_url = page_url
|
21
21
|
@items = extract_items
|
22
22
|
end
|
data/lib/mida/version.rb
CHANGED
data/mida.gemspec
CHANGED
@@ -18,10 +18,9 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
spec.extra_rdoc_files = ['README.rdoc', 'LICENCE.rdoc', 'CHANGELOG.rdoc']
|
20
20
|
spec.rdoc_options << '--main' << 'README.rdoc'
|
21
|
-
spec.add_dependency('blankslate', '3.1.3')
|
22
21
|
spec.add_dependency('nokogiri', '>= 1.6')
|
23
|
-
spec.add_dependency('addressable', '~> 2.
|
22
|
+
spec.add_dependency('addressable', '~> 2.4')
|
24
23
|
spec.add_development_dependency "bundler", "~> 1.6"
|
25
24
|
spec.add_development_dependency "rake"
|
26
|
-
spec.add_development_dependency "rspec", "~>
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.1"
|
27
26
|
end
|
@@ -4,37 +4,37 @@ describe Mida::DataType::Boolean do
|
|
4
4
|
|
5
5
|
it '#parse should raise an exception if a invalid text passed' do
|
6
6
|
test = lambda {Mida::DataType::Boolean.parse('example')}
|
7
|
-
test.
|
7
|
+
expect(test).to raise_error(ArgumentError)
|
8
8
|
end
|
9
9
|
|
10
10
|
it '#parse should raise an exception if value is empty' do
|
11
11
|
test = lambda {Mida::DataType::Boolean.parse('')}
|
12
|
-
test.
|
12
|
+
expect(test).to raise_error(ArgumentError)
|
13
13
|
end
|
14
14
|
|
15
15
|
it '#parse should return true for "True" whatever the case' do
|
16
16
|
['true', 'True', 'TRUE', 'tRUE'].each do |true_text|
|
17
|
-
Mida::DataType::Boolean.parse(true_text).
|
17
|
+
expect(Mida::DataType::Boolean.parse(true_text)).to be_truthy
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
21
|
it '#parse should return false for "False" whatever the case' do
|
22
22
|
['false', 'False', 'FALSE', 'fALSE'].each do |false_text|
|
23
|
-
Mida::DataType::Boolean.parse(false_text).
|
23
|
+
expect(Mida::DataType::Boolean.parse(false_text)).to be_falsey
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
27
|
it '#to_s should return proper string representation of boolean' do
|
28
|
-
Mida::DataType::Boolean.parse('fALSE').to_s.
|
29
|
-
Mida::DataType::Boolean.parse('tRUE').to_s.
|
28
|
+
expect(Mida::DataType::Boolean.parse('fALSE').to_s).to eq('False')
|
29
|
+
expect(Mida::DataType::Boolean.parse('tRUE').to_s).to eq('True')
|
30
30
|
end
|
31
31
|
|
32
32
|
it '! should negate as if a TrueClass/FalseClass' do
|
33
33
|
true_boolean = Mida::DataType::Boolean.parse('true')
|
34
34
|
false_boolean = Mida::DataType::Boolean.parse('false')
|
35
35
|
|
36
|
-
(!true_boolean).
|
37
|
-
(!false_boolean).
|
36
|
+
expect(!true_boolean).to be_falsey
|
37
|
+
expect(!false_boolean).to be_truthy
|
38
38
|
end
|
39
39
|
|
40
40
|
end
|
@@ -13,18 +13,18 @@ describe Mida::DataType::Enumeration do
|
|
13
13
|
|
14
14
|
it '#parse should raise an exception if an invalid url passed' do
|
15
15
|
test = lambda {BookType.parse('http://example.com/hardback')}
|
16
|
-
test.
|
16
|
+
expect(test).to raise_error(ArgumentError)
|
17
17
|
end
|
18
18
|
|
19
19
|
it '#parse should raise an exception if value is empty' do
|
20
20
|
test = lambda {BookType.parse('')}
|
21
|
-
test.
|
21
|
+
expect(test).to raise_error(ArgumentError)
|
22
22
|
end
|
23
23
|
|
24
24
|
it '#parse should accept a valid value' do
|
25
25
|
url_text = 'http://example.com/ebook'
|
26
26
|
url = BookType.parse(url_text)
|
27
|
-
url.to_s.
|
27
|
+
expect(url.to_s).to eq(url_text)
|
28
28
|
end
|
29
29
|
|
30
30
|
end
|
data/spec/datatype/float_spec.rb
CHANGED
@@ -4,18 +4,18 @@ describe Mida::DataType::Float do
|
|
4
4
|
|
5
5
|
it '#parse should raise an exception if not a number' do
|
6
6
|
test = lambda {Mida::DataType::Float.parse('hello')}
|
7
|
-
test.
|
7
|
+
expect(test).to raise_error(ArgumentError)
|
8
8
|
end
|
9
9
|
|
10
10
|
it '#parse should raise an exception if value is empty' do
|
11
11
|
test = lambda {Mida::DataType::Float.parse('')}
|
12
|
-
test.
|
12
|
+
expect(test).to raise_error(ArgumentError)
|
13
13
|
end
|
14
14
|
|
15
15
|
it '#parse should accept a valid number' do
|
16
16
|
float_text = '3.14'
|
17
17
|
float = Mida::DataType::Float.parse(float_text)
|
18
|
-
float.to_s.
|
18
|
+
expect(float.to_s).to eq(float_text)
|
19
19
|
end
|
20
20
|
|
21
21
|
end
|
@@ -17,28 +17,28 @@ describe Mida::DataType::Generic do
|
|
17
17
|
|
18
18
|
it "should provide access to the underlying type's methods" do
|
19
19
|
number = Number.new('2.34')
|
20
|
-
number.floor.
|
20
|
+
expect(number.floor).to eq(2)
|
21
21
|
end
|
22
22
|
|
23
23
|
it '#to_s should use the underlying types #to_s method' do
|
24
24
|
number = Number.parse('2.34')
|
25
|
-
number.to_s.
|
25
|
+
expect(number.to_s).to eq('2.34')
|
26
26
|
end
|
27
27
|
|
28
28
|
it '#to_yaml should provide a yaml representation of the items #to_s method' do
|
29
29
|
number = Number.parse('2.34')
|
30
|
-
number.to_yaml.
|
30
|
+
expect(number.to_yaml).to match(/---\s+['"]2.34['"]\n/)
|
31
31
|
end
|
32
32
|
|
33
33
|
it '#== should match against underlying type, string representation and self' do
|
34
34
|
number = Number.new('2.34')
|
35
|
-
(number == 2.34).
|
36
|
-
(number == '2.34').
|
37
|
-
(number == number).
|
35
|
+
expect(number == 2.34).to be_truthy
|
36
|
+
expect(number == '2.34').to be_truthy
|
37
|
+
expect(number == number).to be_truthy
|
38
38
|
|
39
|
-
(number == 2.44).
|
40
|
-
(number == '2.44').
|
41
|
-
(number == Number.new('2.44')).
|
39
|
+
expect(number == 2.44).to be_falsey
|
40
|
+
expect(number == '2.44').to be_falsey
|
41
|
+
expect(number == Number.new('2.44')).to be_falsey
|
42
42
|
end
|
43
43
|
|
44
44
|
end
|
@@ -4,23 +4,23 @@ describe Mida::DataType::Integer do
|
|
4
4
|
|
5
5
|
it '#parse should raise an exception if not a number' do
|
6
6
|
test = lambda {Mida::DataType::Integer.parse('hello')}
|
7
|
-
test.
|
7
|
+
expect(test).to raise_error(ArgumentError)
|
8
8
|
end
|
9
9
|
|
10
10
|
it '#parse should raise an exception if not an integer' do
|
11
11
|
test = lambda {Mida::DataType::Integer.parse('3.14')}
|
12
|
-
test.
|
12
|
+
expect(test).to raise_error(ArgumentError)
|
13
13
|
end
|
14
14
|
|
15
15
|
it '#parse should raise an exception if value is empty' do
|
16
16
|
test = lambda {Mida::DataType::Integer.parse('')}
|
17
|
-
test.
|
17
|
+
expect(test).to raise_error(ArgumentError)
|
18
18
|
end
|
19
19
|
|
20
20
|
it '#parse should accept a valid number' do
|
21
21
|
integer_text = '3'
|
22
22
|
integer = Mida::DataType::Integer.parse(integer_text)
|
23
|
-
integer.to_s.
|
23
|
+
expect(integer.to_s).to eq(integer_text)
|
24
24
|
end
|
25
25
|
|
26
26
|
end
|
@@ -4,12 +4,12 @@ describe Mida::DataType::ISO8601Date do
|
|
4
4
|
|
5
5
|
it '#parse should raise an exception if invalid date format' do
|
6
6
|
test = lambda {Mida::DataType::ISO8601Date.parse('27th August 2009')}
|
7
|
-
test.
|
7
|
+
expect(test).to raise_error(ArgumentError)
|
8
8
|
end
|
9
9
|
|
10
10
|
it '#parse should raise an exception if value is empty' do
|
11
11
|
test = lambda {Mida::DataType::ISO8601Date.parse('')}
|
12
|
-
test.
|
12
|
+
expect(test).to raise_error(ArgumentError)
|
13
13
|
end
|
14
14
|
|
15
15
|
context 'when passed a valid date' do
|
@@ -19,7 +19,7 @@ describe Mida::DataType::ISO8601Date do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
it '#to_s should return the date as an rfc822 text string' do
|
22
|
-
@date.to_s.
|
22
|
+
expect(@date.to_s).to eq("Thu, 27 Aug 2009 01:13:04 +0510")
|
23
23
|
end
|
24
24
|
|
25
25
|
end
|
@@ -4,18 +4,18 @@ describe Mida::DataType::Number do
|
|
4
4
|
|
5
5
|
it '#parse should raise an exception if not a number' do
|
6
6
|
test = lambda {Mida::DataType::Number.parse('hello')}
|
7
|
-
test.
|
7
|
+
expect(test).to raise_error(ArgumentError)
|
8
8
|
end
|
9
9
|
|
10
10
|
it '#parse should raise an exception if value is empty' do
|
11
11
|
test = lambda {Mida::DataType::Number.parse('')}
|
12
|
-
test.
|
12
|
+
expect(test).to raise_error(ArgumentError)
|
13
13
|
end
|
14
14
|
|
15
15
|
it '#parse should accept a valid number' do
|
16
16
|
num_text = '3.14'
|
17
17
|
num = Mida::DataType::Number.parse(num_text)
|
18
|
-
num.to_s.
|
18
|
+
expect(num.to_s).to eq(num_text)
|
19
19
|
end
|
20
20
|
|
21
21
|
end
|
data/spec/datatype/text_spec.rb
CHANGED
@@ -4,13 +4,13 @@ describe Mida::DataType::Text do
|
|
4
4
|
|
5
5
|
it '#parse should accept an empty string' do
|
6
6
|
text = Mida::DataType::Text.parse('')
|
7
|
-
text.
|
7
|
+
expect(text).to eq('')
|
8
8
|
end
|
9
9
|
|
10
10
|
it '#parse should return the input value' do
|
11
11
|
test_text = 'Some text'
|
12
12
|
text = Mida::DataType::Text.parse(test_text)
|
13
|
-
text.
|
13
|
+
expect(text).to eq(test_text)
|
14
14
|
end
|
15
15
|
|
16
16
|
end
|
data/spec/datatype/url_spec.rb
CHANGED
@@ -7,23 +7,23 @@ describe Mida::DataType::URL do
|
|
7
7
|
|
8
8
|
it '#parse should raise an exception if a bad url passed' do
|
9
9
|
test = lambda {Mida::DataType::URL.parse('example.com')}
|
10
|
-
test.
|
10
|
+
expect(test).to raise_error(ArgumentError)
|
11
11
|
end
|
12
12
|
|
13
13
|
it '#parse should raise an exception if value is empty' do
|
14
14
|
test = lambda {Mida::DataType::URL.parse('')}
|
15
|
-
test.
|
15
|
+
expect(test).to raise_error(ArgumentError)
|
16
16
|
end
|
17
17
|
|
18
18
|
it '#parse should accept a valid url' do
|
19
19
|
url_text = 'http://example.com/test/'
|
20
20
|
url = Mida::DataType::URL.parse(url_text)
|
21
|
-
url.to_s.
|
21
|
+
expect(url.to_s).to eq(url_text)
|
22
22
|
end
|
23
23
|
|
24
24
|
it '#parse should accept a valid url with special characters' do
|
25
25
|
url_text = 'http://example.com/übergangslösung'
|
26
26
|
url = Mida::DataType::URL.parse(url_text)
|
27
|
-
url.to_s.
|
27
|
+
expect(url.to_s).to eq(::Addressable::URI.encode(url_text))
|
28
28
|
end
|
29
29
|
end
|
data/spec/document_spec.rb
CHANGED
@@ -11,21 +11,21 @@ def test_parsing(md, vocabulary, expected_results)
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def test_to_h(item, expected_result)
|
14
|
-
item.to_h.
|
14
|
+
expect(item.to_h).to eq(expected_result)
|
15
15
|
end
|
16
16
|
|
17
17
|
def test_properties(item, expected_result)
|
18
18
|
item.properties.each do |name, value|
|
19
|
-
|
19
|
+
match_array_legacy(value, expected_result[:properties][name])
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
def
|
23
|
+
def match_array_legacy(value_array, expected_results)
|
24
24
|
value_array.each_with_index do |element, i|
|
25
25
|
if element.is_a?(Mida::Item)
|
26
26
|
test_properties(element, expected_results[i])
|
27
27
|
else
|
28
|
-
element.
|
28
|
+
expect(element).to eq(expected_results[i])
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
@@ -49,22 +49,29 @@ describe Mida::Document do
|
|
49
49
|
</body></html>
|
50
50
|
'
|
51
51
|
|
52
|
+
@nokogiri_document = Nokogiri(html)
|
53
|
+
|
52
54
|
@md = Mida::Document.new(html)
|
53
55
|
end
|
54
56
|
|
55
57
|
it '#each should pass each item to the block' do
|
56
58
|
item_num = 0
|
57
|
-
@md.each {|item| item.
|
59
|
+
@md.each {|item| expect(item).to eq(@md.items[item_num]); item_num += 1}
|
58
60
|
end
|
59
61
|
|
60
62
|
it 'should have access to the Enumerable mixin methods such as #find' do
|
61
63
|
review = @md.find {|item| item.type == 'http://data-vocabulary.org/Review'}
|
62
|
-
review.type.
|
63
|
-
review.properties['itemreviewed'].
|
64
|
+
expect(review.type).to eq('http://data-vocabulary.org/Review')
|
65
|
+
expect(review.properties['itemreviewed']).to eq(["Romeo Pizza"])
|
64
66
|
|
65
67
|
organization = @md.find {|item| item.type == 'http://data-vocabulary.org/Organization'}
|
66
|
-
organization.type.
|
67
|
-
organization.properties['name'].
|
68
|
+
expect(organization.type).to eq('http://data-vocabulary.org/Organization')
|
69
|
+
expect(organization.properties['name']).to eq(["An org name"])
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should not re-parse a nokogiri document' do
|
73
|
+
md = Mida::Document.new(@nokogiri_document)
|
74
|
+
expect(md.instance_variable_get(:@doc).object_id).to eq(@nokogiri_document.object_id)
|
68
75
|
end
|
69
76
|
end
|
70
77
|
|
@@ -116,14 +123,14 @@ describe Mida::Document, 'when run against a full html document containing items
|
|
116
123
|
|
117
124
|
it '#search should be able to match against items without an itemtype' do
|
118
125
|
items = @md.search(%r{^$})
|
119
|
-
items.size.
|
120
|
-
items[0].properties['name'].
|
126
|
+
expect(items.size).to eq(1)
|
127
|
+
expect(items[0].properties['name']).to eq(['An org name'])
|
121
128
|
end
|
122
129
|
|
123
130
|
it '#search should be able to match against items with an itemtype' do
|
124
131
|
items = @md.search(%r{^.+$})
|
125
|
-
items.size.
|
126
|
-
items[0].type.
|
132
|
+
expect(items.size).to eq(1)
|
133
|
+
expect(items[0].type).to eq('http://data-vocabulary.org/Review')
|
127
134
|
end
|
128
135
|
end
|
129
136
|
|
@@ -152,7 +159,7 @@ describe Mida::Document, 'when run against a full html document containing two n
|
|
152
159
|
end
|
153
160
|
|
154
161
|
it 'should return all the itemscopes' do
|
155
|
-
@md.items.size.
|
162
|
+
expect(@md.items.size).to eq(2)
|
156
163
|
end
|
157
164
|
|
158
165
|
it 'should give the type of each itemscope if none specified' do
|
@@ -165,8 +172,8 @@ describe Mida::Document, 'when run against a full html document containing two n
|
|
165
172
|
itemscope_names[item.type] += 1
|
166
173
|
end
|
167
174
|
|
168
|
-
itemscope_names.size.
|
169
|
-
itemscope_names.each { |name, num| num.
|
175
|
+
expect(itemscope_names.size).to eq 2
|
176
|
+
itemscope_names.each { |name, num| expect(num).to eq(1) }
|
170
177
|
end
|
171
178
|
|
172
179
|
|
@@ -220,11 +227,11 @@ describe Mida::Document, 'when run against a full html document containing one
|
|
220
227
|
end
|
221
228
|
|
222
229
|
it 'should not match itemscopes with different names' do
|
223
|
-
@md.search(%r{nothing}).size.
|
230
|
+
expect(@md.search(%r{nothing}).size).to eq(0)
|
224
231
|
end
|
225
232
|
|
226
233
|
it 'should find the correct number of itemscopes' do
|
227
|
-
@md.items.size.
|
234
|
+
expect(@md.items.size).to eq(1)
|
228
235
|
end
|
229
236
|
|
230
237
|
it 'should return the correct number of itemscopes' do
|
@@ -232,7 +239,7 @@ describe Mida::Document, 'when run against a full html document containing one
|
|
232
239
|
%r{http://data-vocabulary.org/Product},
|
233
240
|
%r{http://data-vocabulary.org/Review-aggregate}
|
234
241
|
]
|
235
|
-
vocabularies.each {|vocabulary| @md.search(vocabulary).size.
|
242
|
+
vocabularies.each {|vocabulary| expect(@md.search(vocabulary).size).to eq(1)}
|
236
243
|
|
237
244
|
end
|
238
245
|
|
@@ -289,16 +296,16 @@ describe Mida::Document, 'when run against a document containing an itemscope
|
|
289
296
|
%r{http://data-vocabulary.org/Product} => 1,
|
290
297
|
%r{http://data-vocabulary.org/Review-aggregate} => 1
|
291
298
|
}
|
292
|
-
vocabularies.each {|vocabulary, num| @md.search(vocabulary).size.
|
299
|
+
vocabularies.each {|vocabulary, num| expect(@md.search(vocabulary).size).to eq(num)}
|
293
300
|
end
|
294
301
|
|
295
302
|
it 'should return the correct number of items' do
|
296
|
-
@md.items.size.
|
303
|
+
expect(@md.items.size).to eq(2)
|
297
304
|
end
|
298
305
|
|
299
306
|
context "when no vocabulary specified or looking at the outer vocabulary" do
|
300
307
|
it 'should return all the properties from the text with the correct values' do
|
301
|
-
|
308
|
+
skip("get the contains: feature working")
|
302
309
|
expected_result = {
|
303
310
|
type: 'http://data-vocabulary.org/Product',
|
304
311
|
properties: {
|
@@ -314,7 +321,7 @@ describe Mida::Document, 'when run against a document containing an itemscope
|
|
314
321
|
}
|
315
322
|
}
|
316
323
|
|
317
|
-
@md.search('http://data-vocabulary.org/Product').first.
|
324
|
+
expect(@md.search('http://data-vocabulary.org/Product').first).to eq(expected_result)
|
318
325
|
end
|
319
326
|
end
|
320
327
|
end
|