request-log-analyzer 1.13.1 → 1.13.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/bin/console +17 -0
  4. data/lib/cli/command_line_arguments.rb +29 -36
  5. data/lib/cli/database_console.rb +1 -3
  6. data/lib/cli/database_console_init.rb +11 -11
  7. data/lib/cli/progressbar.rb +30 -32
  8. data/lib/cli/tools.rb +20 -23
  9. data/lib/request_log_analyzer.rb +8 -8
  10. data/lib/request_log_analyzer/aggregator.rb +4 -7
  11. data/lib/request_log_analyzer/aggregator/database_inserter.rb +10 -13
  12. data/lib/request_log_analyzer/aggregator/echo.rb +5 -7
  13. data/lib/request_log_analyzer/aggregator/summarizer.rb +15 -18
  14. data/lib/request_log_analyzer/class_level_inheritable_attributes.rb +23 -0
  15. data/lib/request_log_analyzer/controller.rb +36 -42
  16. data/lib/request_log_analyzer/database.rb +4 -6
  17. data/lib/request_log_analyzer/database/base.rb +39 -41
  18. data/lib/request_log_analyzer/database/connection.rb +8 -10
  19. data/lib/request_log_analyzer/database/request.rb +1 -3
  20. data/lib/request_log_analyzer/database/source.rb +0 -2
  21. data/lib/request_log_analyzer/database/warning.rb +4 -6
  22. data/lib/request_log_analyzer/file_format.rb +46 -49
  23. data/lib/request_log_analyzer/file_format/amazon_s3.rb +15 -19
  24. data/lib/request_log_analyzer/file_format/apache.rb +42 -45
  25. data/lib/request_log_analyzer/file_format/delayed_job.rb +13 -15
  26. data/lib/request_log_analyzer/file_format/delayed_job2.rb +9 -11
  27. data/lib/request_log_analyzer/file_format/delayed_job21.rb +9 -11
  28. data/lib/request_log_analyzer/file_format/delayed_job3.rb +5 -8
  29. data/lib/request_log_analyzer/file_format/delayed_job4.rb +5 -8
  30. data/lib/request_log_analyzer/file_format/haproxy.rb +44 -48
  31. data/lib/request_log_analyzer/file_format/merb.rb +13 -17
  32. data/lib/request_log_analyzer/file_format/mysql.rb +21 -25
  33. data/lib/request_log_analyzer/file_format/nginx.rb +0 -2
  34. data/lib/request_log_analyzer/file_format/oink.rb +30 -31
  35. data/lib/request_log_analyzer/file_format/postgresql.rb +11 -15
  36. data/lib/request_log_analyzer/file_format/rack.rb +0 -2
  37. data/lib/request_log_analyzer/file_format/rails.rb +100 -104
  38. data/lib/request_log_analyzer/file_format/rails3.rb +19 -23
  39. data/lib/request_log_analyzer/file_format/rails_development.rb +0 -1
  40. data/lib/request_log_analyzer/file_format/w3c.rb +16 -18
  41. data/lib/request_log_analyzer/filter.rb +0 -2
  42. data/lib/request_log_analyzer/filter/anonymize.rb +4 -7
  43. data/lib/request_log_analyzer/filter/field.rb +3 -6
  44. data/lib/request_log_analyzer/filter/timespan.rb +2 -6
  45. data/lib/request_log_analyzer/line_definition.rb +16 -19
  46. data/lib/request_log_analyzer/log_processor.rb +10 -14
  47. data/lib/request_log_analyzer/mailer.rb +9 -12
  48. data/lib/request_log_analyzer/output.rb +12 -14
  49. data/lib/request_log_analyzer/output/fixed_width.rb +21 -28
  50. data/lib/request_log_analyzer/output/html.rb +11 -14
  51. data/lib/request_log_analyzer/request.rb +53 -33
  52. data/lib/request_log_analyzer/source.rb +2 -5
  53. data/lib/request_log_analyzer/source/log_parser.rb +9 -16
  54. data/lib/request_log_analyzer/tracker.rb +10 -12
  55. data/lib/request_log_analyzer/tracker/duration.rb +4 -6
  56. data/lib/request_log_analyzer/tracker/frequency.rb +9 -11
  57. data/lib/request_log_analyzer/tracker/hourly_spread.rb +8 -11
  58. data/lib/request_log_analyzer/tracker/numeric_value.rb +40 -44
  59. data/lib/request_log_analyzer/tracker/timespan.rb +5 -8
  60. data/lib/request_log_analyzer/tracker/traffic.rb +8 -10
  61. data/lib/request_log_analyzer/version.rb +1 -1
  62. data/request-log-analyzer.gemspec +6 -6
  63. data/spec/integration/command_line_usage_spec.rb +33 -33
  64. data/spec/integration/mailer_spec.rb +181 -185
  65. data/spec/integration/munin_plugins_rails_spec.rb +20 -20
  66. data/spec/integration/scout_spec.rb +40 -41
  67. data/spec/lib/helpers.rb +8 -9
  68. data/spec/lib/macros.rb +2 -4
  69. data/spec/lib/matchers.rb +20 -25
  70. data/spec/lib/mocks.rb +10 -11
  71. data/spec/lib/testing_format.rb +8 -10
  72. data/spec/spec_helper.rb +5 -1
  73. data/spec/unit/aggregator/database_inserter_spec.rb +23 -23
  74. data/spec/unit/aggregator/summarizer_spec.rb +7 -7
  75. data/spec/unit/controller/controller_spec.rb +14 -14
  76. data/spec/unit/controller/log_processor_spec.rb +3 -3
  77. data/spec/unit/database/base_class_spec.rb +36 -37
  78. data/spec/unit/database/connection_spec.rb +10 -10
  79. data/spec/unit/database/database_spec.rb +11 -11
  80. data/spec/unit/file_format/amazon_s3_format_spec.rb +66 -62
  81. data/spec/unit/file_format/apache_format_spec.rb +57 -52
  82. data/spec/unit/file_format/common_regular_expressions_spec.rb +18 -21
  83. data/spec/unit/file_format/delayed_job21_format_spec.rb +22 -16
  84. data/spec/unit/file_format/delayed_job2_format_spec.rb +22 -16
  85. data/spec/unit/file_format/delayed_job3_format_spec.rb +14 -10
  86. data/spec/unit/file_format/delayed_job4_format_spec.rb +14 -10
  87. data/spec/unit/file_format/delayed_job_format_spec.rb +12 -12
  88. data/spec/unit/file_format/file_format_api_spec.rb +19 -19
  89. data/spec/unit/file_format/format_autodetection_spec.rb +7 -7
  90. data/spec/unit/file_format/haproxy_format_spec.rb +53 -49
  91. data/spec/unit/file_format/inheritance_spec.rb +13 -0
  92. data/spec/unit/file_format/line_definition_spec.rb +35 -33
  93. data/spec/unit/file_format/merb_format_spec.rb +13 -11
  94. data/spec/unit/file_format/mysql_format_spec.rb +24 -24
  95. data/spec/unit/file_format/oink_format_spec.rb +29 -29
  96. data/spec/unit/file_format/postgresql_format_spec.rb +9 -9
  97. data/spec/unit/file_format/rack_format_spec.rb +36 -31
  98. data/spec/unit/file_format/rails3_format_spec.rb +46 -46
  99. data/spec/unit/file_format/rails_format_spec.rb +52 -53
  100. data/spec/unit/file_format/w3c_format_spec.rb +27 -24
  101. data/spec/unit/filter/anonymize_filter_spec.rb +7 -7
  102. data/spec/unit/filter/field_filter_spec.rb +26 -26
  103. data/spec/unit/filter/filter_spec.rb +4 -4
  104. data/spec/unit/filter/timespan_filter_spec.rb +22 -22
  105. data/spec/unit/mailer_spec.rb +21 -21
  106. data/spec/unit/request_spec.rb +29 -29
  107. data/spec/unit/source/log_parser_spec.rb +5 -5
  108. data/spec/unit/tracker/duration_tracker_spec.rb +23 -23
  109. data/spec/unit/tracker/frequency_tracker_spec.rb +29 -30
  110. data/spec/unit/tracker/hourly_spread_spec.rb +35 -35
  111. data/spec/unit/tracker/numeric_value_tracker_spec.rb +71 -72
  112. data/spec/unit/tracker/timespan_tracker_spec.rb +31 -31
  113. data/spec/unit/tracker/tracker_api_spec.rb +43 -44
  114. data/spec/unit/tracker/traffic_tracker_spec.rb +7 -7
  115. metadata +38 -35
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c24635e41e1a2f3e4c11e6f4814cd9381b0d5073
4
- data.tar.gz: 0b70d1e886d4a1ca41361023aee81d7d63acb1fa
3
+ metadata.gz: 91a5bda268facff9ef6d7ddb5ae9d4eec33a8d5c
4
+ data.tar.gz: f3683a5a70afba9f695016d304f91dfa7372b150
5
5
  SHA512:
