Class: Gtmtech::Crypto::Utils
- Inherits:
-
Object
- Object
- Gtmtech::Crypto::Utils
- Defined in:
- lib/gtmtech/crypto/utils.rb
Class Method Summary collapse
- .camelcase(string) ⇒ Object
- .decimal_add(decimal1, decimal2) ⇒ Object
- .decimal_divide(decimal1, decimal2) ⇒ Object
- .decimal_equal?(decimal1, decimal2) ⇒ Boolean
- .decimal_minus(decimal1, decimal2) ⇒ Object
- .decimal_multiply(decimal1, decimal2, decimal3 = "1.0") ⇒ Object
- .find_all_subclasses_of(args) ⇒ Object
- .find_closest_class(args) ⇒ Object
- .make_decimal(digits) ⇒ Object
- .require_dir(classdir) ⇒ Object
- .snakecase(string) ⇒ Object
Class Method Details
.camelcase(string) ⇒ Object
8 9 10 11 |
# File 'lib/gtmtech/crypto/utils.rb', line 8 def self.camelcase string return string if string !~ /_/ && string =~ /[A-Z]+.*/ string.split('_').map{|e| e.capitalize}.join end |
.decimal_add(decimal1, decimal2) ⇒ Object
62 63 64 |
# File 'lib/gtmtech/crypto/utils.rb', line 62 def self.decimal_add decimal1, decimal2 ( BigDecimal( decimal1 ) + BigDecimal( decimal2 ) ).truncate(8).to_s("F") end |
.decimal_divide(decimal1, decimal2) ⇒ Object
74 75 76 |
# File 'lib/gtmtech/crypto/utils.rb', line 74 def self.decimal_divide decimal1, decimal2 ( BigDecimal( decimal1 ) / BigDecimal( decimal2 ) ).truncate(8).to_s("F") end |
.decimal_equal?(decimal1, decimal2) ⇒ Boolean
78 79 80 |
# File 'lib/gtmtech/crypto/utils.rb', line 78 def self.decimal_equal? decimal1, decimal2 BigDecimal( decimal1 ) == BigDecimal( decimal2 ) end |
.decimal_minus(decimal1, decimal2) ⇒ Object
66 67 68 |
# File 'lib/gtmtech/crypto/utils.rb', line 66 def self.decimal_minus decimal1, decimal2 ( BigDecimal( decimal1 ) - BigDecimal( decimal2 ) ).truncate(8).to_s("F") end |
.decimal_multiply(decimal1, decimal2, decimal3 = "1.0") ⇒ Object
70 71 72 |
# File 'lib/gtmtech/crypto/utils.rb', line 70 def self.decimal_multiply decimal1, decimal2, decimal3 = "1.0" ( BigDecimal( decimal1 ) * BigDecimal( decimal2 ) * BigDecimal( decimal3 ) ).truncate(8).to_s("F") end |
.find_all_subclasses_of(args) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/gtmtech/crypto/utils.rb', line 42 def self.find_all_subclasses_of args parent_class = args[ :parent_class ] constants = parent_class.constants candidates = [] constants.each do | candidate | candidates << candidate.to_s.split('::').last if parent_class.const_get(candidate).class.to_s == "Class" end candidates end |
.find_closest_class(args) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/gtmtech/crypto/utils.rb', line 18 def self.find_closest_class args parent_class = args[ :parent_class ] class_name = args[ :class_name ] constants = parent_class.constants candidates = [] constants.each do | candidate | candidates << candidate.to_s if candidate.to_s.downcase == class_name.downcase end if candidates.count > 0 parent_class.const_get candidates.first else nil end end |
.make_decimal(digits) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/gtmtech/crypto/utils.rb', line 52 def self.make_decimal digits if digits.start_with? "." "0#{digits}" elsif digits =~ /^\d+$/ "#{digits}.0" else digits end end |
.require_dir(classdir) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/gtmtech/crypto/utils.rb', line 33 def self.require_dir classdir num_class_hierarchy_levels = self.to_s.split("::").count - 1 root_folder = File.dirname(__FILE__) + "/" + Array.new(num_class_hierarchy_levels).fill("..").join("/") class_folder = root_folder + "/" + classdir Dir[File.("#{class_folder}/*.rb")].uniq.each do |file| require file end end |
.snakecase(string) ⇒ Object
13 14 15 16 |
# File 'lib/gtmtech/crypto/utils.rb', line 13 def self.snakecase string return string if string !~ /[A-Z]/ string.split(/(?=[A-Z])/).collect {|x| x.downcase}.join("_") end |