everythingrb 0.6.1 → 0.8.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.
@@ -27,4 +27,5 @@ require "json"
27
27
  module Everythingrb
28
28
  end
29
29
 
30
+ require_relative "extensions"
30
31
  require_relative "version"
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Extensions to Ruby's core Range class
5
+ #
6
+ # Provides:
7
+ # - #in_quotes, #with_quotes: Wrap range representations in quotes
8
+ #
9
+ # @example
10
+ # require "everythingrb/range"
11
+ #
12
+ # (1..5).in_quotes # => "\"1..5\""
13
+ # ('a'..'z').in_quotes # => "\"a..z\""
14
+ #
15
+ # # Helpful in error messages:
16
+ # raise "Expected value in #{valid_range.in_quotes}"
17
+ #
18
+ class Range
19
+ include Everythingrb::InspectQuotable
20
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Extensions to Ruby's core Regexp class
5
+ #
6
+ # Provides:
7
+ # - #in_quotes, #with_quotes: Wrap regular expression representations in quotes
8
+ #
9
+ # @example
10
+ # require "everythingrb/regexp"
11
+ #
12
+ # /\d+/.in_quotes # => "\"/\\d+/\""
13
+ #
14
+ # # Useful in debugging output:
15
+ # puts "Pattern used: #{pattern.in_quotes}"
16
+ #
17
+ class Regexp
18
+ include Everythingrb::InspectQuotable
19
+ end
@@ -8,14 +8,18 @@
8
8
  # - #to_deep_h: Recursively parse nested JSON strings
9
9
  # - #to_ostruct, #to_istruct, #to_struct: Convert JSON to data structures
10
10
  # - #with_quotes, #in_quotes: Wrap strings in quotes
11
+ # - #to_camelcase: Convert strings to camelCase or PascalCase
11
12
  #
12
13
  # @example
13
14
  # require "everythingrb/string"
14
15
  #
15
16
  # '{"user": {"name": "Alice"}}'.to_ostruct.user.name # => "Alice"
16
17
  # "Hello".with_quotes # => "\"Hello\""
18
+ # "hello_world".to_camelcase # => "HelloWorld"
17
19
  #
18
20
  class String
21
+ include Everythingrb::StringQuotable
22
+
19
23
  #
20
24
  # Converts JSON string to Hash, returning nil if it failed
21
25
  #
@@ -38,6 +42,10 @@ class String
38
42
  # Recursively attempts to parse string values as JSON
39
43
  #
40
44
  # @return [Hash] Deeply parsed hash with all nested JSON strings converted
45
+ # @return [nil] If the string is not valid JSON at the top level
46
+ #
47
+ # @note If nested JSON strings fail to parse, they remain as strings
48
+ # rather than causing the entire operation to fail
41
49
  #
42
50
  # @example
43
51
  # nested_json = '{
@@ -113,17 +121,42 @@ class String
113
121
  end
114
122
 
115
123
  #
116
- # Returns self wrapped in double quotes
124
+ # Converts a string to camelCase or PascalCase
117
125
  #
118
- # @return [String] The string with surrounding double quotes
126
+ # Handles strings with spaces, hyphens, underscores, and special characters.
127
+ # - Hyphens and underscores are treated like spaces
128
+ # - Special characters and symbols are removed
129
+ # - Capitalizing each word (except the first if set)
119
130
  #
120
- # @example
121
- # "Hello World".with_quotes # => "\"Hello World\""
122
- # "Quote \"me\"".with_quotes # => "\"Quote \\\"me\\\"\""
131
+ # @param first_letter [Symbol] Whether the first letter should be uppercase (:upper)
132
+ # or lowercase (:lower)
133
+ #
134
+ # @return [String] The camelCased string
135
+ #
136
+ # @example Convert a string to PascalCase (default)
137
+ # "welcome to the jungle!".to_camelcase # => "WelcomeToTheJungle"
138
+ #
139
+ # @example Convert a string to camelCase (lowercase first)
140
+ # "welcome to the jungle!".to_camelcase(:lower) # => "welcomeToTheJungle"
123
141
  #