6
- metadata.gz: 605898a6b50c9e528c3807e92a3fa98effdd7ddbcb85391312e15f30e101612e10f0c6710891b1804d94aa25cc5a99cbd37fd90dcad7da0c91d400e89822b3da
7
- data.tar.gz: e617b1756392fe884a0355e06281302d32c6899832482e4f750b237dae34e75763e702b1bc500d6a297a25591dabfa1a1859569ed417cab48ef008a37dc74776
6
+ metadata.gz: e582a48f76e38c28312077176975f7f83369b49152edbd741db1abc0636d518c520bd6471efe30e6a8a8313c3f7ab6b54cf9fadd240101345644bca804fba089
7
+ data.tar.gz: 3a9fb94f97e219dd3346d30d3da6361c329b5d4310f8e68eb8982d47a73093a9d729ed5b298fa00767b67aea38e4f65922f4a374f137b00e98717f67c3ee1b1f
data/.gitignore CHANGED
@@ -13,3 +13,4 @@ Gemfile.lock
13
13
  /.bundle/
14
14
  *.rbc
15
15
  _site/
16
+ .idea
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- encoding : utf-8 -*-
3
+ $LOAD_PATH.unshift(File.expand_path('./../lib', File.dirname(__FILE__)))
4
+ #noinspection RubyResolve
5
+ require 'request_log_analyzer'
6
+ require 'irb'
7
+ require 'pp'
8
+
9
+ if __FILE__ == $0
10
+ IRB.start(__FILE__)
11
+ else # check -e option
12
+ if /\A-e\z/ =~ $0
13
+ IRB.start(__FILE__)
14
+ else
15
+ IRB.setup(__FILE__)
16
+ end
17
+ end
@@ -1,7 +1,5 @@
1
1
  module CommandLine
