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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bca2634a3d9d56135930a816cdc3b4abe043be6130405153c486ab143c2cab55
4
- data.tar.gz: 5443e9adbcc213df2b17ddf24569829d3835b93a3bfde038484521d6df0cc4f0
3
+ metadata.gz: 19c424e1936c0b793d84a5401fe16e61ef506c0ce6b8973095bfe69877078748
4
+ data.tar.gz: 238ecf3f90787dd2094ed1c07018755f3f7b5c0f6ead52eac76d7d344a790441
5
5
  SHA512:
6
- metadata.gz: e00af2a28ac449e76aa1c3b6ee4b54784d29b80b403b4e7662f707cb23ccbcdb7ad4ede7d37fec04eac197a61fe8997bad97daf947fa0926f6cc6d977bac6299
7
- data.tar.gz: 45836173efbc31995aba5ec32042653b87ffb6008e99a1a5feffc118d5e1cfeb1d7230fa4dbf385262ba26916f4c0669416e16ca9de4071a1ce5e486c284e1a8
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
- TODO: Write usage instructions here
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
 
@@ -4,7 +4,6 @@ module Strings
4
4
  RubyLambdas::Strings::ToExport.tap do |to_export|
5
5
  to_export
6
6
  .constants
7
- .reject { |const| const == :ALIASES }
8
7
  .each do |function_name|
9
8
  function = to_export.const_get(function_name)
10
9
 
@@ -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
@@ -1,3 +1,3 @@
1
1
  module RubyLambdas
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-lambdas
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rodrigo Serradura