vnstat-ruby 1.1.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +49 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +7 -5
  6. data/Gemfile +4 -10
  7. data/Gemfile.lock +29 -75
  8. data/LICENSE.txt +18 -17
  9. data/README.md +1 -3
  10. data/Rakefile +4 -25
  11. data/lib/vnstat-ruby.rb +2 -0
  12. data/lib/vnstat.rb +17 -2
  13. data/lib/vnstat/configuration.rb +4 -2
  14. data/lib/vnstat/document.rb +6 -1
  15. data/lib/vnstat/error.rb +2 -0
  16. data/lib/vnstat/errors/executable_not_found.rb +2 -0
  17. data/lib/vnstat/errors/unknown_interface.rb +2 -0
  18. data/lib/vnstat/interface.rb +4 -1
  19. data/lib/vnstat/interface_collection.rb +2 -0
  20. data/lib/vnstat/parser.rb +4 -2
  21. data/lib/vnstat/result.rb +8 -5
  22. data/lib/vnstat/result/date_delegation.rb +2 -0
  23. data/lib/vnstat/result/day.rb +4 -1
  24. data/lib/vnstat/result/hour.rb +6 -2
  25. data/lib/vnstat/result/minute.rb +5 -2
  26. data/lib/vnstat/result/month.rb +6 -2
  27. data/lib/vnstat/result/time_comparable.rb +2 -0
  28. data/lib/vnstat/system_call.rb +10 -7
  29. data/lib/vnstat/traffic.rb +2 -0
  30. data/lib/vnstat/traffic/base.rb +2 -0
  31. data/lib/vnstat/traffic/daily.rb +2 -0
  32. data/lib/vnstat/traffic/hourly.rb +2 -0
  33. data/lib/vnstat/traffic/monthly.rb +2 -0
  34. data/lib/vnstat/traffic/tops.rb +2 -0
  35. data/lib/vnstat/utils.rb +2 -0
  36. data/lib/vnstat/version.rb +5 -0
  37. data/vnstat-ruby.gemspec +36 -109
  38. metadata +27 -65
  39. data/.codeclimate.yml +0 -14
  40. data/spec/lib/vnstat/configuration_spec.rb +0 -72
  41. data/spec/lib/vnstat/document_spec.rb +0 -54
  42. data/spec/lib/vnstat/errors/executable_not_found_spec.rb +0 -5
  43. data/spec/lib/vnstat/errors/unknown_interface_spec.rb +0 -5
  44. data/spec/lib/vnstat/interface_collection_spec.rb +0 -194
  45. data/spec/lib/vnstat/interface_spec.rb +0 -327
  46. data/spec/lib/vnstat/result/day_spec.rb +0 -39
  47. data/spec/lib/vnstat/result/hour_spec.rb +0 -43
  48. data/spec/lib/vnstat/result/minute_spec.rb +0 -54
  49. data/spec/lib/vnstat/result/month_spec.rb +0 -39
  50. data/spec/lib/vnstat/result_spec.rb +0 -86
  51. data/spec/lib/vnstat/system_call_spec.rb +0 -209
  52. data/spec/lib/vnstat/traffic/daily_spec.rb +0 -109
  53. data/spec/lib/vnstat/traffic/hourly_spec.rb +0 -153
  54. data/spec/lib/vnstat/traffic/monthly_spec.rb +0 -46
  55. data/spec/lib/vnstat/traffic/tops_spec.rb +0 -48
  56. data/spec/lib/vnstat/utils_spec.rb +0 -130
  57. data/spec/lib/vnstat_spec.rb +0 -61
  58. data/spec/spec_helper.rb +0 -98
  59. data/spec/support/shared_examples/shared_examples_for_date_delegation.rb +0 -19
  60. data/spec/support/shared_examples/shared_examples_for_traffic_collection.rb +0 -19
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: '09d872127c5d9034c7a218a15337d658e921bd2a'
4
- data.tar.gz: 5016a6c59ca8e17b23d24da2f678c9de07088b2b
2
+ SHA256:
3
+ metadata.gz: 1147fd1dc7aa2c9d3990b48e410a1a2f68e8ecd3e5dfc390116131f703050624
4
+ data.tar.gz: 5804a8055fc72e8f5dd9fefe888072524ebd8ee842fa26194b45130106dbc170
5
5
  SHA512:
