jekyll-kw-shorten 0.0.9 → 0.0.10

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: 97496aede7c98b125cb9e846af73359d5fbc9bf7a1d2bf64209cd1b029e2a8c8
4
- data.tar.gz: f10ea06d240481bbf7dc057ea48bd30a915d23a1df0c20a4faedd276d9879475
3
+ metadata.gz: 68f63c1abffd9e7cadb9ce48e2b926f612b4e6ec7a40d964a9a7660631cff5fb
4
+ data.tar.gz: 319d0ba44d6f0ae50589ad2df7db45ca9798bab80db52a225bc29ba32318d967
5
5
  SHA512:
6
- metadata.gz: dbe3c662114d8a867b4e1ed5718215a62826eb35e3e08934fdf460a967757ec00f2b35283a2411e551796b69c2aae0b093cd38e5aa081e8235fbd284acda348a
7
- data.tar.gz: 0112cb09a60e5dc1bf4d7a9f9de3a035ed178dcbac030fe2d8f5e5924fc79205d8284907ace1a0175f954acad24e56a2a7e42651a3b3bc3aa53a71983085eba9
6
+ metadata.gz: a5bd7d988b75d828a50c5733e2e843e662c58c18a3dd009c61955926c53f62fe5216fbdded3642b12d2f9648dea238392665b773e5b32e6e1002b0e86d6ee91e
7
+ data.tar.gz: 38b05260c97dda5f6e1c531cf87e815c8890d880b1a83f3edfc36d9842121a981add98eb36ac7f57863b427a1b0f975dfba4bdca9db49cbccc0fbbc7334af69f
@@ -20,7 +20,7 @@ module Jekyll
20
20
 
21
21
  def initialize(tag_name, input, tokens)
22
22
  super
23
- @input = input
23
+ @input = input.to_s.strip
24
24
 
25
25
  # raise ArgumentError, <<~MSG
26
26
  # Could not use '#{input}' in tag '#{self.class.tag_name}'.
@@ -30,6 +30,7 @@ module Jekyll
30
30
 
31
31
  def render(context)
32
32
  parser = Jekyll::KargWare::Shorten::Parser.new(get_plugin_config(context))
33
+ # parser = Jekyll::KargWare::Shorten::Parser.new({})
33
34
  parser.parse(@input)
34
35
  end
35
36
 
@@ -14,24 +14,34 @@ module Jekyll
14
14
  end
15
15
 
16
16
  def parse(text)
17
- if text.is_a? String then
18
- return text
19
- else
20
- num = text.to_i
17
+ if Parser.is_number?(text) then
18
+ num = text.to_f
21
19
  if num >= 1000000000000 then
22
20
  return "∞ 🚀"
23
21
  elsif num >= 1000000000 then
24
- return (num / 1000000000.0).truncate(1).to_s + @configuration.shorten_gt9_digit
22
+ return format(num / 1000000000.0) + @configuration.shorten_gt9_digit
25
23
  elsif num >= 1000000 then
26
- return (num / 1000000.0).truncate(1).to_s + @configuration.shorten_gt6_digit
24
+ return format(num / 1000000.0) + @configuration.shorten_gt6_digit
27
25
  elsif num >= 1000 then
28
- return (num / 1000.0).truncate(1).to_s + @configuration.shorten_gt3_digit
26
+ return format(num / 1000.0) + @configuration.shorten_gt3_digit
29
27
  else
30
- return (num).truncate(1).to_s
28
+ return num.round(0).truncate(0).to_s.rjust(5)
31
29
  end
30
+ else
31
+ return text
32
32
  end
33
33
  end
34
34
 
35
+ # private
36
+
37
+ def format(num)
38
+ num.round(1).truncate(1).to_s
39
+ end
40
+
41
+ def self.is_number? string
42
+ true if Float(string) rescue false
43
+ end
44
+
35
45
  end
36
46
  end
37
47
  end
@@ -4,7 +4,7 @@ module Jekyll
4
4
  module KargWare
5
5
  module Shorten
6
6
  RUBYGEM_NAME = 'jekyll-kw-shorten'
7
- VERSION = '0.0.9'
7
+ VERSION = '0.0.10'
8
8
  end
9
9
  end
10
10
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-kw-shorten
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
  - Nicolas Karg
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-12-27 00:00:00.000000000 Z
12
+ date: 2020-12-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jekyll