Module: Institutions::Core

Included in:
Institution
Defined in:
lib/institutions/institution/core.rb

Overview

:no_doc

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#codeObject (readonly)

Required attributes



4
5
6
# File 'lib/institutions/institution/core.rb', line 4

def code
  @code
end

#defaultObject (readonly) Also known as: default?

Optional core attributes



8
9
10
# File 'lib/institutions/institution/core.rb', line 8

def default
  @default
end

#nameObject (readonly) Also known as: display_name

Required attributes



4
5
6
# File 'lib/institutions/institution/core.rb', line 4

def name
  @name
end

Instance Method Details

#initialize(code, name, h = {}) ⇒ Object

Creates a new Institution object from the given code, name and hash.

The optional hash, if given, will generate additional attributes and values.

For example:

require 'institutions'
hash = { "attribute1" => "My first attribute.", :array_attribute => [1, 2] }
institution = Institutions::Institution.new("my_inst", "My Institution", hash)

p institution        # -> <Institutions::Institution @code=:my_inst @name="My Institution" @attribute1=My first attribute." @array_attribute=[1, 2] @default=false>


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

def initialize(code, name, h={})
  # Set the required attributes
  set_required_attributes code, name
  # Merge in the optional hash attribute
  merge h unless h.nil?
  # If the institution is named default, take that as an
  # indication that it's the default institution
  @default = true if name.downcase.eql? "default"
  # If default was never set, explicitly set default as false.
  @default = false if default.nil?
end