lib/gps_pvt/util.rb in gps_pvt-0.9.0 vs lib/gps_pvt/util.rb in gps_pvt-0.9.1
- old
+ new
@@ -21,37 +21,47 @@
buf += f.call(len - buf.size) while buf.size < len
buf
}
def eof?; false; end
}
- module Kernel
- open_orig = instance_method(:open)
- define_method(:open){|*args, &b|
- return open_orig.bind(self).call(*args, &b) unless Serial::SPEC =~ args[0]
- Serial::new($1, $2 ? $2.to_i : 115200)
- }
- module_function(:open)
- end
}.call if require 'rubyserial'
require 'open-uri'
require_relative 'ntrip'
class URI::Ntrip
def read_format(options = {})
pnt_list = self.read_source_table(options).mount_points
case pnt_list[self.mount_point][:format]
when /u-?b(?:lo)?x/i; :ubx
- when /RTCM 3/i; :rtcm3
+ when /RTCM ?3/i; :rtcm3
else; nil
end
end
end
module GPS_PVT
module Util
class << self
+ def special_stream?(spec)
+ ['-', (Serial::SPEC rescue nil)].compact.any?{|v| v === spec}
+ end
+ def open(*args, &b)
+ return args[0].open(*args[1..-1], &b) if args[0].respond_to?(:open)
+ case args[0].to_str
+ when (Serial::SPEC rescue nil)
+ return ((@serial_ports ||= {})[$1] ||= Serial::new($1, $2 ? $2.to_i : 115200))
+ when '-'
+ if (/^[wa]/ === args[1]) \
+ || (args[1].kind_of?(Integer) && ((File::Constants::WRONLY & args[1]) > 0)) then
+ return STDOUT
+ else
+ return STDIN
+ end
+ end rescue nil
+ super
+ end
def inflate(src, type = :gz)
case type
when :gz
require 'zlib'
Zlib::GzipReader.send(*(src.kind_of?(IO) ? [:new, src] : [:open, src]))
@@ -64,10 +74,10 @@
raise "Unknown compression type: #{type} of #{src}"
end
end
def get_txt(fname_or_uri)
is_uri = fname_or_uri.kind_of?(URI)
- (is_uri ? URI : Kernel).send(:open, fname_or_uri){|src|
+ open(fname_or_uri){|src|
compressed = proc{
case src.content_type
when /gzip/; next :gz
end if is_uri
case fname_or_uri.to_s