2
-
3
2
  class Option
4
-
5
3
  attr_reader :name, :alias
6
4
  attr_reader :parameter_count
7
5
  attr_reader :default_value
@@ -18,7 +16,7 @@ module CommandLine
18
16
  def initialize(name, definition = {})
19
17
  @name = CommandLine::Option.rewrite(name)
20
18
  @alias = definition[:alias] ? definition[:alias].to_sym : nil
21
- @required = definition.has_key?(:required) && definition[:required] == true
19
+ @required = definition.key?(:required) && definition[:required] == true
22
20
  @parameter_count = definition[:parameters] || 1
23
21
  @multiple = definition[:multiple] || false
24
22
  @default_value = definition[:default] || false
@@ -29,7 +27,7 @@ module CommandLine
29
27
  return true
30
28
  elsif @parameter_count == 1
31
29
  parameter = arguments_parser.next_parameter
32
- raise CommandLine::ParameterExpected, self if parameter.nil?
30
+ fail CommandLine::ParameterExpected, self if parameter.nil?
33
31
  return parameter
34
32
  elsif @parameter_count == :any
35
33
  parameters = []
@@ -39,9 +37,9 @@ module CommandLine
39
37
  return parameters
40
38
  else
41
39
  parameters = []
42
- @parameter_count.times do |n|
40
+ @parameter_count.times do |_n|
43
41
  parameter = arguments_parser.next_parameter
44
- raise CommandLine::ParameterExpected, self if parameter.nil?
42
+ fail CommandLine::ParameterExpected, self if parameter.nil?
45
43
  parameters << parameter
46
44
  end
47
45
  return parameters
@@ -87,10 +85,8 @@ module CommandLine
87
85
  end
88
86
 
89
87
  class Arguments
90
-
91
88
  class Definition
