Class: Iugu::Utils
- Inherits:
-
Object
- Object
- Iugu::Utils
- Defined in:
- lib/iugu/utils.rb
Class Method Summary collapse
- .auth_from_env ⇒ Object
- .camelize(string) ⇒ Object
- .intersect(array, another_hash) ⇒ Object
- .stringify_keys(hash) ⇒ Object
- .underscore(string) ⇒ Object
Class Method Details
.auth_from_env ⇒ Object
3 4 5 6 |
# File 'lib/iugu/utils.rb', line 3 def self.auth_from_env api_key = ENV['IUGU_API_KEY'] Iugu.api_key = api_key if api_key end |
.camelize(string) ⇒ Object
23 24 25 |
# File 'lib/iugu/utils.rb', line 23 def self.camelize(string) string.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase } end |
.intersect(array, another_hash) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/iugu/utils.rb', line 8 def self.intersect(array, another_hash) keys_intersection = array & another_hash.keys intersection = {} keys_intersection.each {|k| intersection[k] = another_hash[k]} intersection end |
.stringify_keys(hash) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/iugu/utils.rb', line 27 def self.stringify_keys(hash) new_hash = {} hash.each do |key, value| if value.is_a? Hash new_hash[key.to_s] = stringify_keys(value) else new_hash[key.to_s] = value end end new_hash end |
.underscore(string) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/iugu/utils.rb', line 15 def self.underscore(string) string.gsub(/::/, '/'). gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). tr("-", "_"). downcase end |