6
- metadata.gz: ddb82f9aa3612a655f0de2960e1d9d165e5abdb7cff76d4b48de780e29e09a4ecca03c6eb5cf06de060db30a6eaa1166d7931c52c79a8618abd25321eeb383df
7
- data.tar.gz: e90d226876389a9f23251279ffd632cd7840d735012de903eb065987dfc8ce57f9b6716321bbb89cc4d838971a8def23e2055908b51f35cd05596d9bfa7e8d5e
6
+ metadata.gz: 9e2be0b328f5b8df0dea239b8c2554d812afc439c89798844fe80dc2edf4fb5f1841ffd1036c3470763fca10a2cc21d90a816043030e89bd250edf3151f3ccb6
7
+ data.tar.gz: b163535f90d28910ec626e7d3e997c426addb363dfa50b242f5d0a384b0e9b92ceeeadc000a3d4a1d3af52934125b0ecaab6b6409b7b088448c0f810713f1861
@@ -0,0 +1,49 @@
1
+ # rcov generated
2
+ coverage
3
+ coverage.data
4
+
5
+ # rdoc generated
6
+ rdoc
7
+
8
+ # yard generated
9
+ doc
10
+ .yardoc
11
+
12
+ # bundler
13
+ .bundle
14
+
15
+ # jeweler generated
16
+ pkg
17
+
18
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
19
+ #
20
+ # * Create a file at ~/.gitignore
21
+ # * Include files you want ignored
22
+ # * Run: git config --global core.excludesfile ~/.gitignore
23
+ #
24
+ # After doing this, these files will be ignored in all your git projects,
25
+ # saving you from having to 'pollute' every project you touch with them
26
+ #
27
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
28
+ #
29
+ # For MacOS:
30
+ #
31
+ #.DS_Store
32
+
33
+ # For TextMate
34
+ #*.tmproj
35
+ #tmtags
36
+
37
+ # For emacs:
38
+ #*~
39
+ #\#*
40
+ #.\#*
41
+
42
+ # For vim:
43
+ #*.swp
44
+
45
+ # For redcar:
46
+ #.redcar
47
+
48
+ # For rubinius:
49
+ #*.rbc
@@ -0,0 +1 @@
1
+ vnstat-ruby
@@ -0,0 +1 @@
1
+ 2.5.0
@@ -1,10 +1,12 @@
1
+ sudo: false
1
2
  language: ruby
2
3
  rvm:
3
- - '2.0.0'
4
- - '2.1.7'
5
- - '2.2.3'
6
- - '2.3.1'
7
- - '2.4.1'
4
+ - '2.1.10'
5
+ - '2.2.8'
6
+ - '2.3.6'
7
+ - '2.4.3'
8
+ - '2.5.0'
9
+ before_install: gem install bundler -v 1.14.6
8
10
  script: bundle exec rspec
9
11
  addons:
10
12
  code_climate:
data/Gemfile CHANGED
@@ -1,12 +1,6 @@
1
- source 'http://rubygems.org'
1
+ # frozen_string_literal: true
2
2
 
3
- gem 'nokogiri', '~> 1.6'
3
+ source 'https://rubygems.org'
4
4
 
5
- group :development do
6
- gem 'bundler', '~> 1.0'
7
- gem 'codeclimate-test-reporter', '0.6.0', require: false
8
- gem 'jeweler', '~> 2.0', '>= 2.0.1'
9
- gem 'rspec', '~> 3.0'
10
- gem 'rubocop', '~> 0'
11
- gem 'yard', '~> 0'
12
- end
5
+ # Specify your gem's dependencies in vnstat-ruby.gemspec
6
+ gemspec
@@ -1,62 +1,23 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ vnstat-ruby (2.0.0)
5
+ nokogiri (~> 1.8)
6
+
1
7
  GEM
2
- remote: http://rubygems.org/
8
+ remote: https://rubygems.org/
3
9
  specs:
4
- addressable (2.5.1)
5
- public_suffix (~> 2.0, >= 2.0.2)
6
- ast (2.3.0)
7
- builder (3.2.3)
8
- codeclimate-test-reporter (0.6.0)
9
- simplecov (>= 0.7.1, < 1.0.0)
10
- descendants_tracker (0.0.4)
11
- thread_safe (~> 0.3, >= 0.3.1)
10
+ ast (2.4.0)
12
11
  diff-lcs (1.2.5)
