megli_common_helper 1.0.0 → 1.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d8960ca308d19b4e60fa5f2f0cc5a31f158502f8
4
- data.tar.gz: 7c8c9687a7dc4f52b587630683979b0b1ac8dce8
3
+ metadata.gz: 26681f16a21e628a78982e6ceb0db964e808c6db
4
+ data.tar.gz: 89e2db73e4df160b41784753b4dec3fa6be4f47e
5
5
  SHA512:
6
- metadata.gz: 9a63f292c37244df21f5e05c2f964d54fed14de174684110d63fb1934874ee4ba7c2d31dab2877b9002ee905a7889a33f5ee176aa5c595f2014167fac5ba5e69
7
- data.tar.gz: 881cb7e32fc929de8da8481eba349013b4d66e4b52d38e2a61c975bc8d9c207ace1711f1525d88f01d62bf2d2970adf6606ea7ab71310c7b8c212d50b39437cb
6
+ metadata.gz: 41f35beb21037d9839ca341d2b5bebecd160d00289500f1b1fc59275c6d5c11a3007aa2ba6dc433f8539cd2d2ac650f15e7209f544693da6b5565ddcc457dc20
7
+ data.tar.gz: f7a21459b0ff201966778c9eb0e295538e1aa728b9e57c884f69d05f54d3a33dfb09096f6736a26738081031038fb1ceb8a2d8c6c6d04a1caedf664efc15ba2c
@@ -1,67 +1,62 @@
1
- module MegliCommonHelper
1
+ require 'json'
2
+ require 'timeout'
2
3
 
3
- require 'json'
4
- require 'timeout'
5
-
6
- class CommonHelper
7
- private_class_method :new
8
-
9
- # Check if text is null or empty
10
- # @param text [String] text to be checked
11
- # @return [Boolean] true if text is nil or empty and false if not
12
- def self.nil_or_empty?(text)
13
- (text.nil? || text.to_s.empty? || text.empty?)
14
- rescue
15
- false
16
- end
4
+ class MegliHelper::CommonHelper
5
+ # Check if text is null or empty
6
+ # @param text [String] text to be checked
7
+ # @return [Boolean] true if text is nil or empty and false if not
8
+ def self.nil_or_empty?(text)
9
+ (text.nil? || text.to_s.empty? || text.empty?)
10
+ rescue
11
+ false
12
+ end
17
13
 
18
- # Convert string value to boolean
19
- # @param value [String] value to be converted
20
- # @return [Boolean][nil] if string is not a valid boolean it will return nil
21
- def self.to_boolean(value)
22
- return false if nil_or_empty? value
23
- return true if %w(true 1 y yes).include? value.to_s.downcase.strip
24
- return false if %w(false 0 n no).include? value.to_s.downcase.strip
25
- false
26
- rescue
27
- false
28
- end
14
+ # Convert string value to boolean
15
+ # @param value [String] value to be converted
16
+ # @return [Boolean][nil] if string is not a valid boolean it will return nil
17
+ def self.to_boolean(value)
18
+ return false if nil_or_empty? value
19
+ return true if %w(true 1 y yes).include? value.to_s.downcase.strip
20
+ return false if %w(false 0 n no).include? value.to_s.downcase.strip
21
+ false
22
+ rescue
23
+ false
24
+ end
29
25
 
30
- # Transform float value to a decimal formatted
31
- # @param decimal [Float] value to be formatted
32
- # @param decimal_format formmated used to format the value
33
- # @param currency [String] currency signal to be included in the decimal like: $, £, R$, etc.
34
- # @param currency_before [Boolean] where the currency must be included (before or after decimal)
35
- # @return [String] decimal formatted
36
- def self.to_decimal(decimal, decimal_format = '%8.2f', currency = nil, currency_before = true)
37
- new_decimal = (decimal_format % decimal).strip
38
- unless nil_or_empty?(currency)
39
- return currency + new_decimal if currency_before
40
- return new_decimal + currency
41
- end
42
- new_decimal
26
+ # Transform float value to a decimal formatted
27
+ # @param decimal [Float] value to be formatted
28
+ # @param decimal_format formmated used to format the value
29
+ # @param currency [String] currency signal to be included in the decimal like: $, £, R$, etc.
30
+ # @param currency_before [Boolean] where the currency must be included (before or after decimal)
31
+ # @return [String] decimal formatted
32
+ def self.to_decimal(decimal, decimal_format = '%8.2f', currency = nil, currency_before = true)
33
+ new_decimal = (decimal_format % decimal).strip
34
+ unless nil_or_empty?(currency)
35
+ return currency + new_decimal if currency_before
36
+ return new_decimal + currency
43
37
  end
38
+ new_decimal
39
+ end
44
40
 
