no_regex 0.1.0 → 0.1.1

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +210 -1
  3. data/lib/no_regex/version.rb +1 -1
  4. metadata +7 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a468f27fb587ec14c92c7a9164acc0afbe38f904fbc765bd206d589cc5e90c4e
4
- data.tar.gz: 3c6b9c9d8c6179034637022cc010bfd19ff02968ca5a8bf174fb8ac548b7058f
3
+ metadata.gz: 2620e92704d0f067482dd54418ec154a4c8de99da9a9f960fe79dc44f9f17760
4
+ data.tar.gz: c2da4ada8d933a38c9fd1c1b166744b1a2f9779054fcc4e298e9f153ebfeab23
5
5
  SHA512:
6
- metadata.gz: 1f380a614f7a93833d25e748240033b7ef88585140f0a4b2289c402f4336a1b974eff1ffcfa312ceec15831b07193941b7d3ec268cf6655ff44b16c61b35ea10
7
- data.tar.gz: 21083b7f2f777552af3541f00e0a9f8a4cf99f65e0c98d29b7904f5f0509842118a88b94a06eb3e41e07600feddd8d31c10529fd5ce92a803231904aaeba4b6a
6
+ metadata.gz: f326fe5e40057f5321fd088562820c5bc3fb9eecb48f64307ffb009d912ec3f188864afe76d7d87daa758d3bb1358abcc0e0c54428a775b5e67ba8d83efd0721
7
+ data.tar.gz: 3b12fa97e48731261465565b490b77314c24fdf216da57d86328d17610e0c2ff101a289307ddb0c6c6c94914a95923667855b14f4b830f8b16c490463ad47fc8
data/README.md CHANGED
@@ -7,4 +7,213 @@ Write Ruby without regex! A gem that provides simple, readable methods to replac
7
7
  Add this line to your application's Gemfile:
8
8
 
