string_magic 0.3.0 → 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: 29052aa4271f574a936a326f9e2460655962a9242020d4180d3bb170d043374b
4
- data.tar.gz: 1f728af7f58397870658ce3edb3cb1522b6dc036c068b8c092475fcd7185779f
3
+ metadata.gz: 7c2974ab8c5a68c297377233418f680d5f92ddc66d1c2c4490744c136ac6982a
4
+ data.tar.gz: da5732a7df509fb6d1ff3c73990a477f9b1417fb0ffd50e4c18819fd495b17f8
5
5
  SHA512:
6
- metadata.gz: c135c02a42aecdd923c75bff56354b4c12e158e8a359e2c9f3114bb4aa319111907770bf6ee012abaf431f48b26776b5b5d9ecfdbd81ce47927c3e4438aab14b
7
- data.tar.gz: fcd862e9ed702db639d76af3ce6767ca8c4f2fe21493a991f9a4362db18125b72a6e26a7fc160715b2528cf22fc28c7c80bc60418a061b3c0e8a0883c54437b2
6
+ metadata.gz: b82312455117a5efdf8cc12d58dd825e0cc268c351199185c5430125eede62d4180ec71f5497bbec627dca9a3ebffee177d5a8480fd3fedfb469709145530f2b
7
+ data.tar.gz: 2520fb7095a7ccdfc3ea91e9e702e0906c37dc6f810b1f5e9231c4aeb8759747ccfce1a05a20488187463627e537c298bd864647a7b3309ddc894c5dd69c551e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [0.4.0] - 2025-01-01
2
+
3
+ ### Added
4
+
5
+ - Core string utility methods (palindrome, case conversions, word operations)
6
+ - Test coverage for new methods
7
+
1
8
  ## [0.3.0] - 2025-01-01
2
9
 
3
10
  - Text analysis features
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # StringMagic
2
2
 
