Class: Maglev::Section::Block

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
app/models/maglev/section/block.rb

Overview

rubocop:disable Style/ClassAndModuleChildren

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#acceptObject

attributes ##



9
10
11
# File 'app/models/maglev/section/block.rb', line 9

def accept
  @accept
end

#limitObject

attributes ##



9
10
11
# File 'app/models/maglev/section/block.rb', line 9

def limit
  @limit
end

#nameObject

validation ##



9
10
11
# File 'app/models/maglev/section/block.rb', line 9

def name
  @name
end

#rootObject

attributes ##



9
10
11
# File 'app/models/maglev/section/block.rb', line 9

def root
  @root
end

#settingsObject

attributes ##



9
10
11
# File 'app/models/maglev/section/block.rb', line 9

def settings
  @settings
end

#typeObject

attributes ##



9
10
11
# File 'app/models/maglev/section/block.rb', line 9

def type
  @type
end

Class Method Details

.build(hash) ⇒ Object

class methods ##



23
24
25
26
27
28
29
30
31
32
33
# File 'app/models/maglev/section/block.rb', line 23

def self.build(hash)
  attributes = hash.slice('name', 'type', 'accept', 'root', 'limit')
  attributes['root'] = true if attributes['root'].nil?
  attributes['limit'] = -1 if attributes['limit'].nil?

  new(
    attributes.merge(
      settings: Maglev::Section::Setting.build_many(hash['settings'])
    )
  )
end

.build_many(list) ⇒ Object



35
36
37
38
39
# File 'app/models/maglev/section/block.rb', line 35

def self.build_many(list)
  return [] if list.blank?

  list.map { |hash| build(hash) }
end

Instance Method Details

#root?Boolean

methods

Returns:

  • (Boolean)


17
18
19
# File 'app/models/maglev/section/block.rb', line 17

def root?
  !!root
end