rupower 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MGU2MmY1MjFiY2MzOTYwNDIyYTI2MTUwNWVlZjllN2M5YjU0YTljMA==
5
+ data.tar.gz: !binary |-
6
+ MTg2YWFjY2M5ZTU4NGIzZjlhMjg5MTI0NDNkODg5OGY1NzBiMjBhZA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ NGM4Yjc0ODI0MjFhZjU5YjY0NmMzNWM4YjAwZTBiZTgwYjkwYTA5YTYzNDhi
10
+ YWNiMjQ3Mzc5M2NmOGI4NDA2OGM1Njc4MjQyZGJhNDA5NmIwOGIyMTBlNmJj
11
+ ZGNiOTBlM2YzOTUwNmFkNmVkMGYzMjExZGZhNWQ5ZjczMzg5ZDc=
12
+ data.tar.gz: !binary |-
13
+ MDVhNTE2NGRlOGJhOTM2ZWIyNjQ3MjJlNWI5NzdhOTJjNDc3MmY5Y2Y1MTQ2
14
+ NjJmZTdkNDAyNDAwNjEwNGM4MzdhZjlmMDRhNTRlZDYzODE4MGZhYWM3NGEw
15
+ NGFhYTdkOTk5ZmNhY2Q0MzM4NDBhYWY3NDVjNTI2NWJhMDdlMDc=
data/lib/rupower.rb CHANGED
@@ -4,12 +4,13 @@ require_relative "rupower/version"
4
4
  module Rupower
5
5
 
6
6
  module Parser
7
- TIME = Regexp.new( /(\d{2}:){2}\d{2}\s\d{4}/ )
8
- NUMBER = Regexp.new(/^\d+[.]?\d*(|[%]|\s+\w+)$/) #( /\A[+-]?\d+?(\.\d+)?\Z/ )
7
+ TIME = Regexp.new(/\d{4},?\s(\d{2}:){2}\d{2}\s/)
8
+ ETA = Regexp.new(/(\d+\.\d)\s(hour|minute)/)
9
+ NUMBER = Regexp.new(/^\d+[.,]?\d*(|[%]|\s+\w+)$/) #( /\A[+-]?\d+?(\.\d+)?\Z/ )
9
10
  end
10
11
 
11
12
  class PowerDevice
12
- def initialize( params = {refresh_always:true} )
13
+ def initialize( params = {refresh_always: true} )
13
14
  @refresh_always = params[:refresh_always]
14
15
  @command = params[:command] || Command.new
15
16
  refresh
@@ -30,8 +31,12 @@ module Rupower
30
31
  def typize( value )
31
32
  res = value
32
33
  res = value[/^yes$/] ? true : false if value[/^(yes|no)$/]
33
- res = value.to_f == value.to_i ? value.to_i : value.to_f if value[Parser::NUMBER ]
34
+ if value[Parser::NUMBER ]
35
+ value.gsub!(',','.')
36
+ res = value.to_f == value.to_i ? value.to_i : value.to_f
37
+ end
34
38
  res = DateTime.parse( value ) if value.match( Parser::TIME )
39
+ res = value if value[Parser::ETA]
35
40
  res
36
41
  end
37
42
 
@@ -49,7 +54,8 @@ module Rupower
49
54
  METHODS = [:native_path, :vendor, :model, :serial, :power_supply, :updated,
50
55
  :has_history, :has_statistics, :present, :rechargeable, :state,
51
56
  :energy, :energy_empty, :energy_full, :energy_full_design,
52
- :energy_rate, :voltage, :percentage, :capacity, :technology]
57
+ :energy_rate, :voltage, :percentage, :capacity, :technology,
58
+ :time_to_empty, :time_to_full]
53
59
 
54
60
  METHODS.each do |method|
55
61
  define_method method do
@@ -1,3 +1,3 @@
1
1
  module Rupower
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
@@ -23,7 +23,7 @@ class RupowerTest < Test::Unit::TestCase
23
23
  assert_instance_of( Float, @battery.voltage )
