lite-ruby 1.0.0 → 1.0.1

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: 329151a0021c9f782b6c9b32c60401cd35e2f94d73b24a69d5e6d48ff3c29fce
4
- data.tar.gz: 96f11da93a7a669dd1f356022a39cd1c4456a22b3afda67562f46c19b63db794
3
+ metadata.gz: ebfe63ca0039bd6f048350883e4561c313c846cdd223bcb1bc08e19d3203c8ff
4
+ data.tar.gz: 2b0cec21a13746667b3afaba2936f33928b8d9c368efd13a88312de8c54f2341
5
5
  SHA512:
6
- metadata.gz: 66527e6752355b6374ba751ee3dd67dcc17fa4b340dc009d7d3e6e54e24345d668f8d911b9fb67fdaed74d0ee92c7e10451394946bce1faebb9a5a85caf3d39d
7
- data.tar.gz: 48b9b357661552e2c0664a1c49ce66ad9bcb7c96b36a7d791932971f30ce940dda9343fdeedcea999778b816f9b86d20fcafe9204b90a04e32b0992cd03bf85e
6
+ metadata.gz: 26e0c61e5539fd9b9691c62ec69bf942e79f08a2cc3d571a09ad337572c406637098ad0f86b50aaf5a40c138109c1898134c2a206cb09e1039c559a932c97b67
7
+ data.tar.gz: 47643cd5b5026e8e8edad9291d4528dc4739ffb1be2406713eb0b384f95e9bf39f0701540b74033067dbf8db77b24e5c02bcae8dbe639c956e77cbcaa35e3528
@@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.0.1] - 2019-07-12
10
+ ### Added
11
+ - Added String => `acronym`
12
+ - Added Struct extensions
13
+ - Added Time => `elapse`
14
+ # Changed
15
+ - Configuration
16
+
9
17
  ## [1.0.0] - 2019-07-12
10
18
  ### Added
