Class: BeerDb::ZipReader
Instance Method Summary
collapse
Methods inherited from ReaderBase
#load, #load_beers_for_country, #load_beers_for_country_n_state, #load_beers_worker, #load_breweries_for_country, #load_breweries_for_country_n_state, #load_breweries_worker, #load_setup
Methods included from Matcher
#match_beers_for_country, #match_beers_for_country_n_state, #match_breweries_for_country, #match_breweries_for_country_n_state, #match_brewpubs_for_country, #match_brewpubs_for_country_n_state
Constructor Details
#initialize(name, include_path, opts = {}) ⇒ ZipReader
Returns a new instance of ZipReader.
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/beerdb/reader_zip.rb', line 8
def initialize( name, include_path, opts = {} )
path = "#{include_path}/#{name}.zip"
@zip_file = Zip::File.open( path )
@zip_prefix = ''
end
|
Instance Method Details
#close ⇒ Object
31
32
33
34
|
# File 'lib/beerdb/reader_zip.rb', line 31
def close
@zip_file.close
end
|
#create_beers_reader(name, more_attribs = {}) ⇒ Object
66
67
68
69
70
71
72
|
# File 'lib/beerdb/reader_zip.rb', line 66
def create_beers_reader( name, more_attribs={} )
path = name_to_zip_entry_path( name )
logger.debug "parsing data (beers) in zip '#{name}' (#{path})..."
BeerReader.from_zip( @zip_file, path, more_attribs )
end
|
#create_breweries_reader(name, more_attribs = {}) ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/beerdb/reader_zip.rb', line 75
def create_breweries_reader( name, more_attribs={} )
path = name_to_zip_entry_path( name )
logger.debug "parsing data (breweries) in zip '#{name}' (#{path})..."
if name =~ /\(m\)/ more_attribs[ :prod_m ] = true
elsif name =~ /\(l\)/ more_attribs[ :prod_l ] = true
else
end
BreweryReader.from_zip( @zip_file, path, more_attribs )
end
|
#create_fixture_reader(name) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/beerdb/reader_zip.rb', line 37
def create_fixture_reader( name )
query = "**/#{name}.txt"
candidates = @zip_file.glob( query )
pp candidates
path = candidates[0].name
logger.debug " zip entry path >>#{path}<<"
@zip_prefix = path[ 0...(path.size-(name.size+4)) ]
logger.debug " zip entry prefix >>#{@zip_prefix}<<"
logger.info "parsing data in zip '#{name}' (#{path})..."
FixtureReader.from_zip( @zip_file, path )
end
|