Class: Wms::Input::AndroidWifiLocation
- Inherits:
-
Base
- Object
- Plugin::Plugin
- Base
- Wms::Input::AndroidWifiLocation
- Defined in:
- lib/wms/input/android_wifilocation.rb
Instance Attribute Summary collapse
-
#filepath ⇒ Object
Returns the value of attribute filepath.
Attributes inherited from Base
Attributes included from Config::Mixin
Attributes inherited from Plugin::Plugin
Instance Method Summary collapse
Methods inherited from Base
Methods included from Config::Mixin
#get_config, included, #init_config, #set_config, #source
Methods inherited from Plugin::Plugin
#finished, #initialize, #shutdown
Constructor Details
This class inherits a constructor from Wms::Input::Base
Instance Attribute Details
#filepath ⇒ Object
Returns the value of attribute filepath.
8 9 10 |
# File 'lib/wms/input/android_wifilocation.rb', line 8 def filepath @filepath end |
Instance Method Details
#register(options = {}) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/wms/input/android_wifilocation.rb', line 12 def register(={}) raise "#{self.class.name}: filepath required in options" unless [:filepath] @filepath = [:filepath] @compressed = [:compressed] @file_ext = [:file_ext] @is_gz = [:file_ext] == '.gz' end |
#run(&block) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 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 64 65 66 |
# File 'lib/wms/input/android_wifilocation.rb', line 24 def run(&block) # adding options to make data manipulation easy total_lines = 0 str_arr = [] if @is_gz Zlib::GzipReader.open(@filepath) do |csv| csv.read.each_line do |line| str_arr = [] str_arr << '[' str_arr << line str_arr << ']' joined_str = str_arr.join("") json_obj = JSON.parse(joined_str) norm_json = normlaize_json_obj(json_obj) callback = block callback.call(norm_json) # @logger.debug ">>>>>>#{norm_json}" total_lines += 1 end end @logger.debug "Total line: %d" % total_lines else File.open(@filepath, "r").each_line do |line| str_arr = [] str_arr << '[' str_arr << line str_arr << ']' joined_str = str_arr.join("") json_obj = JSON.parse(joined_str) norm_json = normlaize_json_obj(json_obj) callback = block callback.call(norm_json) # @logger.debug ">>>>>>#{norm_json}" total_lines += 1 end end end |