Class: Dieses::Application::Sheet

Inherits:
Object
  • Object
show all
Extended by:
DSL, Forwardable
Defined in:
lib/dieses/application/sheet.rb

Defined Under Namespace

Modules: DSL Classes: Proto

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DSL

extended, sheet, variate

Constructor Details

#initialize(paper, variant: Undefined) ⇒ Sheet

Returns a new instance of Sheet.



73
74
75
76
77
78
79
80
81
# File 'lib/dieses/application/sheet.rb', line 73

def initialize(paper, variant: Undefined)
  @paper   = paper
  @variant = Undefined.equal?(variant) ? self.class.default_variant : self.class.variant!(variant)
  @param   = parametrize
  @canvas  = Canvas.new(paper)
  @pen     = Pen.new(@canvas)

  setup if respond_to? :setup
end

Instance Attribute Details

#paperObject (readonly)

Returns the value of attribute paper.



71
72
73
# File 'lib/dieses/application/sheet.rb', line 71

def paper
  @paper
end

#variantObject (readonly)

Returns the value of attribute variant.



71
72
73
# File 'lib/dieses/application/sheet.rb', line 71

def variant
  @variant
end

Class Method Details

.default_variantObject



97
98
99
100
101
# File 'lib/dieses/application/sheet.rb', line 97

def default_variant
  return variant!(default) unless Undefined.equal?(proto.default)

  variants.values.first
end

.variant!(name) ⇒ Object

Raises:



103
104
105
106
107
108
# File 'lib/dieses/application/sheet.rb', line 103

def variant!(name)
  raise Error, "No variant defined: #{self.class}" if variants.empty?
  raise Error, "No such variant for #{self.class}: #{name}" unless variants.key?(name = name.to_sym)

  variants[name]
end

Instance Method Details

#produce(**kwargs) ⇒ Object



83
84
85
86
# File 'lib/dieses/application/sheet.rb', line 83

def produce(**kwargs)
  call
  canvas.render(variables: self.class.style.to_h, **kwargs)
end