45
- # Check if the JSON passed is valid or not
46
- # @param json [String] json to be verified
47
- # @return [Boolean] is valid or not
48
- def self.valid_json?(json)
49
- return false if nil_or_empty? json
50
- JSON.parse(json)
51
- true
52
- rescue
53
- false
54
- end
41
+ # Check if the JSON passed is valid or not
42
+ # @param json [String] json to be verified
43
+ # @return [Boolean] is valid or not
44
+ def self.valid_json?(json)
45
+ return false if nil_or_empty? json
46
+ JSON.parse(json)
47
+ true
48
+ rescue
49
+ false
50
+ end
55
51
 
56
- # Wait until a condition passed happen
57
- # @param condition [Proc] condition block to be validated
58
- # @param condition_status [Boolean] condition status to be used to define if condition is satisfied or not
59
- # @param timeout [Integer] timeout to wait for the condition happen
60
- # @param sleep_for [Float] value used to call the condition block
61
- def self.wait_until_condition(condition, condition_status = true, timeout = 20, sleep_for = 0.25)
62
- Timeout.timeout(timeout) do
63
- sleep sleep_for until condition.call == condition_status
64
- end
52
+ # Wait until a condition passed happen
53
+ # @param condition [Proc] condition block to be validated
54
+ # @param condition_status [Boolean] condition status to be used to define if condition is satisfied or not
55
+ # @param timeout [Integer] timeout to wait for the condition happen
56
+ # @param sleep_for [Float] value used to call the condition block
57
+ def self.wait_until_condition(condition, condition_status = true, timeout = 20, sleep_for = 0.25)
58
+ Timeout.timeout(timeout) do
59
+ sleep sleep_for until condition.call == condition_status
65
60
  end
66
61
  end
67
62
  end
@@ -1,34 +1,29 @@
1
- module MegliCommonHelper
2
- require 'time'
3
- class TimeHelper
1
+ require 'time'
4
2
 
5
- private_class_method :new
6
-
7
- # Change timezone of a time passed
8
- # @param time [Time][String] time to be changed
9
- # @param timezone [String] timezone to be set in the time
10
- # @return [Time] time with a new timezone
11
- def self.change_timezone(time, timezone = '+00:00')
12
- time = Time.parse(time) if time.class == String
13
- time.localtime(timezone)
14
- end
3
+ class MegliHelper::TimeHelper
4
+ # Change timezone of a time passed
5
+ # @param time [Time][String] time to be changed
6
+ # @param timezone [String] timezone to be set in the time
7
+ # @return [Time] time with a new timezone
8
+ def self.change_timezone(time, timezone = '+00:00')
9
+ time = Time.parse(time) if time.class == String
10
+ time.localtime(timezone)
11
+ end
15
12
 
16
- # Get time now with addinional minutes and convert it to format passed
17
- # @param format [Symbol] time format. Default value: :iso8601
18
- # @param add_minutes [Integer] quantity of minutes to sum
19
- # @return [String] time formatted
20
- def self.get_time(format = :iso8601, add_minutes = 0)
21
- return nil if add_minutes.nil?
22
- add_minutes = add_minutes.to_i if add_minutes.class == String
23
- time = Time.now + (60 * add_minutes)
24
- unless format.nil?
25
- time = time.iso8601 if format == :iso8601
26
- time = time.utc if format == :utc
27
- time = time.rfc822 if format == :rfc822 || format == :rfc2822
28
- time = time.ctime if format == :ctime
29
- end
30
- time
13
+ # Get time now with addinional minutes and convert it to format passed
14
+ # @param format [Symbol] time format. Default value: :iso8601
15
+ # @param add_minutes [Integer] quantity of minutes to sum
16
+ # @return [String] time formatted
17
+ def self.get_time(format = :iso8601, add_minutes = 0)
18
+ return nil if add_minutes.nil?
19
+ add_minutes = add_minutes.to_i if add_minutes.class == String
20
+ time = Time.now + (60 * add_minutes)
21
+ unless format.nil?
22
+ time = time.iso8601 if format == :iso8601
23
+ time = time.utc if format == :utc
24
+ time = time.rfc822 if format == :rfc822 || format == :rfc2822
25
+ time = time.ctime if format == :ctime
31
26
  end
32
-
27
+ time
33
28
  end
34
29
  end
@@ -0,0 +1,5 @@
1
+ class MegliHelper
2
+ end
3
+
4
+ require 'helpers/common_helper'
5
+ require 'helpers/time_helper'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: megli_common_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduardo Gomes Heinen
@@ -18,6 +18,7 @@ extra_rdoc_files: []
18
18
  files:
19
19
  - lib/helpers/common_helper.rb
20
20
  - lib/helpers/time_helper.rb
21
+ - lib/megli_helper.rb
21
22
  homepage: http://rubygems.org/gems/megli-common-helper
22
23
  licenses:
23
24
  - MIT