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 +4 -4
- data/lib/i2c/alpha_display.rb +1 -0
- data/lib/i2c/alpha_display/extensions.rb +42 -0
- data/lib/i2c/alpha_display/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96460488d5fdec071a77578a458f1debd8be3e34
|
4
|
+
data.tar.gz: 9eb8700402b0c86185aff32ba76611d553b81b76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 24aae001a71f39fe9d8c87bdeea06bb30321583ee7557629a03317e986fd1822fb9854887d7270da0b622ec39bdbf6043bbe3f2a239e76e1180cca97d0205997
|
7
|
+
data.tar.gz: 0e73ba3b30ad116cc58858545703981ba089739df8944450f118fe75a58166fdc855696d21416185d7ea9382f7cb60f38f66d1d4ddfe7f812afbb96ce5fc8c90
|
data/lib/i2c/alpha_display.rb
CHANGED
@@ -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
|
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.
|
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
|