Module: Institutions::Core
- Included in:
- Institution
- Defined in:
- lib/institutions/institution/core.rb
Overview
:no_doc
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Required attributes.
-
#default ⇒ Object
(also: #default?)
readonly
Optional core attributes.
-
#name ⇒ Object
(also: #display_name)
readonly
Required attributes.
Instance Method Summary collapse
-
#initialize(code, name, h = {}) ⇒ Object
Creates a new Institution object from the given code, name and hash.
Instance Attribute Details
#code ⇒ Object (readonly)
Required attributes
4 5 6 |
# File 'lib/institutions/institution/core.rb', line 4 def code @code end |
#default ⇒ Object (readonly) Also known as: default?
Optional core attributes
8 9 10 |
# File 'lib/institutions/institution/core.rb', line 8 def default @default end |
#name ⇒ Object (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 |