Class: CodelessCode::Renderers::Page

Inherits:
Object
  • Object
show all
Defined in:
lib/codeless_code/renderers/page.rb

Constant Summary collapse

PAGER_FORMAT =
[
  '%<title>s', '%<sep1>s', '%<headers>s', '%<sep2>s', '', '%<body>s'
].join("\n").freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(max_width: nil) ⇒ Page

Returns a new instance of Page.



25
26
27
28
29
# File 'lib/codeless_code/renderers/page.rb', line 25

def initialize(max_width: nil)
  @max_width = max_width || term_width
  @headers = {}
  @key_width = 0
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



23
24
25
# File 'lib/codeless_code/renderers/page.rb', line 23

def body
  @body
end

#titleObject

Returns the value of attribute title.



23
24
25
# File 'lib/codeless_code/renderers/page.rb', line 23

def title
  @title
end

Instance Method Details

#add_header(key, value) ⇒ Object



37
38
39
40
# File 'lib/codeless_code/renderers/page.rb', line 37

def add_header(key, value)
  @key_width = [@key_width, key.size].max
  @headers[key] = value
end

#to_sObject



31
32
33
34
35
# File 'lib/codeless_code/renderers/page.rb', line 31

def to_s
  format(PAGER_FORMAT, title: title.center(width),
                       sep1: seperator('='), sep2: seperator('-'),
                       headers: header_section, body: body)
end