Class: WorldDb::CountryReader
- Inherits:
-
Object
- Object
- WorldDb::CountryReader
show all
- Includes:
- LogUtils::Logging, TextUtils::ValueHelper, Model
- Defined in:
- lib/worlddb/readers/country.rb
Constant Summary
Constants included
from Model
Model::Prop, Model::Tag, Model::Tagging
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(text, more_attribs = {}) ⇒ CountryReader
Returns a new instance of CountryReader.
61
62
63
64
65
66
|
# File 'lib/worlddb/readers/country.rb', line 61
def initialize( text, more_attribs={} )
@text = text
@more_attribs = more_attribs
end
|
Class Method Details
.from_file(path, more_attribs = {}) ⇒ Object
46
47
48
49
50
51
|
# File 'lib/worlddb/readers/country.rb', line 46
def self.from_file( path, more_attribs={} )
text = File.read_utf8( path )
self.from_string( text, more_attribs )
end
|
.from_string(text, more_attribs = {}) ⇒ Object
53
54
55
|
# File 'lib/worlddb/readers/country.rb', line 53
def self.from_string( text, more_attribs={} )
CountryReader.new( text, more_attribs )
end
|
.from_zip(zip_file, entry_path, more_attribs = {}) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/worlddb/readers/country.rb', line 17
def self.from_zip( zip_file, entry_path, more_attribs={} )
entry = zip_file.find_entry( entry_path )
text = entry.get_input_stream().read()
logger = LogUtils::Logger.root
logger.debug "text.encoding.name (before): #{text.encoding.name}"
text = text.force_encoding( Encoding::UTF_8 )
logger.debug "text.encoding.name (after): #{text.encoding.name}"
self.from_string( text, more_attribs )
end
|
Instance Method Details
#read ⇒ Object
68
69
70
71
72
73
74
75
|
# File 'lib/worlddb/readers/country.rb', line 68
def read()
reader = ValuesReader.from_string( @text, @more_attribs )
reader.each_line do |attribs, values|
opts = { skip_tags: skip_tags? }
Country.create_or_update_from_attribs( attribs, values, opts )
end
end
|
58
|
# File 'lib/worlddb/readers/country.rb', line 58
def skip_tags?() @skip_tags == true; end
|
#strict? ⇒ Boolean
59
|
# File 'lib/worlddb/readers/country.rb', line 59
def strict?() @strict == true; end
|