11
19
  - Initial project version
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lite-ruby (1.0.0)
4
+ lite-ruby (1.0.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -37,17 +37,9 @@ Or install it yourself as:
37
37
 
38
38
  ```ruby
39
39
  Lite::Ruby.configure do |config|
40
- config.array = true
41
- config.date = true
42
- config.enumerable = true
43
- config.hash = true
44
- config.integer = true
45
- config.kernel = true
46
- config.numeric = true
47
- config.object = true
48
- config.range = true
49
- config.string = true
50
- config.time = true
40
+ config.monkey_patches = %w[
41
+ array date enumerable hash integer kernel numeric object range string struct time
42
+ ]
51
43
  end
52
44
  ```
53
45
 
@@ -63,15 +55,16 @@ end
63
55
  * [Object](https://github.com/drexed/lite-ruby/blob/master/docs/OBJECT.md)
64
56
  * [Range](https://github.com/drexed/lite-ruby/blob/master/docs/RANGE.md)
65
57
  * [String](https://github.com/drexed/lite-ruby/blob/master/docs/STRING.md)
58
+ * [Struct](https://github.com/drexed/lite-ruby/blob/master/docs/STRUCT.md)
66
59
  * [Time](https://github.com/drexed/lite-ruby/blob/master/docs/TIME.md)
67
60
 
68
61
  ## 3rd-party
69
62
 
70
63
  The following are highly recommended 3rd-party extensions to supplement your workflow:
71
64
 
72
- * **String:** Escape Utils - https://github.com/brianmario/escape_utils
73
- * **String:** Fast Blank - https://github.com/SamSaffron/fast_blank
74
- * **Primitives:** Facets - https://github.com/rubyworks/facets
65
+ * **Performance:** Escape Utils - https://github.com/brianmario/escape_utils
66
+ * **Performance:** Fast Blank - https://github.com/SamSaffron/fast_blank
67
+ * **Extensions:** Facets - https://github.com/rubyworks/facets
75
68
 
76
69
  ## Port
77
70
 
@@ -1,5 +1,13 @@
1
1
  # String
2
2
 
3
+ `acronym(!)`
4
+ ------
5
+ Returns the first letter of each word without spaces.
6
+
7
+ ```ruby
8
+ 'example string'.acronym #=> 'es'
9
+ ```
10
+
3
11
  `any?`
4
12
  ------
5
13
  Returns if a string includes a set of string(s).
@@ -0,0 +1,24 @@
1
+ # Struct
2
+
3
+ `attributes`
4
+ ------
5
+ Returns the key values of the assigned struct.
6
+
7
+ ```ruby
8
+ person = Struct.new(:name, :age)
9
+ person.new('bob', 60)
10
+
11
+ person.attributes #=> { name: 'bob', age: 60 }
12
+ ```
13
+
14
+ `replace`
15
+ ------
16
+ Replaces values provided within the hash.
17
+
18
+ ```ruby
19
+ person = Struct.new(:name, :age)
20
+ person.new('bob', 60)
21
+
22
+ person.replace(name: 'tom', age: 28)
23
+ preson.name #=> 'tom'
24
+ ```
@@ -84,3 +84,11 @@ Converts a `time` object to a predefined format.
84
84
  ```ruby
85
85
  Time.now.stamp(:datetime) #=> 'January 09, 2014 02:31 pm'
86
86
  ```
87
+
88
+ `elapse`
89
+ ------
90
+ Returns the amount of time taken to execute a block.
91
+
92
+ ```ruby
93
+ Time.elapse { sleep 1 } #=> 1.00005465
94
+ ```
@@ -1,15 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  Lite::Ruby.configure do |config|
4
- config.array = true
5
- config.date = true
6
- config.enumerable = true
7
- config.hash = true
8
- config.integer = true
9
- config.kernel = true
10
- config.numeric = true
11
- config.object = true
12
- config.range = true
13
- config.string = true
14
- config.time = true
4
+ config.monkey_patches = %w[
5
+ array date enumerable hash integer kernel numeric object range string struct time
6
+ ]
15
7
  end
@@ -1,15 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'lite/ruby/version'
4
- require 'lite/ruby/configuration'
3
+ %w[version configuration].each do |filename|
4
+ require "lite/ruby/#{filename}"
5
+ end
5
6
 
6
7
  %w[date time].each do |filename|
7
8
  require "lite/ruby/helpers/#{filename}_helper"
8
9
  end
9
10
 
10
- %w[array date enumerable hash integer kernel numeric object range string time].each do |filename|
11
- next unless Lite::Ruby.configuration.send(filename)
12
-
11
+ Lite::Ruby.configuration.monkey_patches.each do |filename|
13
12
  require "lite/ruby/#{filename}"
14
13
  end
15
14
 
@@ -5,24 +5,13 @@ module Lite
5
5
 
6
6
  class Configuration
7
7
 
8
- attr_accessor :array, :date, :enumerable, :hash, :integer, :kernel, :numeric, :object, :range,
9
- :string, :time
8
+ attr_accessor :monkey_patches
10
9
 
11
- # rubocop:disable Metrics/MethodLength
12
10
  def initialize
13
- @array = true
14
- @date = true
15
- @enumerable = true
16
- @hash = true
17
- @integer = true
18
- @kernel = true
19
- @numeric = true
20
- @object = true
21
- @range = true
22
- @string = true
23
- @time = true
11
+ @monkey_patches = %w[
12
+ array date enumerable hash integer kernel numeric object range string struct time
13
+ ]
24
14
  end
25
- # rubocop:enable Metrics/MethodLength
26
15
 
27
16
  end
28
17
 
@@ -32,6 +32,14 @@ class String
32
32
  'Ÿ' => 'Y', 'Ź' => 'Z', 'ź' => 'z', 'Ż' => 'Z', 'ż' => 'z', 'Ž' => 'Z', 'ž' => 'z'
33
33
  }.freeze
34
34
 
35
+ def acronym
36
+ gsub(/(([a-zA-Z0-9])([a-zA-Z0-9])*)./, '\\2')
37
+ end
38
+
39
+ def acronym!
40
+ replace(acronym)
41
+ end
42
+
35
43
  def any?(*keys)
36
44
  keys.any? { |key| include?(key) }
37
45
  end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: false
2
+
3
+ class Struct
4
+
5
+ def attributes
6
+ each_pair.with_object({}) { |(key, val), hash| hash[key] = val }
7
+ end
8
+
9
+ def replace(args)
10
+ args.each_pair { |key, val| send("#{key}=", val) }
11
+ end
12
+
13
+ end
@@ -5,6 +5,16 @@ class Time
5
5
  include Lite::Ruby::DateHelper
6
6
  include Lite::Ruby::TimeHelper
7
7
 
8
+ class << self
9
+
10
+ def elapse
11
+ time = now.to_f
12
+ yield
13
+ now.to_f - time
14
+ end
15
+
16
+ end
17
+
8
18
  private
9
19
 
10
20
  def default_format
@@ -3,7 +3,7 @@
3
3
  module Lite
4
4
  module Ruby
5
5
 
6
- VERSION ||= '1.0.0'
6
+ VERSION ||= '1.0.1'
7
7
 
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lite-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Gomez
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-07-12 00:00:00.000000000 Z
11
+ date: 2019-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -154,6 +154,7 @@ files:
154
154
  - docs/OBJECT.md
155
155
  - docs/RANGE.md
156
156
  - docs/STRING.md
157
+ - docs/STRUCT.md
157
158
  - docs/TIME.md
158
159
  - lib/generators/lite/ruby/install_generator.rb
159
160
  - lib/generators/lite/ruby/templates/install.rb
@@ -171,6 +172,7 @@ files:
171
172
  - lib/lite/ruby/object.rb
172
173
  - lib/lite/ruby/range.rb
173
174
  - lib/lite/ruby/string.rb
175
+ - lib/lite/ruby/struct.rb
174
176
  - lib/lite/ruby/time.rb
175
177
  - lib/lite/ruby/version.rb
176
178
  - lite-ruby.gemspec