Module: Isaca::Helpers

Defined in:
lib/isaca/helpers.rb

Overview

A series of helper methods for parsing the way ISACA sends some data.

Class Method Summary collapse

Class Method Details

.normalize_member_type(type) ⇒ Symbol

ISACA has an abbreviated member type and this method will break down those abbreviations into one of the three primary types: member, non_member or student.

Parameters:

  • type (String)

    The abbreviated member type.

Returns:

  • (Symbol)

    :member, :non_member or :student.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/isaca/helpers.rb', line 33

def self.normalize_member_type(type)
  return :non_member if type.nil?

  case type.upcase
    when 'COMP' then :member
    when 'LIFE' then :member
    when 'STUM' then :student
    when 'PENS' then :student
    when 'RG1' then :member
    when 'RG2' then :member
    when 'RETM' then :member
    when 'UADV' then :member
    when 'MEM' then :member
    when 'PEND' then :member
    when 'PENRG' then :member
    when 'EMPL' then :member
    else :non_member
  end
end

.parse_boolean(string) ⇒ Object

ISACA passes booleans as a string representation, this method helps parse these representations.

Parameters:

  • string (String)

    The string representation of a boolean. (e.g. “True”, “false”, “False”). If nil this method will return false.



23
24
25
26
# File 'lib/isaca/helpers.rb', line 23

def self.parse_boolean(string)
  return false if string.nil?
  string.downcase == 'true' ? true : false
end

.strptime(string_time, format = '%m/%d/%Y %I:%M:%S %p') ⇒ DateTime

ISACA seems to use the default format to pass datetimes. This method exists so you don’t have to remember the parse format.

Parameters:

  • string_time (String)

    The time passed by ISACA.

  • format (String) (defaults to: '%m/%d/%Y %I:%M:%S %p')

    The format of the time.

Returns:

  • (DateTime)


14
15
16
# File 'lib/isaca/helpers.rb', line 14

def self.strptime(string_time, format='%m/%d/%Y %I:%M:%S %p')
  (string_time.nil? || string_time.empty?) ? nil : DateTime.strptime(string_time, format)
end