text-gen 0.4.6 → 0.5.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: 7818963b925f0327e1788fac07898d955c4197721a901a38f83f5311355a81fd
4
- data.tar.gz: e3620212fb2ea2154b1e06444c875462e7c68a1c60a2c6fb45a92b28729a60a9
3
+ metadata.gz: 86f9c9dd7fe5548ad60d314ac884c1094ae01a963f4b8857b5ef054ee80e2c21
4
+ data.tar.gz: be6f441194af3a555fa497a33397c27c230fbcaad7ae0607636ce4bba71826e2
5
5
  SHA512:
6
- metadata.gz: '048df93a9adb0c5764fd55e90e0bffceacc7f078b5741a8f7c30365755570043101fa7668969a67d6588a17da126945ba0f0d5e4e413a112d4ec4b13d7af5acf'
7
- data.tar.gz: 244bddd0a689bc18451dc780fa7604a0fbf326ad591fadf9aecf6cb20e203ad31837f8da6c7ab8a9f2240dfbab743523f900a3234243becba538a70dbd471136
6
+ metadata.gz: 3a50a01053a1e25fb2261f9cbbaa5f2c64c19e4542665deb1a164490e9a840a4b83b714dd53fd21a69593fb72820312129e8232978b01b88e6de53cc7aec2a8b
7
+ data.tar.gz: 740dfeda14160a78830087c87d82526131a11d1e30d3038220147ab743bf7db5821d2070ef88d4bd5d5319a57f8f83cb005b7fbc94e7e1c86abfefb9d8dbd15c
@@ -28,6 +28,10 @@ module Text
28
28
  result = Result.from(text: result.text, type: :function, result:)
29
29
  result.merge_kv(filter["key"], filter["value"])
30
30
  result
31
+ when "swap"
32
+ text = Function::Swapper.swap(result.text, filter["key"], filter["value"])
33
+ result = Result.from(text:, type: :function, result:)
34
+ result
31
35
  end
32
36
  end
33
37
 
@@ -15,13 +15,16 @@ module Text
15
15
  "elf" => "elves",
16
16
  "man" => "men",
17
17
  "ox" => "oxen",
18
+ "cactus" => "cacti",
19
+ "thesis" => "theses",
20
+ "criterion" => "criteria",
18
21
  "thief" => "thieves",
19
22
  "tooth" => "teeth",
20
23
  "wolf" => "wolves",
21
24
  "woman" => "women"
22
25
  }.freeze
23
26
 
24
- SINGLE = Set.new(%w[a an the this that my your his her its our their])
27
+ SINGLE = Set.new(%w[a an the this his her its my your our that their])
25
28
 
26
29
  class << self
27
30
  def pluralize(str)
@@ -30,10 +33,13 @@ module Text
30
33
  arr = str.split(/\s+/)
31
34
  return str if arr.length < 2
32
35
 
33
- num = to_num(arr[0])
36
+ idx = arr.rindex { |s| to_num(s) }
37
+ return str if idx.nil? || idx >= arr.length - 1
38
+
39
+ num = to_num(arr[idx])
34
40
  if num && num > 1
35
41
  dc = arr[-1].downcase
36
- arr[-1] = exceptions(dc) || others(dc) || ends_with_y(dc) || simple(dc)
42
+ arr[-1] = exceptions(dc) || single_letter(dc) || others(dc) || ends_with_y(dc) || simple(dc)
37
43
  end
38
44
  arr.join(" ")
39
45
  end
@@ -48,6 +54,12 @@ module Text
48
54
  EXCEPTIONS[str]
49
55
  end
50
56
 
57
+ def single_letter(str)
58
+ if str =~ /^[a-zA-Z0-9]$/
59
+ "#{str}'s"
60
+ end
61
+ end
62
+
51
63
  def others(str)
52
64
  if str.end_with?("s") || str.end_with?("x") || str.end_with?("z") || str.end_with?("ch") || str.end_with?("sh")
53
65
  "#{str}es"
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Text
4
+ module Gen
5
+ module Function
6
+ class Swapper
7
+ class << self
8
+ def swap(str, key, val)
9
+ return str if key.nil? || key.empty?
10
+
11
+ puts("str=#{str} key=#{key} val=#{val}")
12
+
13
+ arr = str.split(/\s+/)
14
+ arr = arr.map do |s|
15
+ case key
16
+ when "digit"
17
+ swap_digit(s)
18
+ else
19
+ swap_any(s, key, val.to_s)
20
+ end
21
+ end
22
+ arr.join(" ")
23
+ end
24
+
25
+ def swap_any(str, key, val)
26
+ str == key ? val : str
27
+ end
28
+
29
+ def swap_digit(str)
30
+ case str
31
+ when "1"
32
+ "one"
33
+ when "2"
34
+ "two"
35
+ when "3"
36
+ "three"
37
+ when "4"
38
+ "four"
39
+ when "5"
40
+ "five"
41
+ when "6"
42
+ "six"
43
+ when "7"
44
+ "seven"
45
+ when "8"
46
+ "eight"
47
+ when "9"
48
+ "nine"
49
+ else
50
+ str
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Text
4
4
  module Gen
5
- VERSION = "0.4.6"
5
+ VERSION = "0.5.0"
6
6
  end
7
7
  end
data/lib/text/gen.rb CHANGED
@@ -8,6 +8,7 @@ require_relative "gen/max_recursion_error"
8
8
 
9
9
  require_relative "gen/function/titleizer"
10
10
  require_relative "gen/function/pluralizer"
11
+ require_relative "gen/function/swapper"
11
12
  require_relative "gen/result_accumulator"
12
13
  require_relative "gen/result"
13
14
  require_relative "gen/segment/parser"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: text-gen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.6
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - G Palmer
@@ -43,6 +43,7 @@ files:
43
43
  - lib/text/gen/filter.rb
44
44
  - lib/text/gen/filter_error.rb
45
45
  - lib/text/gen/function/pluralizer.rb
46
+ - lib/text/gen/function/swapper.rb
46
47
  - lib/text/gen/function/titleizer.rb
47
48
  - lib/text/gen/lookup_error.rb
48
49
  - lib/text/gen/max_attempts_error.rb