Class: Ggggsss::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/ggggsss.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Command

Returns a new instance of Command.



10
11
12
13
14
15
16
17
18
# File 'lib/ggggsss.rb', line 10

def initialize(args)
  @bucket_name = ''
  opt_parser = OptionParser.new
  opt_parser.on('-b BUCKET_NAME', '--bucket-name BUCKET_NAME') {|name| @bucket_name = name }

  opt_parser.parse!(args)

  @keyword, @path = *args
end

Instance Attribute Details

#bucket_nameObject (readonly)

Returns the value of attribute bucket_name.



8
9
10
# File 'lib/ggggsss.rb', line 8

def bucket_name
  @bucket_name
end

#keywordObject (readonly)

Returns the value of attribute keyword.



8
9
10
# File 'lib/ggggsss.rb', line 8

def keyword
  @keyword
end

#pathObject (readonly)

Returns the value of attribute path.



8
9
10
# File 'lib/ggggsss.rb', line 8

def path
  @path
end

Instance Method Details

#execute!Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ggggsss.rb', line 20

def execute!
  fetcher = S3Fetcher.new(@bucket_name, @path)
  fetcher.fetch!

  fetcher.objects.each do |s3_object|
    collector = LineCollector.new(s3_object.body, @keyword)
    collector.collect!

    printer = ResultPrinter.new(s3_object.key, collector.results)
    printer.print
  rescue => e
    puts "#{s3_object.key}: #{e.message}"
  end
end