13
- docile (1.1.5)
14
- faraday (0.9.2)
15
- multipart-post (>= 1.2, < 3)
16
- git (1.3.0)
17
- github_api (0.11.3)
18
- addressable (~> 2.3)
19
- descendants_tracker (~> 0.0.1)
20
- faraday (~> 0.8, < 0.10)
21
- hashie (>= 1.2)
22
- multi_json (>= 1.7.5, < 2.0)
23
- nokogiri (~> 1.6.0)
24
- oauth2
25
- hashie (3.5.5)
26
- highline (1.7.8)
27
- jeweler (2.1.2)
28
- builder
29
- bundler (>= 1.0)
30
- git (>= 1.2.5)
31
- github_api (~> 0.11.0)
32
- highline (>= 1.6.15)
33
- nokogiri (>= 1.5.10)
34
- rake
35
- rdoc
36
- semver
37
- json (2.1.0)
38
- jwt (1.5.6)
39
- mini_portile2 (2.1.0)
40
- multi_json (1.12.1)
41
- multi_xml (0.6.0)
42
- multipart-post (2.0.0)
43
- nokogiri (1.6.8.1)
44
- mini_portile2 (~> 2.1.0)
45
- oauth2 (1.3.1)
46
- faraday (>= 0.8, < 0.12)
47
- jwt (~> 1.0)
48
- multi_json (~> 1.3)
49
- multi_xml (~> 0.5)
50
- rack (>= 1.2, < 3)
51
- parser (2.4.0.0)
52
- ast (~> 2.2)
12
+ mini_portile2 (2.3.0)
13
+ nokogiri (1.8.2)
14
+ mini_portile2 (~> 2.3.0)
15
+ parallel (1.12.1)
16
+ parser (2.5.0.4)
17
+ ast (~> 2.4.0)
53
18
  powerpack (0.1.1)
54
- public_suffix (2.0.5)
55
- rack (1.6.5)
56
- rainbow (2.2.2)
57
- rake
58
- rake (12.0.0)
59
- rdoc (5.1.0)
19
+ rainbow (3.0.0)
20
+ rake (10.5.0)
60
21
  rspec (3.3.0)
61
22
  rspec-core (~> 3.3.0)
62
23
  rspec-expectations (~> 3.3.0)
@@ -70,34 +31,27 @@ GEM
70
31
  diff-lcs (>= 1.2.0, < 2.0)
71
32
  rspec-support (~> 3.3.0)
72
33
  rspec-support (3.3.0)
73
- rubocop (0.48.1)
74
- parser (>= 2.3.3.1, < 3.0)
34
+ rubocop (0.53.0)
35
+ parallel (~> 1.10)
36
+ parser (>= 2.5)
75
37
  powerpack (~> 0.1)
76
- rainbow (>= 1.99.1, < 3.0)
38
+ rainbow (>= 2.2.2, < 4.0)
77
39
  ruby-progressbar (~> 1.7)
78
40
  unicode-display_width (~> 1.0, >= 1.0.1)
79
- ruby-progressbar (1.8.1)
80
- semver (1.0.1)
81
- simplecov (0.14.1)
82
- docile (~> 1.1.0)
83
- json (>= 1.8, < 3)
84
- simplecov-html (~> 0.10.0)
85
- simplecov-html (0.10.0)
86
- thread_safe (0.3.6)
87
- unicode-display_width (1.2.1)
88
- yard (0.9.9)
41
+ ruby-progressbar (1.9.0)
42
+ unicode-display_width (1.3.0)
43
+ yard (0.9.12)
89
44
 
90
45
  PLATFORMS
91
46
  ruby
92
47
 
93
48
  DEPENDENCIES
94
- bundler (~> 1.0)
95
- codeclimate-test-reporter (= 0.6.0)
96
- jeweler (~> 2.0, >= 2.0.1)
97
- nokogiri (~> 1.6)
49
+ bundler (~> 1.14)
50
+ rake (~> 10.0)
98
51
  rspec (~> 3.0)
99
- rubocop (~> 0)
100
- yard (~> 0)
52
+ rubocop (~> 0.53)
53
+ vnstat-ruby!
54
+ yard (~> 0.9.12)
101
55
 
102
56
  BUNDLED WITH
103
- 1.14.6
57
+ 1.16.1
@@ -1,20 +1,21 @@
1
- Copyright (c) 2015 Tobias Casper
1
+ The MIT License (MIT)
2
2
 
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
3
+ Copyright (c) 2018 Tobias Casper
10
4
 
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
13
11
 
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -1,7 +1,5 @@
1
1
  # vnstat-ruby
2
2
 