124
- def with_quotes
125
- %("#{self}")
142
+ # @example With mixed formatting
143
+ # "please-WAIT while_loading...".to_camelcase # => "PleaseWaitWhileLoading"
144
+ #
145
+ # @see String#capitalize
146
+ # @see String#downcase
147
+ #
148
+ def to_camelcase(first_letter = :upper)
149
+ gsub(/[-_]/, " ") # Treat dash/underscore as new words so they are capitalized
150
+ .gsub(/[^a-zA-Z0-9\s]/, "") # Remove any special characters
151
+ .split(/\s+/) # Split by word (removes extra whitespace)
152
+ .map # Don't use `join_map(with_index: true)`, this is faster
153
+ .with_index do |word, index| # Convert the words
154
+ if index == 0 && first_letter == :lower
155
+ word.downcase
156
+ else
157
+ word.capitalize
158
+ end
159
+ end
160
+ .join # And join it back together
126
161
  end
127
-
128
- alias_method :in_quotes, :with_quotes
129
162
  end
@@ -5,6 +5,7 @@
5
5
  #
6
6
  # Provides:
7
7
  # - #to_deep_h: Recursively convert to hash with all nested objects
8
+ # - #in_quotes, #with_quotes: Wrap struct in quotes
8
9
  #
9
10
  # @example
10
11
  # require "everythingrb/struct"
@@ -14,9 +15,15 @@
14
15
  # person.to_deep_h # => {name: "Alice", profile: {roles: ["admin"]}}
15
16
  #
16
17
  class Struct
18
+ include Everythingrb::InspectQuotable
19
+
17
20
  #
18
21
  # Recursively converts the Struct and all nested objects to hashes
19
22
  #
23
+ # This method traverses the entire Struct structure, converting not just
24
+ # the top-level Struct but also nested Structs, OpenStructs, Data objects,
25
+ # and any other objects that implement `to_h`.
26
+ #
20
27
  # @return [Hash] A deeply converted hash of the Struct
21
28
  #
22
29
  # @example
@@ -18,12 +18,12 @@ class Symbol
18
18
  # @return [Symbol] The symbol with surrounding double quotes
19
19
  #
20
20
  # @example
21
- # :hello_world.with_quotes # => :"\"hello_world\""
21
+ # :hello_world.in_quotes # => :"\"hello_world\""
22
22
  # :hello_world.in_quotes # => :"\"hello_world\""
23
23
  #
24
- def with_quotes
24
+ def in_quotes
25
25
  :"\"#{self}\""
26
26
  end
27
27
 
28
- alias_method :in_quotes, :with_quotes
28
+ alias_method :with_quotes, :in_quotes
29
29
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Extensions to Ruby's core Time class
5
+ #
6
+ # Provides:
7
+ # - #in_quotes, #with_quotes: Wrap time representations in quotes
8
+ #
9
+ # @example
10
+ # require "everythingrb/time"
11
+ #
12
+ # Time.new(2025, 5, 3).in_quotes # => "\"2025-05-03 00:00:00 +0000\""
13
+ #
14
+ # # Useful in formatted output:
15
+ # "Event created at #{Time.now.in_quotes}"
16
+ #
17
+ class Time
18
+ include Everythingrb::StringQuotable
19
+ end
@@ -7,5 +7,5 @@
7
7
  #
8
8
  module Everythingrb
9
9
  # Current version of the everythingrb gem
10
- VERSION = "0.6.1"
10
+ VERSION = "0.8.0"
11
11
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: everythingrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-04-26 00:00:00.000000000 Z
11
+ date: 2025-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ostruct
@@ -59,15 +59,25 @@ files:
59
59
  - lib/everythingrb.rb
60
60
  - lib/everythingrb/all.rb
61
61
  - lib/everythingrb/array.rb
62
+ - lib/everythingrb/boolean.rb
62
63
  - lib/everythingrb/data.rb
64
+ - lib/everythingrb/date.rb
63
65
  - lib/everythingrb/enumerable.rb
66
+ - lib/everythingrb/extensions.rb
67
+ - lib/everythingrb/extensions/quotable.rb
64
68
  - lib/everythingrb/hash.rb
69
+ - lib/everythingrb/kernel.rb
65
70
  - lib/everythingrb/module.rb
71
+ - lib/everythingrb/nil.rb
72
+ - lib/everythingrb/numeric.rb
66
73
  - lib/everythingrb/ostruct.rb
67
74
  - lib/everythingrb/prelude.rb
75
+ - lib/everythingrb/range.rb
76
+ - lib/everythingrb/regexp.rb
68
77
  - lib/everythingrb/string.rb
69
78
  - lib/everythingrb/struct.rb
70
79
  - lib/everythingrb/symbol.rb
80
+ - lib/everythingrb/time.rb
71
81
  - lib/everythingrb/version.rb
72
82
  homepage: https://github.com/itsthedevman/everythingrb
73
83
  licenses: