timex_datalink_client 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 187352acb16bdc8baa7fec37d4793942f49b6c3d60da9a778b4afd94505c9f1e
4
- data.tar.gz: 55214e32e3536da008eb7739d0921af0012c1af6ff70d17491ef37a2fd6008a8
3
+ metadata.gz: 499c12fec3a8fae40770efc4173421e0a996b999a98a19a7e9ec64295628d757
4
+ data.tar.gz: 29b1bec826b2d5a2c25f7d7c9e47405760a2c08526e04f7f84084587dfec44c5
5
5
  SHA512:
6
- metadata.gz: 9106e98e689a8646ab779cd1ca38bce9c220c8aa80ae0fe984237e6a92270b0ee10bbdf9b31bc40c4492dc7b17d25c796baf7f3a5720a4649d7deb09a37b540f
7
- data.tar.gz: 70e7601d4ba51ecfc3cb6d3f51549e8272ec3baf55ee39174a6fbc5f48272569efcfad25b3eef447a05af767c855f79a4b84d15c286a39d30d2ad7506d273213
6
+ metadata.gz: 1278164bd72754ee49ad9d26b7cf3a953de3f164e6bb19a42a30a34528ed012b6d967f605aeb244b6554ca29541312edec4b4d2730c1fadfa38b9946d862e76e
7
+ data.tar.gz: ad536dfbf0e894b5474be3fc36c4c8b0387cdc47e7134c58c98e7c6978ac004a78b20c4f54059e63d8cc3accda0e7b2f60199920be8bdbe128d98afa62798727
@@ -49,9 +49,7 @@ class TimexDatalinkClient
49
49
  private
50
50
 
51
51
  def message_characters
52
- message_padded = message.ljust(MESSAGE_LENGTH)
53
-
54
- chars_for(message_padded)
52
+ chars_for(message, length: 8, pad: true)
55
53
  end
56
54
 
57
55
  def audible_integer
@@ -3,19 +3,23 @@
3
3
  class TimexDatalinkClient
4
4
  class Helpers
5
5
  module CharEncoders
6
- CHARS = "0123456789abcdefghijklmnopqrstuvwxyz !\"#$%&'()*+,-./:\\;=@?ABCDEF"
6
+ CHARS = "0123456789abcdefghijklmnopqrstuvwxyz !\"#$%&'()*+,-./:\\;=@?_|<>[]"
7
+
7
8
  EEPROM_TERMINATOR = 0x3f
8
9
 
9
10
  PHONE_CHARS = "0123456789cfhpw "
10
11
 
11
- def chars_for(string_chars, char_map: CHARS)
12
- string_chars.each_char.map do |string_char|
13
- char_map.index(string_char)
12
+ def chars_for(string_chars, char_map: CHARS, length: nil, pad: false)
13
+ formatted_chars = string_chars.downcase[0..length.to_i - 1]
14
+ formatted_chars = formatted_chars.ljust(length) if pad
15
+
16
+ formatted_chars.each_char.map do |char|
17
+ char_map.index(char)
14
18
  end
15
19
  end
16
20
 
17
21
  def eeprom_chars_for(string_chars)
18
- chars = chars_for(string_chars).append(EEPROM_TERMINATOR)
22
+ chars = chars_for(string_chars, length: 31).append(EEPROM_TERMINATOR)
19
23
 
20
24
  packed_int = chars.each_with_index.sum do |char, index|
21
25
  char << (6 * index)
@@ -25,7 +29,7 @@ class TimexDatalinkClient
25
29
  end
26
30
 
27
31
  def phone_chars_for(string_chars)
28
- chars = chars_for(string_chars, char_map: PHONE_CHARS)
32
+ chars = chars_for(string_chars, char_map: PHONE_CHARS, length: 12)
29
33
 
30
34
  packed_int = chars.each_with_index.sum do |char, index|
31
35
  char << (4 * index)
@@ -18,12 +18,14 @@ class TimexDatalinkClient
18
18
  # @param is_24h [Boolean] Toggle 24 hour time.
19
19
  # @param date_format [Integer] Date format.
20
20
  # @param time [::Time] Time to set (including time zone).
21
+ # @param name [String, nil] Name of time zone (defaults to zone from time; 3 chars max)
21
22
  # @return [Time] Time instance.
22
- def initialize(zone:, is_24h:, date_format:, time:)
23
+ def initialize(zone:, is_24h:, date_format:, time:, name: nil)
23
24
  @zone = zone
24
25
  @is_24h = is_24h
25
26
  @date_format = date_format
26
27
  @time = time
28
+ @name = name
27
29
  end
28
30
 
29
31
  # Compile packets for a time.
@@ -40,7 +42,7 @@ class TimexDatalinkClient
40
42
  time.month,
41
43
  time.day,
42
44
  year_mod_1900,
43
- timezone_characters,
45
+ name_characters,
44
46
  wday_from_monday,
45
47
  is_24h_value,
46
48
  date_format
@@ -50,8 +52,12 @@ class TimexDatalinkClient
50
52
 
51
53
  private
52
54
 
53
- def timezone_characters
54
- chars_for(time.zone.downcase)
55
+ def name
56
+ @name || time.zone.downcase
57
+ end
58
+
59
+ def name_characters
60
+ chars_for(name, length: 3, pad: true)
55
61
  end
56
62
 
57
63
  def year_mod_1900
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class TimexDatalinkClient
4
- VERSION = "0.3.1"
4
+ VERSION = "0.4.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timex_datalink_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maxwell Pray
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-08 00:00:00.000000000 Z
11
+ date: 2022-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: crc