i2c-alpha_display 0.1.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 20684e599b86fa327f9015464c32319871e6b2f8
4
- data.tar.gz: 3775a3ee22721a4be8878881883a0984565c1c06
3
+ metadata.gz: 96460488d5fdec071a77578a458f1debd8be3e34
4
+ data.tar.gz: 9eb8700402b0c86185aff32ba76611d553b81b76
5
5
  SHA512:
6
- metadata.gz: a112dd8b3ca6c9c7d0c429ce33ec1892ad0753c4c71424b6f2455380942d4c1ae59810212d3fafad654601a60a2b0a44d58c7836324e5489e52a11d4e54511af
7
- data.tar.gz: a471164318b27af93fbdda40724f3f31774ae85c4b6097a72d6ce98c4dec94aa7e47268a012640eb2ad3b77a217d157463af4271dde7ce7ebb32c9d6315ff14d
6
+ metadata.gz: 24aae001a71f39fe9d8c87bdeea06bb30321583ee7557629a03317e986fd1822fb9854887d7270da0b622ec39bdbf6043bbe3f2a239e76e1180cca97d0205997
7
+ data.tar.gz: 0e73ba3b30ad116cc58858545703981ba089739df8944450f118fe75a58166fdc855696d21416185d7ea9382f7cb60f38f66d1d4ddfe7f812afbb96ce5fc8c90
@@ -1,5 +1,6 @@
1
1
  require "i2c/alpha_display/version"
2
2
  require "i2c/alpha_display/hardware"
3
+ require "i2c/alpha_display/extensions"
3
4
 
4
5
  module I2C
5
6
  class AlphaDisplay
@@ -0,0 +1,42 @@
1
+ class Time
2
+ def to_alpha
3
+ strftime '%H.%M'
4
+ end
5
+ end
6
+
7
+ class Fixnum
8
+ def to_alpha
9
+ return to_s if self < 1000
10
+ return self.to_f.to_alpha
11
+ end
12
+ end
13
+
14
+ class Float
15
+ def to_alpha(len = 4)
16
+ v = self.to_f
17
+
18
+ prefixes = ['', 'k', 'M', 'G', 'T']
19
+ pref_index = 0
20
+
21
+ if v.round.to_s.length > len
22
+ while v.abs > 1000
23
+ v = v / 1000
24
+ pref_index += 1
25
+ end
26
+
27
+ if v < 0 && v.abs >= 100
28
+ v = v / 1000
29
+ pref_index += 1
30
+ end
31
+ end
32
+
33
+ pref = prefixes[pref_index]
34
+ digits = len - pref.length
35
+ decimals = digits - v.abs.to_i.to_s.length - (v < 0 ? 1 : 0)
36
+ return ("%.#{decimals}f" % v) + pref
37
+ end
38
+
39
+ def to_ts
40
+ TimeSpan.new self
41
+ end
42
+ end
@@ -1,5 +1,5 @@
1
1
  module I2C
2
2
  class AlphaDisplay
3
- VERSION = "0.1.0"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i2c-alpha_display
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Reed
@@ -57,6 +57,7 @@ files:
57
57
  - exe/i2c-disp
58
58
  - i2c-alpha_display.gemspec
59
59
  - lib/i2c/alpha_display.rb
60
+ - lib/i2c/alpha_display/extensions.rb
60
61
  - lib/i2c/alpha_display/hardware.rb
61
62
  - lib/i2c/alpha_display/version.rb
62
63
  - lib/i2c/alpha_display_app.rb