24
24
  assert_instance_of( String, @battery.vendor )
25
25
  assert_instance_of( String, @battery.native_path )
26
- assert_instance_of( DateTime, @battery.updated )
26
+ assert_instance_of( DateTime, @battery.updated )
27
27
  end
28
28
 
29
29
  def test_line_ac_get_methods_returns_correct_values
@@ -3,7 +3,7 @@
3
3
  model: 42T4795
4
4
  serial: 6804
5
5
  power supply: yes
6
- updated: Sun Mar 25 22:56:15 2012 (22 seconds ago)
6
+ updated: Wed 04 Dec 2013 02:06:26 AM CET (0 seconds ago)
7
7
  has history: yes
8
8
  has statistics: yes
9
9
  battery
@@ -1,7 +1,7 @@
1
1
  native-path: /sys/devices/LNXSYSTM:00/device:00/PNP0A08:00/device:09/PNP0C09:00/ACPI0003:00/power_supply/AC
2
2
  power supply: yes
3
- updated: Sat Mar 24 23:47:24 2012 (79753 seconds ago)
3
+ updated: Wed 04 Dec 2013 02:06:26 AM CET (0 seconds ago)
4
4
  has history: no
5
5
  has statistics: no
6
6
  line-power
7
- online: yes
7
+ online: yes
@@ -33,7 +33,7 @@ class RupowerBatteryTest < Test::Unit::TestCase
33
33
  end
34
34
 
35
35
  def test_updated_returns_correct_value
36
- assert_equal( DateTime.parse("Sun Mar 25 22:56:15 2012"), @battery.updated )
36
+ assert_equal( DateTime.parse("Wed 04 Dec 2013 02:06:26 AM CET"), @battery.updated )
37
37
  end
38
38
 
39
39
  def test_has_history_returns_correct_value
@@ -22,7 +22,7 @@ class RupowerLineAcTest < Test::Unit::TestCase
22
22
  end
23
23
 
24
24
  def test_updated_returns_correct_value
25
- assert_equal( DateTime.parse("Sat Mar 24 23:47:24 2012"), @line_ac.updated )
25
+ assert_equal( DateTime.parse("Wed 04 Dec 2013 02:06:26 AM CET"), @line_ac.updated )
26
26
  end
27
27
 
28
28
  def test_has_history_returns_correct_value
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rupower
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
5
- prerelease:
4
+ version: 0.1.6
6
5
  platform: ruby
7
6
  authors:
8
7
  - k-nowicki
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-04-02 00:00:00.000000000 Z
11
+ date: 2013-12-04 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: ! 'Rupower is UPower (http://upower.freedesktop.org) interface for Ruby,
15
14
  working for Battery and AC supply.
@@ -39,30 +38,26 @@ files:
39
38
  - test/stubs/command_stub.rb
40
39
  homepage: https://github.com/k-nowicki/rupower
41
40
  licenses: []
41
+ metadata: {}
42
42
  post_install_message:
43
43
  rdoc_options: []
44
44
  require_paths:
45
45
  - lib
46
46
  required_ruby_version: !ruby/object:Gem::Requirement
47
- none: false
48
47
  requirements:
49
48
  - - ! '>='
50
49
  - !ruby/object:Gem::Version
51
50
  version: 1.9.2
52
51
  required_rubygems_version: !ruby/object:Gem::Requirement
53
- none: false
54
52
  requirements:
55
53
  - - ! '>='
56
54
  - !ruby/object:Gem::Version
57
55
  version: '0'
58
- segments:
59
- - 0
60
- hash: 151074513370215442
61
56
  requirements: []
62
57
  rubyforge_project:
63
- rubygems_version: 1.8.17
58
+ rubygems_version: 2.0.2
64
59
  signing_key:
65
- specification_version: 3
60
+ specification_version: 4
66
61
  summary: Rupower is UPower (http://upower.freedesktop.org) interface for Ruby.
67
62
  test_files:
68
63
  - test/acceptance/rupower_test.rb