3
- [![Code Climate](https://codeclimate.com/github/tlux/vnstat-ruby/badges/gpa.svg)](https://codeclimate.com/github/tlux/vnstat-ruby)
4
- [![Test Coverage](https://codeclimate.com/github/tlux/vnstat-ruby/badges/coverage.svg)](https://codeclimate.com/github/tlux/vnstat-ruby/coverage)
5
3
  [![Build Status](https://travis-ci.org/tlux/vnstat-ruby.svg?branch=master)](https://travis-ci.org/tlux/vnstat-ruby)
6
4
  [![Gem Version](https://badge.fury.io/rb/vnstat-ruby.svg)](https://badge.fury.io/rb/vnstat-ruby)
7
5
 
@@ -15,7 +13,7 @@ maintained by Teemu Toivola.
15
13
 
16
14
  ### Prerequisites
17
15
 
18
- * Ruby 2.0.0 or greater
16
+ * Ruby 2.1.0 or greater
19
17
  * Make sure you have `vnstat` CLI installed by running `which vnstat`.
20
18
 
21
19
  On Ubuntu you can get the vnstat package via `apt-get install vnstat`.
data/Rakefile CHANGED
@@ -1,27 +1,6 @@
1
- # encoding: utf-8
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
2
3
 
3
- require 'rubygems'
4
- require 'bundler'
5
- begin
6
- Bundler.setup(:default, :development)
7
- rescue Bundler::BundlerError => e
8
- $stderr.puts e.message
9
- $stderr.puts "Run `bundle install` to install missing gems"
10
- exit e.status_code
11
- end
12
- require 'rake'
13
- require 'jeweler'
4
+ RSpec::Core::RakeTask.new(:spec)
14
5
 
15
- Jeweler::Tasks.new do |gem|
16
- # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
17
- gem.name = 'vnstat-ruby'
18
- gem.homepage = 'http://github.com/tlux/vnstat-ruby'
19
- gem.license = 'MIT'
20
- gem.summary = 'A Ruby wrapper for vnstat.'
21
- gem.description = 'Uses the the vnstat CLI to track your network traffic.'
22
- gem.email = 'tobias.casper@gmail.com'
23
- gem.authors = ['Tobias Casper']
24
- # dependencies defined in Gemfile
25
- end
26
-
27
- Jeweler::RubygemsDotOrgTasks.new
6
+ task default: :spec
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'vnstat'
@@ -1,5 +1,9 @@
1
- require 'date'
2
- require 'nokogiri'
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/setup'
4
+ require 'rubygems'
5
+ require 'vnstat/version'
6
+ require 'time'
3
7
 
4
8
  ##
5
9
  # The Vnstat namespace.
@@ -58,8 +62,19 @@ module Vnstat
58
62
  ##
59
63
  # Returns information for the currently installed version of vnstat.
60
64
  #
65
+ # @deprecated Please use {#cli_version} instead.
61
66
  # @return [String]
62
67
  def version
68
+ warn '[DEPRECATION] `Vnstat.version` is deprecated. Please use ' \
69
+ '`Vnstat.cli_version` instead.'
70
+ cli_version
71
+ end
72
+
73
+ ##
74
+ # Returns information for the currently installed version of vnstat.
75
+ #
76
+ # @return [String]
77
+ def cli_version
63
78
  Utils.call_executable('-v')
64
79
  end
65
80
  end
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Vnstat
2
4
  ##
3
5
  # A class encapsulating configurations of the Vnstat environment.
4
6
  #
5
- # @attr_writer [String] executable_path Sets the location of the vnstat
6
- # executable.
7
+ # @!attribute executable_path
8
+ # @return The location of the vnstat executable.
7
9
  class Configuration
8
10
  ##
9
11
  # Initializes the {Configuration}.
@@ -1,7 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'nokogiri'
4
+
1
5
  module Vnstat
2
6
  # A class encapsulating document data.
3
7
  #
4
- # @attr_reader [Nokogiri::XML::Document] data The underlying XML document.
8
+ # @!attribute [r] data
9
+ # @return [Nokogiri::XML::Document] The underlying XML document.
5
10
  class Document
6
11
  ##
7
12
  # Initializes the document.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Vnstat
2
4
  ##
3
5
  # An exception that hints at a generic error with vnstat.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Vnstat
2
4
  ##
3
5
  # An exception that is raised when the vnstat CLI could not be found on the
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Vnstat
2
4
  #
3
5
  # An exception that is raised when the specified interface could not be found
@@ -1,8 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Vnstat
2
4
  ##
3
5
  # A class encapsulating traffic information for a specific network interface.
4
6
  #
5
- # @attr_reader [String] id The network interface identifier.
7
+ # @!attribute [r] id
8
+ # @return [String] The network interface identifier.
6
9
  class Interface < Document
7
10
  attr_reader :id
8
11
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Vnstat
2
4
  ##
3
5
  # A class encapsulating traffic information for all known network interfaces.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Vnstat
2
4
  ##
3
5
  # A module containing several utility methods responsible for document
@@ -36,8 +38,8 @@ module Vnstat
36
38
  date = extract_date_from_xml_element(element)
37
39
  hour = element.xpath('time/hour').text.to_i
38
40
  minute = element.xpath('time/minute').text.to_i
39
- DateTime.new(date.year, date.month, date.day, hour, minute, 0,
40
- DateTime.now.offset)
41
+ offset = Time.now.strftime('%:z')
42
+ Time.new(date.year, date.month, date.day, hour, minute, 0, offset)
41
43
  end
42
44
 
43
45
  ##