Class: Institution

Inherits:
Struct
  • Object
show all
Defined in:
lib/authpds/institution.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(h = {}) ⇒ Institution

Better initializer than Struct gives us, take a hash instead of an ordered array. :services=>[] is an array of service ids, not actual Services!



8
9
10
11
12
13
14
15
16
# File 'lib/authpds/institution.rb', line 8

def initialize(h={})
  members.each {|m| self.send( ("#{m}=").to_sym , (h.delete("#{m}".to_sym) || h.delete("#{m}"))) }
  # If the institution is named default, take that as an
  # indication that it's the default institution
  self.default= true if name == "default" or name == "DEFAULT"
  self.default= false unless default
  # Log the fact that there are left overs in the hash
  # Rails.logger.warn("The following institution settings were ignored: #{h.inspect}.") unless h.empty?
end

Instance Attribute Details

#defaultObject

Returns the value of attribute default

Returns:

  • (Object)

    the current value of default



1
2
3
# File 'lib/authpds/institution.rb', line 1

def default
  @default
end

#display_nameObject

Returns the value of attribute display_name

Returns:

  • (Object)

    the current value of display_name



1
2
3
# File 'lib/authpds/institution.rb', line 1

def display_name
  @display_name
end

#ip_addressesObject

Returns the value of attribute ip_addresses

Returns:

  • (Object)

    the current value of ip_addresses



1
2
3
# File 'lib/authpds/institution.rb', line 1

def ip_addresses
  @ip_addresses
end

#layoutsObject

Returns the value of attribute layouts

Returns:

  • (Object)

    the current value of layouts



1
2
3
# File 'lib/authpds/institution.rb', line 1

def layouts
  @layouts
end

#loginObject

Returns the value of attribute login

Returns:

  • (Object)

    the current value of login



1
2
3
# File 'lib/authpds/institution.rb', line 1

def 
  @login
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



1
2
3
# File 'lib/authpds/institution.rb', line 1

def name
  @name
end

#parent_institutionObject

Returns the value of attribute parent_institution

Returns:

  • (Object)

    the current value of parent_institution



1
2
3
# File 'lib/authpds/institution.rb', line 1

def parent_institution
  @parent_institution
end

#viewsObject

Returns the value of attribute views

Returns:

  • (Object)

    the current value of views



1
2
3
# File 'lib/authpds/institution.rb', line 1

def views
  @views
end

Instance Method Details

#includes_ip?(prospective_ip_address) ⇒ Boolean

Check the list of IP addresses for the given IP

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/authpds/institution.rb', line 25

def includes_ip?(prospective_ip_address)
  return false if ip_addresses.nil?
  ip_prospect = IPAddr.new(prospective_ip_address)
  ip_addresses.each do |ip_address|
    ip_range = (ip_address.match(/[\-\*]/)) ? 
      (ip_address.match(/\-/)) ? 
        (IPAddr.new(ip_address.split("-")[0])..IPAddr.new(ip_address.split("-")[1])) :
          (IPAddr.new(ip_address.gsub(/\*/, "0"))..IPAddr.new(ip_address.gsub(/\*/, "255"))) :
            IPAddr.new(ip_address).to_range
    return true if ip_range === ip_prospect unless ip_range.nil?
  end
  return false;
end

#instantiate_services!Object

Instantiates a new copy of all services included in this institution, returns an array.



20
21
22
# File 'lib/authpds/institution.rb', line 20

def instantiate_services!
  services.collect {|s|  }
end

#to_hObject



39
40
41
42
43
# File 'lib/authpds/institution.rb', line 39

def to_h
  h = {}
  members.each {|m| h[m.to_sym] = self.send(m)}
  h
end