92
-
93
- ENDLESS_PARAMETERS = 99999
89
+ ENDLESS_PARAMETERS = 99_999
94
90
 
95
91
  attr_reader :commands, :options, :parameters
96
92
 
@@ -103,10 +99,10 @@ module CommandLine
103
99
 
104
100
  def [](option_name)
105
101
  option_symbol = CommandLine::Option.rewrite(option_name)
106
- if the_option = @options.detect { |(_, odef)| odef =~ option_symbol }
102
+ if the_option = @options.find { |(_, odef)| odef =~ option_symbol }
107
103
  the_option[1]
108
104
  else
109
- raise CommandLine::UnknownOption, option_name
105
+ fail CommandLine::UnknownOption, option_name
110
106
  end
111
107
  end
112
108
 
@@ -114,11 +110,9 @@ module CommandLine
114
110
  @parameters = count_specifier..ENDLESS_PARAMETERS
115
111
  end
116
112
 
117
- def parameters=(count_specifier)
118
- @parameters = count_specifier
119
- end
113
+ attr_writer :parameters
120
114
 
121
- alias :files= :parameters=
115
+ alias_method :files=, :parameters=
122
116
 
123
117
  def option(name, options = {})
124
118
  clo = CommandLine::Option.new(name, options)
@@ -126,10 +120,10 @@ module CommandLine
126
120
  end
127
121
 
128
122
  def switch(name, switch_alias = nil)
129
- option(name, :alias => switch_alias, :parameters => 0)
123
+ option(name, alias: switch_alias, parameters: 0)
130
124
  end
131
125
 
132
- def command(name, &block)
126
+ def command(name, &_block)
133
127
  command_definition = Definition.new(self)
134
128
  yield(command_definition) if block_given?
135
129
  @commands[CommandLine::Option.rewrite(name)] = command_definition
@@ -140,7 +134,7 @@ module CommandLine
140
134
  end
141
135
  end
142
136
 
143
- OPTION_REGEXP = /^\-\-([A-Za-z0-9-]+)$/;
137
+ OPTION_REGEXP = /^\-\-([A-Za-z0-9-]+)$/
144
138
  ALIASES_REGEXP = /^\-([A-Aa-z0-9]+)$/
145
139
 
146
140
  attr_reader :definition
@@ -150,7 +144,7 @@ module CommandLine
150
144
  def self.parse(tokens = $*, &block)
151
145
  cla = Arguments.new
152
146
  cla.define(&block)
153
- return cla.parse!(tokens)
147
+ cla.parse!(tokens)
154
148
  end
155
149
 
156
150
  def initialize
@@ -159,12 +153,12 @@ module CommandLine
159
153
  @current_definition = @definition
160
154
  end
161
155
 
162
- def define(&block)
156
+ def define(&_block)
163
157
  yield(@definition)
164
158
  end
165
159
 
166
160
  def [](option)
167
- if the_option = @options.detect { |(key, _)| key =~ option }
161
+ if the_option = @options.find { |(key, _)| key =~ option }
168
162
  the_option[1]
169
163
  else
170
164
  @current_definition[option].default_value
@@ -173,13 +167,13 @@ module CommandLine
173
167
 
174
168
  def next_token
175
169
  @current_token = @tokens.shift
176
- return @current_token
170
+ @current_token
177
171
  end
178
172
 
179
173
  def next_parameter
180
174
  parameter_candidate = @tokens.first
181
175
  parameter = (parameter_candidate.nil? || OPTION_REGEXP =~ parameter_candidate || ALIASES_REGEXP =~ parameter_candidate) ? nil : @tokens.shift
182
- return parameter
176
+ parameter
183
177
  end
184
178
 
185
179
  def parse!(tokens)
@@ -200,8 +194,8 @@ module CommandLine
200
194
  @command = CommandLine::Option.rewrite(@current_token)
201
195
  else
202
196
  case @current_token
203
- when ALIASES_REGEXP; handle_alias_expansion($1)
204
- when OPTION_REGEXP; handle_option($1)
197
+ when ALIASES_REGEXP then handle_alias_expansion(Regexp.last_match[1])
198
+ when OPTION_REGEXP then handle_option(Regexp.last_match[1])
205
199
  else; handle_other_parameter(@current_token)
206
200
  end
207
201
  @first_token = false
