jekyll-kw-shorten 0.0.11 → 0.0.12

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
  SHA256:
3
- metadata.gz: 3e593496e1b6a803fc2ccad35c0e477fefe1fb7fa1f9d5ae4431a84a9c99395f
4
- data.tar.gz: 27ad67e6058c04547fc482d58e9b12bf9f06685ce01ff966b5e7fd7302348801
3
+ metadata.gz: 012dee8b1fc72f257b2e457836d2b8f56cc3faac819e57fb0f29336cf3ff2436
4
+ data.tar.gz: b3203689baedeeef368523c60a6bc272c74642f4348bf7dfc332665836085188
5
5
  SHA512:
6
- metadata.gz: cf3e5f9f35fad937a511661d3a6ab694046dc8fe178e84a234c195e46766d3291d2438c0990cba4b534d129d87d951865d4cb8903fe9009b9263cf664a217bf0
7
- data.tar.gz: ece39f6384277d0f5f32fc6c32a79c3903099343cf4d0cea6682fae432814240dffdfe3817852e0339dc4d17db2019a8f400306e2582c415d8de4b63691bc933
6
+ metadata.gz: 443768121201fcbb3a56405c1d25ca797278b4178070445b5ff745113a6efc1f694aff1156f9ea6e073b553c690348eb423db86ae0154e7d4e8847792d015a04
7
+ data.tar.gz: ed61ccbf42f6b92577d68f8efbc4258f884185b69866a93c93b1484dc2e10c7937177b3bc9303e6b2cdaf6993e89637270fc1e5cc89be8120fd735a5ca6442af
@@ -35,11 +35,11 @@ module Jekyll
35
35
 
36
36
  # shorten filter {{ number | shorten }} for Jekyll
37
37
  module ShortenFilter
38
- def shorten(number)
38
+ def shorten(input)
39
39
  parser = Jekyll::KargWare::Shorten::Parser.new(
40
40
  Jekyll::KargWare::Shorten.get_plugin_config(@context)
41
41
  )
42
- parser.parse(number)
42
+ parser.parse(input)
43
43
  end
44
44
  end
45
45
  end
@@ -7,6 +7,9 @@ module Jekyll
7
7
  module Shorten
8
8
  # jekyll-kw-shorten parser class
9
9
  class Parser
10
+ # https://stackoverflow.com/questions/33952093/how-to-allow-only-one-dot-in-regex
11
+ DIGITS_AND_SINGLE_DOT_ESCAPE_REGEXP = /(-?\s?[0-9]+(\.[0-9]+)?)/.freeze
12
+
10
13
  attr_reader :configuration
11
14
 
12
15
  def initialize(options = {})
@@ -14,10 +17,11 @@ module Jekyll
14
17
  end
15
18
 
16
19
  def parse(text)
17
- return text unless Parser.number?(text)
20
+ num = Parser.only_float_numbers(text)
21
+
22
+ return text unless Parser.number?(num)
18
23
 
19
24
  begin
20
- num = text.to_f
21
25
  if num >= 1000000000000
22
26
  '∞ 🚀'
23
27
  elsif num >= 1000000000
@@ -43,9 +47,16 @@ module Jekyll
43
47
 
44
48
  def self.number?(string)
45
49
  true if Float(string)
50
+ # true if Float(Parser.only_float_numbers(string))
46
51
  rescue StandardError
47
52
  false
48
53
  end
54
+
55
+ def self.only_float_numbers(input)
56
+ input.to_s.scan(DIGITS_AND_SINGLE_DOT_ESCAPE_REGEXP).first.first.to_f
57
+ rescue StandardError
58
+ input
59
+ end
49
60
  end
50
61
  end
51
62
  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.11'
7
+ VERSION = '0.0.12'
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.11
4
+ version: 0.0.12
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: 2021-01-04 00:00:00.000000000 Z
12
+ date: 2021-01-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jekyll