Class: EtdaUtilities::AccessLevel

Inherits:
Object
  • Object
show all
Defined in:
lib/etda_utilities/access_level.rb

Constant Summary collapse

ACCESS_LEVEL_KEYS =

attr_accessor :current_access_level *** IMPORTANT NOTE *** The order of the keys in this array matter and they should go from least restrictive to most restrictive This is used in the comparison operation (<=>) below

['open_access', 'restricted_to_institution', 'restricted', ''].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(level) ⇒ AccessLevel



46
47
48
49
50
# File 'lib/etda_utilities/access_level.rb', line 46

def initialize(level)
  # super(submission_attributes, level)
  @attributes = self.class.partner_access_levels['access_level'][level.to_s] # || 'NO_ACCESS'
  @current_access_level = verify_access_level(level)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object (private)



93
94
95
96
97
98
99
100
# File 'lib/etda_utilities/access_level.rb', line 93

def method_missing(sym, *args, &block)
  super
rescue NoMethodError
  name = sym.to_s.sub('?', '')
  return false if ACCESS_LEVEL_KEYS.include?(name)

  raise
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



8
9
10
# File 'lib/etda_utilities/access_level.rb', line 8

def attributes
  @attributes
end

#current_access_levelObject (readonly)

Returns the value of attribute current_access_level.



52
53
54
# File 'lib/etda_utilities/access_level.rb', line 52

def current_access_level
  @current_access_level
end

Class Method Details

.paper_access_level_keysObject



31
32
33
# File 'lib/etda_utilities/access_level.rb', line 31

def self.paper_access_level_keys
  ACCESS_LEVEL_KEYS
end

.paper_access_levelsObject



39
40
41
42
43
44
# File 'lib/etda_utilities/access_level.rb', line 39

def self.paper_access_levels
  paper_access_level_keys.map do |key|
    level = EtdaUtilities::AccessLevel.new(key)
    { type: key, label: level.label, description: level.description }
  end
end

.partner_access_levelsObject



27
28
29
# File 'lib/etda_utilities/access_level.rb', line 27

def self.partner_access_levels
  CURRENT_PARTNER_ACCESS_LEVELS
end

.valid_levelsObject



35
36
37
# File 'lib/etda_utilities/access_level.rb', line 35

def self.valid_levels
  paper_access_level_keys #  + ['']
end

Instance Method Details

#<=>(other) ⇒ Object



54
55
56
57
58
# File 'lib/etda_utilities/access_level.rb', line 54

def <=>(other)
  alevel = other
  alevel = self.class.new(alevel) unless alevel.instance_of? self.class
  to_i <=> alevel.to_i
end

#descriptionObject



68
69
70
71
72
# File 'lib/etda_utilities/access_level.rb', line 68

def description
  return '' if current_access_level == ''

  self.class.partner_access_levels['access_level']["#{current_access_level}_attr"]['description_html']
end

#labelObject



64
65
66
# File 'lib/etda_utilities/access_level.rb', line 64

def label
  self.class.partner_access_levels['access_level'][current_access_level] || ''
end

#scopeObject



60
61
62
# File 'lib/etda_utilities/access_level.rb', line 60

def scope
  self.class.partner_access_levels['access_level']["#{current_access_level}_attr"]['scope'] || 'released_for_publication'
end

#to_iObject

define the integer value of the item as the index in the access other keys array



75
76
77
# File 'lib/etda_utilities/access_level.rb', line 75

def to_i
  self.class.valid_levels.find_index current_access_level
end