@@ -211,24 +205,24 @@ module CommandLine
211
205
 
212
206
  validate_arguments!
213
207
 
214
- return self
208
+ self
215
209
  end
216
210
 
217
211
  protected
218
212
 
219
213
  def prepare_result!
220
- multiple_options = Hash[*@current_definition.options.select { |name, o| o.multiple? }.flatten]
221
- multiple_options.each { |name, definition| @options[definition] = [] }
214
+ multiple_options = Hash[*@current_definition.options.select { |_name, o| o.multiple? }.flatten]
215
+ multiple_options.each { |_name, definition| @options[definition] = [] }
222
216
  end
223
217
 
224
218
  def validate_arguments!
225
219
  if @current_definition.parameters && !(@current_definition.parameters === @parameters.length)
226
- raise CommandLine::ParametersOutOfRange.new(@current_definition.parameters, @parameters.length)
220
+ fail CommandLine::ParametersOutOfRange.new(@current_definition.parameters, @parameters.length)
227
221
  end
228
222
 
229
- required_options = Hash[*@current_definition.options.select { |name, o| o.required? }.flatten]
223
+ required_options = Hash[*@current_definition.options.select { |_name, o| o.required? }.flatten]
230
224
  required_options.each do |name, definition|
231
- raise CommandLine::RequiredOptionMissing, definition unless self[name]
225
+ fail CommandLine::RequiredOptionMissing, definition unless self[name]
232
226
  end
233
227
  end
234
228
 
@@ -237,7 +231,7 @@ module CommandLine
237
231
  if option_definition = @current_definition[alias_char]
238
232
  @tokens.unshift(option_definition.to_option)
239
233
  else
240
- raise CommandLine::UnknownOption, alias_char
234
+ fail CommandLine::UnknownOption, alias_char
241
235
  end
242
236
  end
243
237
  end
@@ -248,7 +242,7 @@ module CommandLine
248
242
 
249
243
  def handle_option(option_name)
250
244
  option_definition = @current_definition[option_name]
251
- raise CommandLine::UnknownOption, option_name if option_definition.nil?
245
+ fail CommandLine::UnknownOption, option_name if option_definition.nil?
252
246
 
253
247
  if option_definition.multiple?
254
248
  @options[option_definition] << option_definition.parse(self)
@@ -256,7 +250,6 @@ module CommandLine
256
250
  @options[option_definition] = option_definition.parse(self)
257
251
  end
258
252
  end
259
-
260
253
  end
261
254
 
262
255
  # Commandline parsing errors and exceptions
@@ -273,7 +266,7 @@ module CommandLine
273
266
  # Missing a required file
274
267
  class ParametersOutOfRange < CommandLine::Error
275
268
  def initialize(expected, actual)
276
- if expected.kind_of?(Range)
269
+ if expected.is_a?(Range)
277
270
  if expected.end == CommandLine::Arguments::Definition::ENDLESS_PARAMETERS
278
271
  super("The command expected at least #{expected.begin} parameters, but found #{actual}!")
279
272
  else
@@ -298,4 +291,4 @@ module CommandLine
298
291
  super("#{option_identifier.inspect} not recognized as a valid option!")
299
292
  end
300
293
  end
301
- end
294
+ end
@@ -1,5 +1,4 @@
1
1
  class DatabaseConsole
2
-
3
2
  IRB = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
3
 
5
4
  def initialize(arguments)
@@ -7,7 +6,7 @@ class DatabaseConsole
7
6
  end
8
7
 
9
8
  def run!
10
- libraries = ['irb/completion', 'rubygems','cli/database_console_init']
9
+ libraries = ['irb/completion', 'rubygems', 'cli/database_console_init']
11
10
  libaries_string = libraries.map { |l| "-r #{l}" }.join(' ')
12
11
 
13
12
  ENV['RLA_DBCONSOLE_DATABASE'] = @arguments[:database]
@@ -22,4 +21,3 @@ class DatabaseConsole
22
21
  exec("#{IRB} #{libaries_string} --simple-prompt")
23
22
  end
24
23
  end
25
-
@@ -1,5 +1,5 @@
1
1
  # Setup the include path
