ruby-lambdas 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +34 -2
- data/lib/ruby/lambdas/strings.rb +0 -1
- data/lib/ruby/lambdas/strings/to_export.rb +4 -1
- data/lib/ruby/lambdas/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19c424e1936c0b793d84a5401fe16e61ef506c0ce6b8973095bfe69877078748
|
4
|
+
data.tar.gz: 238ecf3f90787dd2094ed1c07018755f3f7b5c0f6ead52eac76d7d344a790441
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 62eb3e3f36731b625d4629b24b6d6bed9b76643f8c6ae5e3ea8f3eb194a7b51e6170c062430bd82c4dda21fdcd404a49b0008238371a5239bdd0002c90c001f5
|
7
|
+
data.tar.gz: baf613b0646136602049d21c32de3bac40eb69893d015f9609c17f26b053fc6af67266eb65f8aede2565366fd88b7cd147a54885eb2c6ef7180987b6c5f0cc1d
|
data/README.md
CHANGED
@@ -9,7 +9,7 @@ TODO: Delete this and the text above, and describe your gem
|
|
9
9
|
Add this line to your application's Gemfile:
|
10
10
|
|
11
11
|
```ruby
|
12
|
-
gem 'ruby-lambdas'
|
12
|
+
gem 'ruby-lambdas', '~> 0.1.0', require: 'ruby/lambdas'
|
13
13
|
```
|
14
14
|
|
15
15
|
And then execute:
|
@@ -22,7 +22,39 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
25
|
+
**Basics:**
|
26
|
+
```ruby
|
27
|
+
require "ruby/lambdas"
|
28
|
+
|
29
|
+
Strings::Strip.call(" hello ") # => "hello"
|
30
|
+
|
31
|
+
# Strings::Trim is an alias to the Strings::Strip function
|
32
|
+
Strings::Trim.call(" hello ") # => "hello"
|
33
|
+
```
|
34
|
+
|
35
|
+
**Composing functions (`RUBY_VERSION >= '2.6.0'`):**
|
36
|
+
```ruby
|
37
|
+
require "ruby/lambdas"
|
38
|
+
# -- Alternative syntax --
|
39
|
+
Slugify = # Slugify =
|
40
|
+
Strings::FromObject # Strings::String
|
41
|
+
.>> Strings::Strip # >> Strings::Trim \
|
42
|
+
.>> Strings::LowerCase # >> Strings::LowerCase \
|
43
|
+
.>> Strings::GSub[' ', '-'] # >> Strings::ReplaceAll[' ', '-']
|
44
|
+
|
45
|
+
# Reading the previous composition (Step by step)
|
46
|
+
# 1. Convert a given object (first input) as a String
|
47
|
+
# 2. Remove all whitespaces from both sides of a string.
|
48
|
+
# 3. Convert a string to all lower case.
|
49
|
+
# 4. Replace all occurrences of " " by "-".
|
50
|
+
|
51
|
+
# Usage
|
52
|
+
|
53
|
+
Slugify.(nil) # => ""
|
54
|
+
Slugify.(1) # => "1"
|
55
|
+
Slugify.(1.0) # => "1.0"
|
56
|
+
Slugify.(' I WILL be a url slug ') # => "i-will-be-a-url-slug"
|
57
|
+
```
|
26
58
|
|
27
59
|
## Development
|
28
60
|
|
data/lib/ruby/lambdas/strings.rb
CHANGED
@@ -9,6 +9,8 @@ module RubyLambdas
|
|
9
9
|
|
10
10
|
Downcase = -> data { data.downcase }
|
11
11
|
|
12
|
+
FromObject = -> data { String(data) }
|
13
|
+
|
12
14
|
GSub = -> (pattern, replacement, data) do
|
13
15
|
return data.gsub(pattern, &replacement) if replacement.is_a?(::Proc)
|
14
16
|
|
@@ -19,8 +21,9 @@ module RubyLambdas
|
|
19
21
|
end
|
20
22
|
|
21
23
|
ALIASES = {
|
22
|
-
GSub: :ReplaceAll,
|
23
24
|
Downcase: :LowerCase,
|
25
|
+
FromObject: :String,
|
26
|
+
GSub: :ReplaceAll,
|
24
27
|
Strip: :Trim,
|
25
28
|
}.freeze
|
26
29
|
end
|
data/lib/ruby/lambdas/version.rb
CHANGED