raspberry_pi_iot 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -102,7 +102,7 @@
102
102
  </div>
103
103
 
104
104
  <div id="footer">
105
- Generated on Thu Dec 20 18:09:38 2018 by
105
+ Generated on Wed Dec 26 18:10:00 2018 by
106
106
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
107
107
  0.9.16 (ruby-2.3.3).
108
108
  </div>
@@ -1,6 +1,6 @@
1
1
  require 'binary_receptor'
2
2
 
3
- # Button - simple push button
3
+ # Button - simple tactile / push button
4
4
  class Button < BinaryReceptor
5
5
  attr_writer :measure_pause
6
6
 
@@ -30,4 +30,47 @@ module RaspberryPi
30
30
  end
31
31
  info
32
32
  end
33
+
34
+ # Return host name as a string
35
+ def self.host_name
36
+ `hostname`.chomp
37
+ end
38
+
39
+ # Return host ip-addresses as an Array
40
+ def self.host_ip
41
+ `hostname -I`.chomp.split " "
42
+ end
43
+
44
+ # Return used and free disk space in KB on a file system or on all (with '*')
45
+ def self.disk_space(mounted='/', hash=false)
46
+ disk_memory = []
47
+ lines = `df -k`
48
+ lines.split("\n").each do |line|
49
+ disk_memory << line.chomp.split(" ")
50
+ end
51
+ disk_memory.shift # deleie 1st array with titles
52
+
53
+ if mounted == '*'
54
+ return hash ? self.matrix2hash(disk_memory) : disk_memory
55
+ else
56
+ disk_memory.each do |fs|
57
+ if fs[-1] == mounted
58
+ return hash ? self.list2hash(fs) : fs
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ private
65
+ def self.list2hash(a)
66
+ {:file_system=>a[0], :size=>a[1].to_i, :used=>a[2].to_i, :free=>a[3].to_i, :procent=>a[4].to_f, :mounted=>a[5]}
67
+ end
68
+
69
+ def self.matrix2hash(m)
70
+ h = {}
71
+ m.each do |a|
72
+ h[a[-1]] = self.list2hash(a)
73
+ end
74
+ h
75
+ end
33
76
  end
@@ -18,7 +18,7 @@ class RaspberryPiIoT_ButtonTest < MiniTest::Test
18
18
  assert @button.was_not_pressed?
19
19
  printf "Waiting for press...\n"
20
20
  @button.wait_for_press
21
- assert @button.was_pressed? if !@button.timeout?
21
+ assert @button.was_pressed? unless @button.timeout?
22
22
 
23
23
  end
24
24
 
@@ -26,22 +26,28 @@ class RaspberryPiIoT_ButtonTest < MiniTest::Test
26
26
  def test_wait_for_short_press
27
27
  printf "Waiting for 1 short press...\n"
28
28
  @button.wait_for_press
29
- assert @button.single_press?
30
- assert !@button.long_press?
29
+ unless @button.timeout?
30
+ assert @button.single_press?
31
+ assert !@button.long_press?
32
+ end
31
33
  end
32
34
 
33
35
  def test_wait_for_long_press
34
36
  printf "Waiting for 1 long press (> 1 second)...\n"
35
37
  @button.wait_for_press
36
- assert @button.single_press?
37
- assert !@button.double_press?
38
- assert @button.long_press?
38
+ unless !@button.timeout?
39
+ assert @button.single_press?
40
+ assert !@button.double_press?
41
+ assert @button.long_press?
42
+ end
39
43
  end
40
44
 
41
45
  def test_wait_for_double_press
42
46
  printf "Waiting for double press...\n", p
43
47
  @button.wait_for_presses 2
44
- assert @button.double_press?
45
- assert !@button.single_press?
48
+ unless @button.timeout?
49
+ assert @button.double_press?
50
+ assert !@button.single_press?
51
+ end
46
52
  end
47
53
  end
@@ -16,7 +16,29 @@ class RaspberryPiIoT_InfoTest < Minitest::Test
16
16
  assert_equal RaspberryPi.hardware_info['SoC'][0..2], "BCM"
17
17
  end
18
18
 
19
- #IoT::Log.new.message "I", "Test logging."
19
+ def test_hostname
20
+ assert RaspberryPi.host_name().size > 0
21
+ end
22
+
23
+ def test_ip
24
+ assert RaspberryPi.host_ip().class.to_s == 'Array'
25
+ end
26
+
27
+ def test_space
28
+ a = RaspberryPi.disk_space('*')
29
+ assert a.flatten.size > a.size
30
+ h = RaspberryPi.disk_space('*', true)
31
+ assert h.class.to_s == 'Hash'
32
+ assert h['/'].size == 6
33
+ assert h['/'][:mounted] == '/'
34
+
35
+ assert RaspberryPi.disk_space().class.to_s == 'Array'
36
+ assert RaspberryPi.disk_space() == RaspberryPi.disk_space('/', false)
37
+ assert RaspberryPi.disk_space('/')[-1] == '/'
38
+ assert RaspberryPi.disk_space('/', true).class.to_s == 'Hash'
39
+ end
20
40
  end
21
41
 
42
+ #IoT::Log.new.message "I", "Test logging."
43
+
22
44
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: raspberry_pi_iot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Shock (Mikhail V. Shokhirev)
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-12-20 00:00:00.000000000 Z
11
+ date: 2018-12-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -265,9 +265,9 @@ require_paths:
265
265
  - lib
266
266
  required_ruby_version: !ruby/object:Gem::Requirement
267
267
  requirements:
268
- - - ">="
268
+ - - "~>"
269
269
  - !ruby/object:Gem::Version
270
- version: '0'
270
+ version: '2.0'
271
271
  required_rubygems_version: !ruby/object:Gem::Requirement
272
272
  requirements:
273
273
  - - ">="