63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/unicoder/builder.rb', line 63
def parse_file(identifier, parse_mode, **parse_options)
filename = UNICODE_FILES[identifier.to_sym] || filename
raise ArgumentError, "No valid file identifier or filename given" if !filename
filename = filename.dup
filename.sub! 'UNICODE_VERSION', @unicode_version
filename.sub! 'EMOJI_VERSION', @emoji_version
filename.sub! 'EMOJI_RELATED_VERSION', EMOJI_RELATED_UNICODE_VERSIONS[@emoji_version]
filename.sub! '.zip', ''
filename.sub! /\A(https?|ftp):\//, ""
Downloader.fetch(identifier) unless File.exist?(LOCAL_DATA_DIRECTORY + filename)
file = File.read(LOCAL_DATA_DIRECTORY + filename)
if parse_mode == :line
active = !parse_options[:begin]
file.each_line{ |line|
if !active && parse_options[:begin] && line.match?(parse_options[:begin])
active = true
elsif active && parse_options[:end] && line.match?(parse_options[:end])
active = false
end
if active
yield Hash[ $~.names.zip( $~.captures ) ] if line =~ parse_options[:regex]
end
}
elsif parse_mode == :xml
require "oga"
yield Oga.parse_xml(file)
else
yield file
end
end
|