fbo 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/fbo.rb +9 -2
- data/lib/fbo/chunked_file.rb +2 -5
- data/lib/fbo/interpreter.rb +59 -70
- data/lib/fbo/node_extensions.rb +20 -16
- data/lib/fbo/parser.rb +1 -1
- data/lib/fbo/segmented_file.rb +64 -0
- data/lib/fbo/version.rb +1 -1
- data/spec/fbo/chunked_file_spec.rb +4 -4
- data/spec/fbo/interpreter_spec.rb +76 -44
- data/spec/fbo/segmented_file_spec.rb +48 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 038791a71715415069e8fef85ee55570b4c604a7
|
4
|
+
data.tar.gz: ec28f0ae4378dd0d7066bada202ce433d8f5ef32
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29f5094d45d2a9014447e79ffd852da117b4040005713420ec186e2adf1491223e3b910f7f0e5c577e8d4b1c431d960b59783646ff9678dd92746c3b394e9268
|
7
|
+
data.tar.gz: 4499d2b12c10327761a83c834db340aa515b44bfdb822f1e0b423596fa1a166cd6a8f401600f5fc2d5934cdec9ecf9edafd0b9cbb3ec4345ddc78f30afd2cd12
|
data/lib/fbo.rb
CHANGED
@@ -1,11 +1,18 @@
|
|
1
1
|
require 'fbo/version'
|
2
2
|
|
3
|
+
module FBO
|
4
|
+
NOTICE_TYPES = %w( presol combine amdcss mod award ja itb fairopp fstd ) +
|
5
|
+
%w( srcsgt snote ssale epsupload delete archive unarchive )
|
6
|
+
NOTICE_TAG_NAMES = NOTICE_TYPES.map { |name| name.upcase }
|
7
|
+
NOTICE_CLOSE_REGEXP = /<\/(#{ NOTICE_TAG_NAMES.join('|') })>$/
|
8
|
+
|
9
|
+
end
|
10
|
+
|
3
11
|
require 'fbo/file'
|
4
12
|
require 'fbo/chunked_file'
|
13
|
+
require 'fbo/segmented_file'
|
5
14
|
require 'fbo/remote_file'
|
6
15
|
require 'fbo/parser'
|
7
16
|
require 'fbo/node_extensions'
|
8
17
|
require 'fbo/interpreter'
|
9
18
|
|
10
|
-
module FBO
|
11
|
-
end
|
data/lib/fbo/chunked_file.rb
CHANGED
@@ -9,9 +9,6 @@ module FBO
|
|
9
9
|
|
10
10
|
|
11
11
|
DEFAULT_CHUNK_SIZE = 250 * 1024 # 250KB
|
12
|
-
NOTICE_TAG_NAMES = %w( PRESOL COMBINE AMDCSS MOD AWARD JA ITB FAIROPP FSTD) +
|
13
|
-
%w( SRCSGT SNOTE SSALE EPSUPLOAD DELETE ARCHIVE UNARCHIVE )
|
14
|
-
NOTICE_CLOSE_REGEXP = /<\/(#{ NOTICE_TAG_NAMES.join('|') })>$/
|
15
12
|
|
16
13
|
|
17
14
|
def initialize(file, chunk_size = DEFAULT_CHUNK_SIZE)
|
@@ -46,12 +43,12 @@ module FBO
|
|
46
43
|
end while (chunk.bytesize < @chunk_size)
|
47
44
|
|
48
45
|
# Add lines up to the end of a notice.
|
49
|
-
if line && line !~ NOTICE_CLOSE_REGEXP
|
46
|
+
if line && line !~ FBO::NOTICE_CLOSE_REGEXP
|
50
47
|
begin
|
51
48
|
line = gets
|
52
49
|
break unless line
|
53
50
|
chunk += line
|
54
|
-
break if line =~ NOTICE_CLOSE_REGEXP
|
51
|
+
break if line =~ FBO::NOTICE_CLOSE_REGEXP
|
55
52
|
end while (true)
|
56
53
|
end
|
57
54
|
|
data/lib/fbo/interpreter.rb
CHANGED
@@ -1,87 +1,76 @@
|
|
1
1
|
module FBO
|
2
2
|
class Interpreter
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
def each_combined_solicitation
|
16
|
-
each_node(nodes_by_type(FBO::Dump::CombinedSolicitationNode), &Proc.new)
|
17
|
-
end
|
18
|
-
|
19
|
-
def each_amendment
|
20
|
-
each_node(nodes_by_type(FBO::Dump::AmendmentNode), &Proc.new)
|
21
|
-
end
|
22
|
-
|
23
|
-
def each_modification
|
24
|
-
each_node(nodes_by_type(FBO::Dump::ModificationNode), &Proc.new)
|
25
|
-
end
|
26
|
-
|
27
|
-
def each_award
|
28
|
-
each_node(nodes_by_type(FBO::Dump::AwardNode), &Proc.new)
|
29
|
-
end
|
30
|
-
|
31
|
-
def each_justification_and_approval
|
32
|
-
each_node(nodes_by_type(FBO::Dump::JustificationAndApprovalNode), &Proc.new)
|
33
|
-
end
|
34
|
-
|
35
|
-
def each_intent_to_bundle
|
36
|
-
each_node(nodes_by_type(FBO::Dump::IntentToBundleNode), &Proc.new)
|
37
|
-
end
|
38
|
-
|
39
|
-
def each_fair_opportunity
|
40
|
-
each_node(nodes_by_type(FBO::Dump::FairOpportunityNode), &Proc.new)
|
41
|
-
end
|
42
|
-
|
43
|
-
def each_sources_sought
|
44
|
-
each_node(nodes_by_type(FBO::Dump::SourcesSoughtNode), &Proc.new)
|
45
|
-
end
|
46
|
-
|
47
|
-
def each_foreign_standard
|
48
|
-
each_node(nodes_by_type(FBO::Dump::ForeignStandardNode), &Proc.new)
|
49
|
-
end
|
50
|
-
|
51
|
-
def each_special_notice
|
52
|
-
each_node(nodes_by_type(FBO::Dump::SpecialNoticeNode), &Proc.new)
|
3
|
+
class << self
|
4
|
+
def notice_enumeration(name, type)
|
5
|
+
define_method(name) do |&block|
|
6
|
+
selected = notice_nodes(type)
|
7
|
+
return unless selected
|
8
|
+
selected.each do |node|
|
9
|
+
block.call node.to_hash.merge({ type: node.type })
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
53
13
|
end
|
54
14
|
|
55
|
-
|
56
|
-
|
15
|
+
notice_enumeration :each_notice, :all
|
16
|
+
notice_enumeration :each_presolicitation, :presol
|
17
|
+
notice_enumeration :each_combined_solicitation, :combine
|
18
|
+
notice_enumeration :each_amendment, :amdcss
|
19
|
+
notice_enumeration :each_modification, :mod
|
20
|
+
notice_enumeration :each_award, :award
|
21
|
+
notice_enumeration :each_justification_and_approval, :ja
|
22
|
+
notice_enumeration :each_intent_to_bundle, :itb
|
23
|
+
notice_enumeration :each_fair_opportunity, :fairopp
|
24
|
+
notice_enumeration :each_sources_sought, :srcsgt
|
25
|
+
notice_enumeration :each_foreign_standard, :fstd
|
26
|
+
notice_enumeration :each_special_notice, :snote
|
27
|
+
notice_enumeration :each_sale_of_surplus, :ssale
|
28
|
+
notice_enumeration :each_document_upload, :epsupload
|
29
|
+
notice_enumeration :each_document_delete, :delete
|
30
|
+
notice_enumeration :each_document_archival, :archive
|
31
|
+
notice_enumeration :each_document_unarchival, :unarchive
|
32
|
+
|
33
|
+
def initialize(file)
|
34
|
+
@file = file
|
57
35
|
end
|
58
36
|
|
59
|
-
|
60
|
-
each_node(nodes_by_type(FBO::Dump::DocumentUploadNode), &Proc.new)
|
61
|
-
end
|
37
|
+
private
|
62
38
|
|
63
|
-
def
|
64
|
-
|
65
|
-
|
39
|
+
def notice_nodes(type = :all)
|
40
|
+
if @notice_nodes.nil?
|
41
|
+
@notice_nodes = {}
|
42
|
+
end
|
66
43
|
|
67
|
-
|
68
|
-
|
44
|
+
if @file.is_a?(FBO::SegmentedFile) && type != :all
|
45
|
+
@notice_nodes[type] = parse_segment(type)
|
46
|
+
else
|
47
|
+
@notice_nodes[:all] = parse_file
|
48
|
+
if type == :all
|
49
|
+
@notice_nodes[:all]
|
50
|
+
else
|
51
|
+
@notice_nodes[type] = @notice_nodes[:all].select { |n| n.type == type }
|
52
|
+
end
|
53
|
+
end
|
69
54
|
end
|
70
55
|
|
71
|
-
def
|
72
|
-
|
56
|
+
def parse_file
|
57
|
+
tree = FBO::Parser.new(@file).parse
|
58
|
+
tree.elements
|
73
59
|
end
|
74
60
|
|
75
|
-
|
76
|
-
|
77
|
-
def nodes_by_type(type)
|
78
|
-
@notice_nodes.select { |n| n.is_a? type }
|
79
|
-
end
|
61
|
+
def parse_segment(type = :all)
|
62
|
+
return unless @file.is_a? FBO::SegmentedFile
|
80
63
|
|
81
|
-
|
82
|
-
|
83
|
-
|
64
|
+
content = ""
|
65
|
+
if type == :all
|
66
|
+
content = @file.contents
|
67
|
+
else
|
68
|
+
content = @file.contents_for_type(type)
|
84
69
|
end
|
70
|
+
return unless content
|
71
|
+
|
72
|
+
tree = FBO::Parser.new.parse(content)
|
73
|
+
tree.elements
|
85
74
|
end
|
86
75
|
end
|
87
76
|
end
|
data/lib/fbo/node_extensions.rb
CHANGED
@@ -14,84 +14,88 @@ module FBO
|
|
14
14
|
body_node = elements.first
|
15
15
|
Hash[ body_node.elements.map { |e| [ e.to_sym, e.value ] } ]
|
16
16
|
end
|
17
|
+
|
18
|
+
def type
|
19
|
+
self.class.type
|
20
|
+
end
|
17
21
|
end
|
18
22
|
class PresolicitationNode < NoticeNode
|
19
|
-
def type
|
23
|
+
def self.type
|
20
24
|
:presol
|
21
25
|
end
|
22
26
|
end
|
23
27
|
class CombinedSolicitationNode < NoticeNode
|
24
|
-
def type
|
28
|
+
def self.type
|
25
29
|
:combine
|
26
30
|
end
|
27
31
|
end
|
28
32
|
class AmendmentNode < NoticeNode
|
29
|
-
def type
|
33
|
+
def self.type
|
30
34
|
:amdcss
|
31
35
|
end
|
32
36
|
end
|
33
37
|
class ModificationNode < NoticeNode
|
34
|
-
def type
|
38
|
+
def self.type
|
35
39
|
:mod
|
36
40
|
end
|
37
41
|
end
|
38
42
|
class AwardNode < NoticeNode
|
39
|
-
def type
|
43
|
+
def self.type
|
40
44
|
:award
|
41
45
|
end
|
42
46
|
end
|
43
47
|
class JustificationAndApprovalNode < NoticeNode
|
44
|
-
def type
|
48
|
+
def self.type
|
45
49
|
:ja
|
46
50
|
end
|
47
51
|
end
|
48
52
|
class IntentToBundleNode < NoticeNode
|
49
|
-
def type
|
53
|
+
def self.type
|
50
54
|
:itb
|
51
55
|
end
|
52
56
|
end
|
53
57
|
class FairOpportunityNode < NoticeNode
|
54
|
-
def type
|
58
|
+
def self.type
|
55
59
|
:fairopp
|
56
60
|
end
|
57
61
|
end
|
58
62
|
class SourcesSoughtNode < NoticeNode
|
59
|
-
def type
|
63
|
+
def self.type
|
60
64
|
:srcsgt
|
61
65
|
end
|
62
66
|
end
|
63
67
|
class ForeignStandardNode < NoticeNode
|
64
|
-
def type
|
68
|
+
def self.type
|
65
69
|
:fstd
|
66
70
|
end
|
67
71
|
end
|
68
72
|
class SpecialNoticeNode < NoticeNode
|
69
|
-
def type
|
73
|
+
def self.type
|
70
74
|
:snote
|
71
75
|
end
|
72
76
|
end
|
73
77
|
class SaleOfSurplusNode < NoticeNode
|
74
|
-
def type
|
78
|
+
def self.type
|
75
79
|
:ssale
|
76
80
|
end
|
77
81
|
end
|
78
82
|
class DocumentUploadNode < NoticeNode
|
79
|
-
def type
|
83
|
+
def self.type
|
80
84
|
:epsupload
|
81
85
|
end
|
82
86
|
end
|
83
87
|
class DocumentDeletingNode < NoticeNode
|
84
|
-
def type
|
88
|
+
def self.type
|
85
89
|
:delete
|
86
90
|
end
|
87
91
|
end
|
88
92
|
class DocumentArchivalNode < NoticeNode
|
89
|
-
def type
|
93
|
+
def self.type
|
90
94
|
:archive
|
91
95
|
end
|
92
96
|
end
|
93
97
|
class DocumentUnarchivalNode < NoticeNode
|
94
|
-
def type
|
98
|
+
def self.type
|
95
99
|
:unarchive
|
96
100
|
end
|
97
101
|
end
|
data/lib/fbo/parser.rb
CHANGED
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
module FBO
|
4
|
+
class SegmentedFile
|
5
|
+
extend Forwardable
|
6
|
+
|
7
|
+
attr_reader :file
|
8
|
+
def_delegators :@file, :readline, :read, :eof?
|
9
|
+
|
10
|
+
|
11
|
+
def initialize(file)
|
12
|
+
@file = file
|
13
|
+
end
|
14
|
+
|
15
|
+
FBO::NOTICE_TYPES.each do |type|
|
16
|
+
# Define RegExp constants for partitioning the file
|
17
|
+
regexp_constant_name = "#{ type.upcase }_REGEXP"
|
18
|
+
regexp = /<#{ type.upcase }>.*<\/#{ type.upcase }>/m
|
19
|
+
FBO::SegmentedFile.const_set(regexp_constant_name, regexp)
|
20
|
+
|
21
|
+
# Define methods for accessing content segments
|
22
|
+
method_name = "#{ type }_contents"
|
23
|
+
variable_name = "@#{ type }_contents"
|
24
|
+
define_method(method_name) do
|
25
|
+
if !instance_variable_defined?(variable_name)
|
26
|
+
regexp = FBO::SegmentedFile.const_get(regexp_constant_name)
|
27
|
+
match_data = @file.contents.match(regexp)
|
28
|
+
matched_text = cleanup_data( match_data ? match_data.to_s : nil)
|
29
|
+
instance_variable_set(variable_name, matched_text)
|
30
|
+
end
|
31
|
+
instance_variable_get(variable_name)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def contents
|
36
|
+
if @contents.nil?
|
37
|
+
@contents = [ presol_contents, combine_contents, amdcss_contents,
|
38
|
+
mod_contents, award_contents, ja_contents, itb_contents,
|
39
|
+
fairopp_contents, srcsgt_contents, fstd_contents,
|
40
|
+
snote_contents, ssale_contents, epsupload_contents,
|
41
|
+
delete_contents, archive_contents, unarchive_contents ]
|
42
|
+
@contents.compact!
|
43
|
+
#@contents = @file.contents
|
44
|
+
end
|
45
|
+
@contents
|
46
|
+
end
|
47
|
+
|
48
|
+
def contents_for_type(type)
|
49
|
+
return unless type
|
50
|
+
method_name = "#{ type }_contents"
|
51
|
+
self.respond_to?(method_name) ? self.send(method_name) : nil
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def cleanup_data(data)
|
57
|
+
return if data.nil?
|
58
|
+
data.encode('UTF-16le', :invalid => :replace, :replace => '')
|
59
|
+
.encode('UTF-8')
|
60
|
+
.gsub(/\r\n/, "\n")
|
61
|
+
.gsub(/^M/, "")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/lib/fbo/version.rb
CHANGED
@@ -6,16 +6,16 @@ describe FBO::ChunkedFile do
|
|
6
6
|
let(:chunk_size) { 50 * 1024 } # 50KB
|
7
7
|
subject { FBO::ChunkedFile.new(file, chunk_size) }
|
8
8
|
|
9
|
-
describe
|
10
|
-
it
|
9
|
+
describe '#contents' do
|
10
|
+
it 'returns an Array of String' do
|
11
11
|
subject.contents.must_be_instance_of Array
|
12
12
|
subject.contents.each { |x| x.must_be_instance_of String }
|
13
13
|
end
|
14
14
|
|
15
|
-
it
|
15
|
+
it 'returns chunks that include whole notices' do
|
16
16
|
contents = subject.contents
|
17
17
|
contents.each do |chunk|
|
18
|
-
chunk.must_match FBO::
|
18
|
+
chunk.must_match FBO::NOTICE_CLOSE_REGEXP
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
@@ -3,71 +3,103 @@ require 'spec_helper'
|
|
3
3
|
describe FBO::Interpreter do
|
4
4
|
let(:filename) { File.join(File.dirname(__FILE__), '..', 'fixtures', 'FBOFeed20130331') }
|
5
5
|
let(:file) { FBO::File.new(filename) }
|
6
|
-
let(:tree) { FBO::Parser.new(file).parse }
|
7
6
|
let(:actor) { stub('Act on ALL the Notices', process: nil) }
|
8
7
|
|
9
|
-
|
8
|
+
context 'with input FBO::File' do
|
9
|
+
subject { FBO::Interpreter.new(file) }
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
describe '#each_notice' do
|
12
|
+
it 'acts on each notice' do
|
13
|
+
actor.expects(:process).with(instance_of(Hash)).times(8)
|
14
|
+
subject.each_notice { |n| actor.process(n) }
|
15
|
+
end
|
15
16
|
end
|
16
|
-
end
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
describe '#each_presolicitation' do
|
19
|
+
it 'acts on each PRESOL notice' do
|
20
|
+
actor.expects(:process).with(has_entry(solicitation_number: 'SPE4A713R0795'))
|
21
|
+
subject.each_presolicitation { |n| actor.process(n) }
|
22
|
+
end
|
22
23
|
end
|
23
|
-
end
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
describe '#each_sources_sought' do
|
26
|
+
it 'acts on each SRCSGT notice' do
|
27
|
+
actor.expects(:process).with(has_entry(solicitation_number: 'W5J9JE-13-S-0002'))
|
28
|
+
subject.each_sources_sought { |n| actor.process(n) }
|
29
|
+
end
|
29
30
|
end
|
30
|
-
end
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
describe '#each_special_notice' do
|
33
|
+
it 'does nothing (no SNOTE notices)' do
|
34
|
+
actor.expects(:process).never
|
35
|
+
subject.each_special_notice { |n| actor.process(n) }
|
36
|
+
end
|
36
37
|
end
|
37
38
|
end
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
40
|
+
context 'with input FBO::ChunkedFile' do
|
41
|
+
let(:chunked) { FBO::ChunkedFile.new(file) }
|
42
|
+
subject { FBO::Interpreter.new(chunked) }
|
43
|
+
|
44
|
+
describe '#each_notice' do
|
45
|
+
it 'acts on each notice' do
|
46
|
+
actor.expects(:process).with(instance_of(Hash)).times(8)
|
47
|
+
subject.each_notice { |n| actor.process(n) }
|
48
|
+
end
|
43
49
|
end
|
44
|
-
end
|
45
50
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
51
|
+
describe '#each_presolicitation' do
|
52
|
+
it 'acts on each PRESOL notice' do
|
53
|
+
actor.expects(:process).with(has_entry(solicitation_number: 'SPE4A713R0795'))
|
54
|
+
subject.each_presolicitation { |n| actor.process(n) }
|
55
|
+
end
|
50
56
|
end
|
51
|
-
end
|
52
57
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
58
|
+
describe '#each_sources_sought' do
|
59
|
+
it 'acts on each SRCSGT notice' do
|
60
|
+
actor.expects(:process).with(has_entry(solicitation_number: 'W5J9JE-13-S-0002'))
|
61
|
+
subject.each_sources_sought { |n| actor.process(n) }
|
62
|
+
end
|
57
63
|
end
|
58
|
-
end
|
59
64
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
65
|
+
describe '#each_special_notice' do
|
66
|
+
it 'does nothing (no SNOTE notices)' do
|
67
|
+
actor.expects(:process).never
|
68
|
+
subject.each_special_notice { |n| actor.process(n) }
|
69
|
+
end
|
64
70
|
end
|
65
71
|
end
|
66
72
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
73
|
+
context 'with input FBO::SegmentedFile' do
|
74
|
+
let(:segmented) { FBO::SegmentedFile.new(file) }
|
75
|
+
subject { FBO::Interpreter.new(segmented) }
|
76
|
+
|
77
|
+
describe '#each_notice' do
|
78
|
+
it 'acts on each notice' do
|
79
|
+
actor.expects(:process).with(instance_of(Hash)).times(8)
|
80
|
+
subject.each_notice { |n| actor.process(n) }
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe '#each_presolicitation' do
|
85
|
+
it 'acts on each PRESOL notice' do
|
86
|
+
actor.expects(:process).with(has_entry(solicitation_number: 'SPE4A713R0795'))
|
87
|
+
subject.each_presolicitation { |n| actor.process(n) }
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe '#each_sources_sought' do
|
92
|
+
it 'acts on each SRCSGT notice' do
|
93
|
+
actor.expects(:process).with(has_entry(solicitation_number: 'W5J9JE-13-S-0002'))
|
94
|
+
subject.each_sources_sought { |n| actor.process(n) }
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe '#each_special_notice' do
|
99
|
+
it 'does nothing (no SNOTE notices)' do
|
100
|
+
actor.expects(:process).never
|
101
|
+
subject.each_special_notice { |n| actor.process(n) }
|
102
|
+
end
|
71
103
|
end
|
72
104
|
end
|
73
105
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FBO::SegmentedFile do
|
4
|
+
let(:filename) { File.join(File.dirname(__FILE__), '..', 'fixtures', 'FBOFeed20131003') }
|
5
|
+
let(:file) { FBO::File.new(filename) }
|
6
|
+
subject { FBO::SegmentedFile.new(file) }
|
7
|
+
|
8
|
+
describe "#contents" do
|
9
|
+
it "returns an Array of String" do
|
10
|
+
subject.contents.must_be_instance_of Array
|
11
|
+
subject.contents.each { |x| x.must_be_instance_of String }
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns chunks that include whole notices" do
|
15
|
+
contents = subject.contents
|
16
|
+
contents.each do |segment|
|
17
|
+
segment.must_match FBO::NOTICE_CLOSE_REGEXP
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#presol_contents' do
|
23
|
+
let(:presol_contents) { subject.presol_contents }
|
24
|
+
|
25
|
+
it 'returns a single big String' do
|
26
|
+
presol_contents.must_be_instance_of String
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'must start and end with a PRESOL' do
|
30
|
+
presol_contents.must_match /^<PRESOL>/m
|
31
|
+
presol_contents.must_match /<\/PRESOL>$/m
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should not contain other notice types' do
|
35
|
+
non_presols = FBO::NOTICE_TAG_NAMES - [ 'PRESOL' ]
|
36
|
+
regexp_constants = non_presols.map { |name| FBO::SegmentedFile.const_get("#{ name }_REGEXP") }
|
37
|
+
regexp_constants.each do |regexp|
|
38
|
+
presol_contents.wont_match regexp
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '#fstd_contents' do
|
44
|
+
it 'returns nil (no content)' do
|
45
|
+
subject.fstd_contents.must_be_nil
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fbo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Kottom
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: treetop
|
@@ -121,12 +121,14 @@ files:
|
|
121
121
|
- lib/fbo/node_extensions.rb
|
122
122
|
- lib/fbo/parser.rb
|
123
123
|
- lib/fbo/remote_file.rb
|
124
|
+
- lib/fbo/segmented_file.rb
|
124
125
|
- lib/fbo/version.rb
|
125
126
|
- spec/fbo/chunked_file_spec.rb
|
126
127
|
- spec/fbo/file_spec.rb
|
127
128
|
- spec/fbo/interpreter_spec.rb
|
128
129
|
- spec/fbo/parser_spec.rb
|
129
130
|
- spec/fbo/remote_file_spec.rb
|
131
|
+
- spec/fbo/segmented_file_spec.rb
|
130
132
|
- spec/fixtures/.keep
|
131
133
|
- spec/fixtures/FBOFeed20130331
|
132
134
|
- spec/fixtures/FBOFeed20131003
|
@@ -161,6 +163,7 @@ test_files:
|
|
161
163
|
- spec/fbo/interpreter_spec.rb
|
162
164
|
- spec/fbo/parser_spec.rb
|
163
165
|
- spec/fbo/remote_file_spec.rb
|
166
|
+
- spec/fbo/segmented_file_spec.rb
|
164
167
|
- spec/fixtures/.keep
|
165
168
|
- spec/fixtures/FBOFeed20130331
|
166
169
|
- spec/fixtures/FBOFeed20131003
|