3
- [![Gem Version](https://d25lcipzij17d.cloudfront.net/badge.svg?id=rb&r=r&ts=1683906897&type=6e&v=0.3.0&x2=0)](https://badge.fury.io/rb/string_magic)
3
+ [![Gem Version](https://d25lcipzij17d.cloudfront.net/badge.svg?id=rb&r=r&ts=1683906897&type=6e&v=0.4.0&x2=0)](https://badge.fury.io/rb/string_magic)
4
4
  [![CircleCI](https://dl.circleci.com/status-badge/img/circleci/8MamMcAVAVNWTcUqkjQk7R/Sh2DQkMWqqCv4MFvAmYWDL/tree/main.svg?style=svg&circle-token=CCIPRJ_PF8xu3Svcj2Ro4D8jhjCi7_71b7c0a7c781e09fc7194cd58cca67aecdc111b5)](https://dl.circleci.com/status-badge/redirect/circleci/8MamMcAVAVNWTcUqkjQk7R/Sh2DQkMWqqCv4MFvAmYWDL/tree/main)
5
5
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
6
 
@@ -0,0 +1,38 @@
1
+ module StringMagic
2
+ module Advanced
3
+ module Security
4
+ def mask_sensitive_data(text, options = {})
5
+ return text if text.nil? || text.empty?
6
+
7
+ mask_char = options[:mask_char] || "*"
8
+ options[:preserve_count] || 4
9
+
10
+ patterns = {
11
+ credit_card: /\b\d{4}[-\s]?\d{4}[-\s]?\d{4}[-\s]?\d{4}\b/,
12
+ ssn: /\b\d{3}[-\s]?\d{2}[-\s]?\d{4}\b/,
13
+ email: /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/
14
+ }
15
+
16
+ result = text.dup
17
+
18
+ patterns.each do |type, pattern|
19
+ result.gsub!(pattern) do |match|
20
+ case type
21
+ when :credit_card
22
+ digits = match.gsub(/[-\s]/, "")
23
+ mask_char * 12 + digits[-4..]
24
+ when :ssn
25
+ digits = match.gsub(/[-\s]/, "")
26
+ mask_char * 5 + digits[-4..]
27
+ when :email
28
+ local, domain = match.split("@")
29
+ "#{mask_char * local.length}@#{domain}"
30
+ end
31
+ end
32
+ end
33
+
34
+ result
35
+ end
36
+ end
37
+ end
38
+ end
@@ -1,6 +1,35 @@
1
1
  module StringMagic
2
2
  module Core
3
3
  module Transformation
4
+ def titleize_names(text)
5
+ return text if text.nil? || text.empty?
6
+
7
+ special_cases = {
8
+ "mcdonald" => "McDonald",
9
+ "o'reilly" => "O'Reilly",
10
+ "macbook" => "MacBook",
11
+ "iphone" => "iPhone",
12
+ "ipad" => "iPad",
13
+ "ebay" => "eBay"
14
+ }
15
+
16
+ prefixes = Set.new(%w[van de la du das dos di da delle degli delle])
17
+ articles = Set.new(%w[a an the]) # Add this line
18
+
19
+ words = text.downcase.split(/\s+/)
20
+ words.map.with_index do |word, index|
21
+ if special_cases.key?(word)
22
+ special_cases[word]
23
+ elsif prefixes.include?(word) && !index.zero?
24
+ word
25
+ elsif articles.include?(word) && !index.zero? # Add this condition
26
+ word.downcase
27
+ else
28
+ word.capitalize
29
+ end
30
+ end.join(" ")
31
+ end
32
+
4
33
  def to_snake_case(string)
5
34
  return "" if string.nil?
6
35
 
@@ -0,0 +1,19 @@
1
+ module StringMagic
2
+ module Formatting
3
+ module Highlighting
4
+ def highlight(text, phrases, options = {})
5
+ return text if text.nil? || phrases.nil?
6
+
7
+ tag = options[:tag] || "mark"
8
+ css_class = options[:class]
9
+ phrases = Array(phrases)
10
+
11
+ class_attr = css_class ? %( class="#{css_class}") : ""
12
+
13
+ phrases.reduce(text) do |result, phrase|
14
+ result.gsub(/(#{Regexp.escape(phrase)})/i, "<#{tag}#{class_attr}>\\1</#{tag}>")
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,25 @@
1
+ module StringMagic
2
+ module Formatting
3
+ module Truncation
4
+ def truncate_words(text, count, options = {})
5
+ return text if text.nil? || count.nil? || count < 1
6
+
7
+ suffix = options[:suffix] || "..."
8
+ words = text.split(/\s+/)
9
+ return text if words.length <= count
10
+
11
+ words[0...count].join(" ") + suffix
12
+ end
13
+
14
+ def truncate_sentences(text, count, options = {})
15
+ return text if text.nil? || count.nil? || count < 1
16
+
17
+ suffix = options[:suffix] || "..."
18
+ sentences = text.split(/(?<=[.!?])\s+/)
19
+ return text if sentences.length <= count
20
+
21
+ sentences[0...count].join(" ") + suffix
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StringMagic
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
data/lib/string_magic.rb CHANGED
@@ -3,14 +3,19 @@
3
3
  require_relative "string_magic/version"
4
4
  require_relative "string_magic/core/analysis"
5
5
  require_relative "string_magic/core/transformation"
6
+ require_relative "string_magic/formatting/highlighting"
7
+ require_relative "string_magic/formatting/truncation"
8
+ require_relative "string_magic/advanced/security"
6
9
 
7
10
  module StringMagic
8
11
  class Error < StandardError; end
9
12
  class MalformedInputError < Error; end
10
13
 
11
- # Now extend the modules
12
14
  extend Core::Analysis
13
15
  extend Core::Transformation
16
+ extend Formatting::Highlighting
17
+ extend Formatting::Truncation
18
+ extend Advanced::Security
14
19
 
15
20
  def self.hello_world
16
21
  "hello world!"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: string_magic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emad Rahimi
@@ -69,8 +69,11 @@ files:
69
69
  - README.md
70
70
  - Rakefile
71
71
  - lib/string_magic.rb
72
+ - lib/string_magic/advanced/security.rb
72
73
  - lib/string_magic/core/analysis.rb
73
74
  - lib/string_magic/core/transformation.rb
75
+ - lib/string_magic/formatting/highlighting.rb
76
+ - lib/string_magic/formatting/truncation.rb
74
77
  - lib/string_magic/version.rb
75
78
  - sig/string_magic.rbs
76
79
  homepage: https://github.com/erscript/string-magic