Class: Wms::Input::AndroidWifiLocation

Inherits:
Base show all
Defined in:
lib/wms/input/android_wifilocation.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#tags

Attributes included from Config::Mixin

#config

Attributes inherited from Plugin::Plugin

#logger, #params, #state

Instance Method Summary collapse

Methods inherited from Base

#initialize, #tag

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

#filepathObject

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(options={})
  raise "#{self.class.name}: filepath required in options" unless options[:filepath]
  @filepath   = options[:filepath]
  @compressed = options[:compressed]
  @file_ext   = options[:file_ext]
  @is_gz      = options[: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