due_sms_counter 0.2.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: 7cb339df92ef2bdff40d993a12e65e2a67656f78
4
- data.tar.gz: 0100c83eb042f7e8e3c01c773e877c8ea4a9d752
3
+ metadata.gz: f9d439f08dab4143302f15bef065ef403d62b8c8
4
+ data.tar.gz: ab583904aba1e38bedf5bb3428e7b0c0c1c86ec3
5
5
  SHA512:
6
- metadata.gz: 6a537ba047dee4ca72e3e4e9e1875a89d8cb0d71ed1eb4ac0307024d052d0c2ab23a505226d3b5c8724d075719d608ccd63752f1d7d6c63e480163ee3e01228f
7
- data.tar.gz: f32d1c18b22a4ad2b94a59569fd55f6ec7ca3803e8f7cbe09589c621cce21fe40a53c6354a76ce5e453fb11bae18a9a2557bb0e953bb353ece1430586bf24563
6
+ metadata.gz: e236f1620e84b6ff6763732c2aa07dc160dab45ffe190738c2821bfe9ada59d1670c216eca50e052eb722ef0ff0933ef546e43c24f0baa66285a26f6f10b2aab
7
+ data.tar.gz: 6401f7e897e902d9ede77296ab761c9eefbf0f85bd84c6c07f0a5d1b5f754a3d8e09d605ebdd6741b96e48c6c9d1a7cc3328496c1b3bd38c504782d4ff1e8988
@@ -1,3 +1,3 @@
1
1
  module DueSmsCounter
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -7,43 +7,61 @@ B7_2SIZED_CHARS, B7_BASE_CHARS, B7_SMS_COUNT, UNICODE_SMS_COUNT = CONSTS.values_
7
7
  B7_CHARS = B7_BASE_CHARS + B7_2SIZED_CHARS
8
8
 
9
9
  module DueSmsCounter
10
+ class << self
10
11
 
11
- def self.can_be_sent?(sms, max_sms)
12
- char_count = calc_char_count(sms)
13
- max_char = calc_max_char_count(max_sms)
14
- is_unicode = char_count[:is_unicode]
12
+ def can_be_sent?(sms, max_sms)
13
+ char_count = calc_char_count(sms)
14
+ max_char = calc_max_char_count(max_sms)
15
+ is_unicode = char_count[:is_unicode]
15
16
 
16
- char_count[:char_count] <= max_char[is_unicode ? :unicode : :gsm7]
17
- end
17
+ char_count[:char_count] <= max_char[is_unicode ? :unicode : :gsm7]
18
+ end
18
19
 
19
- def self.calc_char_count(sms)
20
- sms = (sms || '').split('')
21
- is_7_bits = (sms + B7_CHARS).uniq.length == B7_CHARS.length
22
- if is_7_bits
23
- { char_count: sms.length + count_2chars_sized(sms),
24
- is_unicode: false }
25
- else
26
- { char_count: sms.length,
27
- is_unicode: true }
20
+ def calc_char_count(sms)
21
+ sms = (sms || '').split('')
22
+ is_7_bits = (sms + B7_CHARS).uniq.length == B7_CHARS.length
23
+ if is_7_bits
24
+ { char_count: sms.length + count_2chars_sized(sms),
25
+ is_unicode: false }
26
+ else
27
+ { char_count: sms.length,
28
+ is_unicode: true }
29
+ end
28
30
  end
29
- end
30
31
 
31
- def self.calc_max_char_count(sms_count)
32
- {
33
- gsm7: (
34
- B7_SMS_COUNT[sms_count.to_s] ||
35
- B7_SMS_COUNT['max']
36
- )[1],
37
- unicode: (
38
- UNICODE_SMS_COUNT[sms_count.to_s] ||
39
- UNICODE_SMS_COUNT['max']
40
- )[1]
41
- }
42
- end
32
+ def calc_max_char_count(sms_count)
33
+ {
34
+ gsm7: (
35
+ B7_SMS_COUNT[sms_count.to_s] ||
36
+ B7_SMS_COUNT['max']
37
+ )[1],
38
+ unicode: (
39
+ UNICODE_SMS_COUNT[sms_count.to_s] ||
40
+ UNICODE_SMS_COUNT['max']
41
+ )[1]
42
+ }
43
+ end
44
+
45
+ def calc_sms_count(char_count, is_unicode)
46
+ base = is_unicode ? UNICODE_SMS_COUNT : B7_SMS_COUNT
47
+ sms_count = 0
48
+ while 42 do
49
+ break if !base[sms_count.to_s] || (base[sms_count.to_s][1] >= char_count)
50
+ sms_count += 1
51
+ end
52
+ sms_count
53
+ end
54
+
55
+ def calc_char_and_sms_count(sms)
56
+ result = calc_char_count(sms)
57
+ result[:sms_count] = calc_sms_count(result[:char_count], result[:is_unicode])
58
+ result
59
+ end
43
60
 
44
- def self.count_2chars_sized(sms)
45
- sms.reduce(0) do |count, letter|
46
- count + (B7_2SIZED_CHARS.include?(letter) ? 1 : 0)
61
+ def count_2chars_sized(sms)
62
+ sms.reduce(0) do |count, letter|
63
+ count + (B7_2SIZED_CHARS.include?(letter) ? 1 : 0)
64
+ end
47
65
  end
48
66
  end
49
67
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: due_sms_counter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ngouy