Class: Odca::HeadfulOverlay

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/odca/headful_overlay.rb

Constant Summary collapse

OVERLAYS_INFO =
'config/overlays_info.yml'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parentful_overlay:, role:, purpose:) ⇒ HeadfulOverlay

Returns a new instance of HeadfulOverlay.



14
15
16
17
18
19
# File 'lib/odca/headful_overlay.rb', line 14

def initialize(parentful_overlay:, role:, purpose:)
  @parentful_overlay = parentful_overlay
  @role = role
  @purpose = purpose
  @overlays_info = overlays_info
end

Instance Attribute Details

#parentful_overlayObject (readonly)

Returns the value of attribute parentful_overlay.



8
9
10
# File 'lib/odca/headful_overlay.rb', line 8

def parentful_overlay
  @parentful_overlay
end

#purposeObject (readonly)

Returns the value of attribute purpose.



8
9
10
# File 'lib/odca/headful_overlay.rb', line 8

def purpose
  @purpose
end

#roleObject (readonly)

Returns the value of attribute role.



8
9
10
# File 'lib/odca/headful_overlay.rb', line 8

def role
  @role
end

Instance Method Details

#headerObject



30
31
32
33
34
35
36
37
# File 'lib/odca/headful_overlay.rb', line 30

def header
  @header ||=
    Odca::Overlays::Header.new(
      role: role,
      purpose: purpose,
      type: overlay_info['type_v1']
    )
end

#overlay_infoObject



45
46
47
48
49
50
51
# File 'lib/odca/headful_overlay.rb', line 45

def overlay_info
  overlay_class_name = overlay.class.name.split('::').last
  overlay_key = overlay_class_name.gsub('Overlay', '').gsub(/([^\^])([A-Z])/,'\1_\2').downcase
  overlays_info.fetch(overlay_key) do
    raise "Not found specific information about #{overlay_class_name}"
  end
end

#overlays_infoObject



39
40
41
42
43
# File 'lib/odca/headful_overlay.rb', line 39

def overlays_info
  @overlays_info ||= YAML.safe_load(
    File.open(File.join(Odca::ROOT_PATH, OVERLAYS_INFO))
  )
end

#to_hObject



25
26
27
28
# File 'lib/odca/headful_overlay.rb', line 25

def to_h
  header.to_h
    .merge(parentful_overlay.to_h)
end

#to_json(options = {}) ⇒ Object



21
22
23
# File 'lib/odca/headful_overlay.rb', line 21

def to_json(options = {})
  to_h.to_json(*options)
end