2
- $:.unshift(File.expand_path('..', File.dirname(__FILE__)))
2
+ $LOAD_PATH.unshift(File.expand_path('..', File.dirname(__FILE__)))
3
3
  require 'request_log_analyzer'
4
4
  require 'request_log_analyzer/database'
5
5
 
@@ -9,9 +9,9 @@ $database.register_default_orm_classes!
9
9
 
10
10
  require 'cli/tools'
11
11
 
12
- def wordwrap(string, max = 80, indent = "")
13
- strings = [""]
14
- string.split(", ").each do |item|
12
+ def wordwrap(string, max = 80, indent = '')
13
+ strings = ['']
14
+ string.split(', ').each do |item|
15
15
  if strings.last.length == 0 || strings.last.length + item.length <= max
16
16
  strings.last << item << ', '
17
17
  else
@@ -28,9 +28,9 @@ class Request
28
28
 
29
29
  inspected_lines = lines.map do |line|
30
30
  inspect_line = " - #{line.line_type} (line #{line.lineno})"
31
- if (inspect_attributes = line.attributes.reject { |(k, v)| [:id, :source_id, :request_id, :lineno].include?(k.to_sym) }).any?
32
- inspect_attributes = inspect_attributes.map { |(k,v)| "#{k} = #{v.inspect}" }.join(', ')
33
- inspect_line << "\n " + wordwrap(inspect_attributes, CommandLine::Tools.terminal_width - 6, " ")
31
+ if (inspect_attributes = line.attributes.reject { |(k, _v)| [:id, :source_id, :request_id, :lineno].include?(k.to_sym) }).any?
32
+ inspect_attributes = inspect_attributes.map { |(k, v)| "#{k} = #{v.inspect}" }.join(', ')
33
+ inspect_line << "\n " + wordwrap(inspect_attributes, CommandLine::Tools.terminal_width - 6, ' ')
34
34
  end
35
35
  inspect_line
36
36
  end
@@ -39,7 +39,7 @@ class Request
39
39
  end
40
40
  end
41
41
 
42
- puts "request-log-analyzer database console"
43
- puts "-------------------------------------"
44
- puts "The following ActiveRecord classes are available:"
45
- puts $database.orm_classes.map { |k| k.name.split('::').last }.join(", ")
42
+ puts 'request-log-analyzer database console'
43
+ puts '-------------------------------------'
44
+ puts 'The following ActiveRecord classes are available:'
45
+ puts $database.orm_classes.map { |k| k.name.split('::').last }.join(', ')
@@ -10,9 +10,9 @@
10
10
 
11
11
  module CommandLine
12
12
  class ProgressBar
13
- VERSION = "0.9"
13
+ VERSION = '0.9'
14
14
 
15
- def initialize (title, total, out = STDERR)
15
+ def initialize(title, total, out = STDERR)
16
16
  @title = title
17
17
  @total = total
18
18
  @out = out
@@ -30,17 +30,18 @@ module CommandLine
30
30
  show
31
31
  end
32
32
 
33
- attr_reader :title
34
- attr_reader :current
35
- attr_reader :total
33
+ attr_reader :title
34
+ attr_reader :current
35
+ attr_reader :total
36
36
  attr_accessor :start_time
37
37
 
38
38
  private
39
+
39
40
  def fmt_bar
40
41
  bar_width = do_percentage * @terminal_width / 100
41
- sprintf("[%s%s]",
42
+ sprintf('[%s%s]',
42
43
  @bar_mark * bar_width,
43
- " " * (@terminal_width - bar_width))
44
+ ' ' * (@terminal_width - bar_width))
44
45
  end
45
46
 
46
47
  def fmt_percentage
@@ -53,59 +54,59 @@ module CommandLine
53
54
 
54
55
  def fmt_stat_for_file_transfer
55
56
  if @finished_p then
56
- sprintf("%s %s %s", bytes, transfer_rate, elapsed)
57
+ sprintf('%s %s %s', bytes, transfer_rate, elapsed)
57
58
  else
58
- sprintf("%s %s %s", bytes, transfer_rate, eta)
59
+ sprintf('%s %s %s', bytes, transfer_rate, eta)
59
60
  end
60
61
  end
61
62
 
62
63
  def fmt_title
63
- @title[0,(@title_width - 1)] + ":"
64
+ @title[0, (@title_width - 1)] + ':'
64
65
  end
