apollo-crawler 0.0.41 → 0.0.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/bin/apollo-crawler CHANGED
@@ -35,6 +35,7 @@ module Crawler
35
35
  @optparser = nil
36
36
  @plugins = nil
37
37
  @formatters = nil
38
+ @formatter = nil
38
39
 
39
40
  # Initializer - Constructor
40
41
  def initialize
@@ -67,6 +68,10 @@ module Crawler
67
68
  @options[:run_all] = true
68
69
  end
69
70
 
71
+ opts.on('-f', '--format [NAME]', "Formatter used") do |name|
72
+ @options[:formatter] = name
73
+ end
74
+
70
75
  opts.on('-g', '--generate [NAME]', "Generate scaffold for new plugin") do |name|
71
76
  @options[:generate_plugin] = name
72
77
  end
@@ -85,6 +90,10 @@ module Crawler
85
90
 
86
91
  opts.on('-l', '--list-plugins', 'List of plugins') do
87
92
  @options[:list_plugins] = true
93
+ end
94
+
95
+ opts.on(nil, '--list-formatters', 'List of formatters available') do
96
+ @options[:list_formatters] = true
88
97
  end
89
98
  end
90
99
  end
@@ -263,6 +272,32 @@ module Crawler
263
272
  register_formatters(dir)
264
273
  end
265
274
 
275
+ # Set default formatter here
276
+ formatter_name = "json"
277
+ if(@options[:formatter])
278
+ formatter_name = @options[:formatter]
279
+ end
280
+
281
+
282
+ # Look for specified formatter
283
+ f = @formatters.select { |k, v|
284
+ k.downcase == formatter_name.downcase
285
+ }
286
+
287
+ if(f)
288
+ @formatter = f[f.keys[0]]
289
+ end
290
+
291
+ if(@options[:list_formatters])
292
+ headings = ['name', 'class']
293
+ rows = @formatters
294
+
295
+ table = Terminal::Table.new :headings => headings, :rows => rows
296
+
297
+ puts table
298
+ return
299
+ end
300
+
266
301
  if(@options[:list_plugins])
267
302
  headings = ['name', 'class']
268
303
  rows = @plugins
@@ -301,8 +336,11 @@ module Crawler
301
336
  next
302
337
  end
303
338
 
304
- puts Apollo::Crawler::Formatters::Json.format(res)
339
+ # puts Apollo::Crawler::Formatters::Json.format(res)
305
340
  # puts Apollo::Crawler::Formatters::Plain.format(res)
341
+ # puts Apollo::Crawler::Formatters::Table.format(res)
342
+
343
+ puts @formatter.format(res)
306
344
  end
307
345
  end
308
346
  end
@@ -5,7 +5,9 @@ require 'apollo_crawler/formatter'
5
5
  require 'apollo_crawler/plugin'
6
6
 
7
7
  # Formatters
8
+ require 'apollo_crawler/formatters/formatter_json'
8
9
  require 'apollo_crawler/formatters/formatter_plain'
10
+ require 'apollo_crawler/formatters/formatter_table'
9
11
 
10
12
  # Plugins
11
13
  require 'apollo_crawler/plugins/alexa_com/alexa'
@@ -7,7 +7,7 @@ module Apollo
7
7
  module Formatters
8
8
  class Json < Formatter
9
9
  def format(obj)
10
- return Plain.format(obj)
10
+ return Json.format(obj)
11
11
  end
12
12
 
13
13
  def self.format(obj)
@@ -0,0 +1,20 @@
1
+ require 'terminal-table'
2
+
3
+ require File.join(File.dirname(__FILE__), '..', 'formatter')
4
+
5
+ module Apollo
6
+ module Crawler
7
+ module Formatters
8
+ class Table < Formatter
9
+ def format(obj)
10
+ return Table.format(obj)
11
+ end
12
+
13
+ def self.format(obj)
14
+ table = Terminal::Table.new :rows => obj[:data]
15
+ return table
16
+ end
17
+ end
18
+ end # Formatters
19
+ end # Crawler
20
+ end # Apollo
@@ -1,5 +1,5 @@
1
1
  module Apollo
2
2
  module Crawler
3
- VERSION = '0.0.41'
3
+ VERSION = '0.0.42'
4
4
  end # Crawler
5
5
  end # Apollo
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apollo-crawler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.41
4
+ version: 0.0.42
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -228,6 +228,7 @@ extra_rdoc_files: []
228
228
  files:
229
229
  - ./lib/apollo_crawler/formatters/formatter_plain.rb
230
230
  - ./lib/apollo_crawler/formatters/formatter_json.rb
231
+ - ./lib/apollo_crawler/formatters/formatter_table.rb
231
232
  - ./lib/apollo_crawler/version.rb
232
233
  - ./lib/apollo_crawler/crawler.rb
233
234
  - ./lib/apollo_crawler/formatter.rb