9
9
  ```ruby
10
- gem 'no_regex'
10
+ gem 'no_regex'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```bash
16
+ $ bundle install
17
+ ```
18
+
19
+ Or install it yourself as:
20
+
21
+ ```bash
22
+ $ gem install no_regex
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ NoRegex extends Ruby's String, Integer, Float, and other classes with intuitive methods that eliminate the need for regex:
28
+
29
+ ### String Methods
30
+
31
+ ```ruby
32
+ require 'no_regex'
33
+
34
+ # Validation methods - return true/false
35
+ "12345".is_number? # => true
36
+ "test@example.com".is_email? # => true
37
+ "https://example.com".is_url? # => true
38
+ "john_doe".is_username? # => true
39
+
40
+ # Manipulation methods - return modified strings
41
+ "hello-world".remove_dashes # => "helloworld"
42
+ "abc123xyz".keep_numbers # => "123"
43
+ "HelloWorld".to_snake_case # => "hello_world"
44
+
45
+ # Extraction methods - return arrays
46
+ "Contact: test@example.com".extract_emails # => ["test@example.com"]
47
+ "Price: $123".extract_numbers # => ["123"]
48
+ ```
49
+
50
+ ### Numeric Methods
51
+
52
+ ```ruby
53
+ 42.is_positive? # => true
54
+ 123.to_currency # => "$123"
55
+ 3.14.to_percentage # => "314.0%"
56
+ ```
57
+
58
+ ## Rails Integration
59
+
60
+ ### Using Format Validations in Rails
61
+
62
+ To use the `format: { with: is_number? }` syntax in your Rails models or form objects, you need to extend your class with `NoRegex::PatternMethods`:
63
+
64
+ ```ruby
65
+ class User < ApplicationRecord
66
+ extend NoRegex::PatternMethods
67
+
68
+ validates :email, format: { with: is_email? }
69
+ validates :phone, format: { with: is_phone_number? }
70
+ end
71
+ ```
72
+
73
+ For form objects:
74
+ ```ruby
75
+ class MyFormObject
76
+ include ActiveModel::Model
77
+ extend NoRegex::PatternMethods
78
+
79
+ validates :search_term, format: { with: is_number? }
80
+ end
81
+ ```
82
+
83
+ This makes all the pattern methods available to your validations. Once extended, you can use any of the validation methods shown below.
84
+
85
+ ### All Available Format Validators
86
+
87
+ ```ruby
88
+ validates :field, format: { with: is_number? } # Only digits
89
+ validates :field, format: { with: is_letters? } # Only letters
90
+ validates :field, format: { with: is_alphanumeric? } # Letters and numbers
91
+ validates :field, format: { with: is_email? } # Email format
92
+ validates :field, format: { with: is_phone_number? } # Phone format
93
+ validates :field, format: { with: is_url? } # URL format
94
+ validates :field, format: { with: is_zip_code? } # ZIP code
95
+ validates :field, format: { with: is_hex_color? } # Hex colors
96
+ validates :field, format: { with: is_username? } # Usernames
97
+ validates :field, format: { with: is_decimal? } # Decimals
98
+ validates :field, format: { with: is_integer? } # Integers
99
+ validates :field, format: { with: is_positive_number? } # Positive numbers
100
+ validates :field, format: { with: is_uuid? } # UUIDs
101
+ validates :field, format: { with: is_credit_card? } # Credit cards
102
+ validates :field, format: { with: is_ssn? } # SSN format
103
+ validates :field, format: { with: is_ipv4? } # IP addresses
104
+ validates :field, format: { with: is_time_24h? } # 24-hour time
105
+ validates :field, format: { with: is_date_yyyy_mm_dd? } # YYYY-MM-DD dates
106
+ ```
107
+
108
+ ### Custom Validators (Alternative Approach)
109
+
110
+ ```ruby
111
+ class User < ApplicationRecord
112
+ validates :phone, number: true
113
+ validates :name, letters: { message: "can only contain letters" }
114
+ validates :username, alphanumeric: true
115
+ validates :email, email_format: true
116
+ validates :website, url_format: { allow_blank: true }
117
+ end
118
+ ```
119
+
120
+ ## Available Methods
121
+
122
+ ### Validation Methods
123
+
124
+ - `is_number?` - Check if string contains only numbers
125
+ - `is_letters?` - Check if string contains only letters
126
+ - `is_alphanumeric?` - Check if string contains only letters and numbers
127
+ - `is_email?` - Check if string is a valid email format
128
+ - `is_blank?` - Check if string is nil or contains only whitespace
129
+ - `is_url?` - Check if string is a valid URL format
130
+ - `is_phone_number?` - Check if string is a valid phone number
131
+ - `is_zip_code?` - Check if string is a valid ZIP code
132
+ - `is_hex_color?` - Check if string is a valid hex color
133
+ - `is_username?` - Check if string is a valid username (letters, numbers, _, -)
134
+ - `is_decimal?` - Check if string is a decimal number
135
+ - `is_integer?` - Check if string is an integer
136
+ - `is_positive_number?` - Check if string is a positive number
137
+ - `is_uuid?` - Check if string is a valid UUID
138
+ - `is_credit_card?` - Check if string is a valid credit card number
139
+ - `is_ssn?` - Check if string is a valid SSN
140
+ - `is_ipv4?` - Check if string is a valid IPv4 address
141
+ - `is_time_24h?` - Check if string is valid 24-hour time format
142
+ - `is_date_yyyy_mm_dd?` - Check if string is valid YYYY-MM-DD date format
143
+
144
+ ### Manipulation Methods
145
+
146
+ - `remove_dashes` - Remove all dashes from string
147
+ - `remove_spaces` - Remove all spaces from string
148
+ - `remove_special_chars` - Remove all special characters, keeping only letters and numbers
149
+ - `remove_numbers` - Remove all numbers from string
150
+ - `remove_letters` - Remove all letters from string
151
+ - `keep_numbers` - Keep only numbers in string
152
+ - `keep_letters` - Keep only letters in string
153
+
154
+ ### Conversion Methods
155
+
156
+ - `to_snake_case` - Convert string to snake_case
157
+ - `to_camel_case` - Convert string to camelCase
158
+
159
+ ### Extraction Methods
160
+
161
+ - `extract_numbers` - Extract all numbers from string (returns array)
162
+ - `extract_emails` - Extract all email addresses from string (returns array)
163
+
164
+ ### Utility Methods
165
+
166
+ - `word_count` - Count words in string
167
+ - `truncate(length, ellipsis)` - Truncate string to specified length with ellipsis
168
+
169
+ ## Examples
170
+
171
+ ```ruby
172
+ # Validation
173
+ "12345".is_number? # => true
174
+ "abc123".is_letters? # => false
175
+ "test@example.com".is_email? # => true
176
+ "https://example.com".is_url? # => true
177
+
178
+ # Manipulation
179
+ "hello-world-123".remove_dashes # => "helloworld123"
180
+ "hello world 123".remove_numbers # => "hello world "
181
+ "abc123xyz".keep_numbers # => "123"
182
+ "abc123xyz".keep_letters # => "abcxyz"
183
+ "Hello@World#123!".remove_special_chars # => "HelloWorld123"
184
+
185
+ # Conversion
186
+ "HelloWorld".to_snake_case # => "hello_world"
187
+ "hello_world".to_camel_case # => "helloWorld"
188
+
189
+ # Extraction
190
+ "Contact: test@example.com or admin@site.org".extract_emails
191
+ # => ["test@example.com", "admin@site.org"]
192
+
193
+ "Price is $123 or $456".extract_numbers # => ["123", "456"]
194
+
195
+ # Utilities
196
+ "Hello world, this is a test".word_count # => 6
197
+ "This is a very long string".truncate(15) # => "This is a ve..."
198
+
199
+ # Numeric Methods
200
+ 42.is_positive? # => true
201
+ -10.is_negative? # => true
202
+ 100.to_currency # => "$100"
203
+ 1234.to_formatted # => "1,234"
204
+ 0.75.to_percentage # => "75.0%"
205
+ ```
206
+
207
+ ## Development
208
+
209
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests.
210
+
211
+ To install this gem onto your local machine, run `bundle exec rake install`.
212
+
213
+ ## Contributing
214
+
215
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Derity/no_regex
216
+
217
+ ## License
218
+
219
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NoRegex
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
6
6
 
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: no_regex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
- - Your Name
7
+ - David Wright
8
8
  bindir: bin
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
@@ -54,7 +54,7 @@ dependencies:
54
54
  description: Replace complex regex patterns with simple, readable methods for string
55
55
  validation and manipulation
56
56
  email:
57
- - your.email@example.com
57
+ - derity@derity.com
58
58
  executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
@@ -67,13 +67,13 @@ files:
67
67
  - lib/no_regex/rails_validators.rb
68
68
  - lib/no_regex/string_extensions.rb
69
69
  - lib/no_regex/version.rb
70
- homepage: https://github.com/yourusername/no_regex
70
+ homepage: https://github.com/Derity/no_regex
71
71
  licenses:
72
72
  - MIT
73
73
  metadata:
74
- homepage_uri: https://github.com/yourusername/no_regex
75
- source_code_uri: https://github.com/yourusername/no_regex
76
- changelog_uri: https://github.com/yourusername/no_regex/blob/main/CHANGELOG.md
74
+ homepage_uri: https://github.com/Derity/no_regex
75
+ source_code_uri: https://github.com/Derity/no_regex
76
+ changelog_uri: https://github.com/Derity/no_regex/blob/main/CHANGELOG.md
77
77
  rdoc_options: []
78
78
  require_paths:
79
79
  - lib