65
66
 
66
- def convert_bytes (bytes)
67
+ def convert_bytes(bytes)
67
68
  if bytes < 1024
68
- sprintf("%6dB", bytes)
69
+ sprintf('%6dB', bytes)
69
70
  elsif bytes < 1024 * 1000 # 1000kb
70
- sprintf("%5.1fKB", bytes.to_f / 1024)
71
+ sprintf('%5.1fKB', bytes.to_f / 1024)
71
72
  elsif bytes < 1024 * 1024 * 1000 # 1000mb
72
- sprintf("%5.1fMB", bytes.to_f / 1024 / 1024)
73
+ sprintf('%5.1fMB', bytes.to_f / 1024 / 1024)
73
74
  else
74
- sprintf("%5.1fGB", bytes.to_f / 1024 / 1024 / 1024)
75
+ sprintf('%5.1fGB', bytes.to_f / 1024 / 1024 / 1024)
75
76
  end
76
77
  end
77
78
 
78
79
  def transfer_rate
79
80
  bytes_per_second = @current.to_f / (Time.now - @start_time)
80
- sprintf("%s/s", convert_bytes(bytes_per_second))
81
+ sprintf('%s/s', convert_bytes(bytes_per_second))
81
82
  end
82
83
 
83
84
  def bytes
84
85
  convert_bytes(@current)
85
86
  end
86
87
 
87
- def format_time (t)
88
+ def format_time(t)
88
89
  t = t.to_i
89
90
  sec = t % 60
90
91
  min = (t / 60) % 60
91
92
  hour = t / 3600
92
- sprintf("%02d:%02d:%02d", hour, min, sec);
93
+ sprintf('%02d:%02d:%02d', hour, min, sec)
93
94
  end
94
95
 
95
96
  # ETA stands for Estimated Time of Arrival.
96
97
  def eta
97
98
  if @current == 0
98
- "ETA: --:--:--"
99
+ 'ETA: --:--:--'
99
100
  else
100
101
  elapsed = Time.now - @start_time
101
- eta = elapsed * @total / @current - elapsed;
102
- sprintf("ETA: %s", format_time(eta))
102
+ eta = elapsed * @total / @current - elapsed
103
+ sprintf('ETA: %s', format_time(eta))
103
104
  end
104
105
  end
105
106
 
106
107
  def elapsed
107
108
  elapsed = Time.now - @start_time
108
- sprintf("Time: %s", format_time(elapsed))
109
+ sprintf('Time: %s', format_time(elapsed))
109
110
  end
110
111
 
111
112
  def eol
@@ -122,7 +123,7 @@ module CommandLine
122
123
 
123
124
  def show
124
125
  arguments = @format_arguments.map do |method|
125
- method = sprintf("fmt_%s", method)
126
+ method = sprintf('fmt_%s', method)
126
127
  send(method)
127
128
  end
128
129
  line = sprintf(@format, *arguments)
@@ -158,9 +159,10 @@ module CommandLine
158
159
  end
159
160
 
160
161
  public
162
+
161
163
  def clear
162
164
  @out.print "\r"
163
- @out.print(" " * (CommandLine::Tools.terminal_width(80) - 1))
165
+ @out.print(' ' * (CommandLine::Tools.terminal_width(80) - 1))
164
166
  @out.print "\r"
165
167
  end
166
168
 
@@ -178,27 +180,23 @@ module CommandLine
178
180
  @format_arguments = [:title, :percentage, :bar, :stat_for_file_transfer]
179
181
  end
180
182
 
181
- def format= (format)
182
- @format = format
183
- end
183
+ attr_writer :format
184
184
 
185
- def format_arguments= (arguments)
186
- @format_arguments = arguments
187
- end
185
+ attr_writer :format_arguments
188
186
 
189
187
  def halt
190
188
  @finished_p = true
191
189
  show
192
190
  end
193
191
 
194
- def inc (step = 1)
192
+ def inc(step = 1)
195
193
  @current += step
196
194
  @current = @total if @current > @total
197
195
  show_if_needed
198
196
  @previous = @current
199
197
  end
200
198
 
201
- def set (count)
199
+ def set(count)
202
200
  count = 0 if count < 0
203
201
  count = @total if count > @total
204
202