Class: Dieses::Application::Paper::Variant

Inherits:
Struct
  • Object
show all
Defined in:
lib/dieses/application/paper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#floorObject

Returns the value of attribute floor

Returns:

  • (Object)

    the current value of floor



44
45
46
# File 'lib/dieses/application/paper.rb', line 44

def floor
  @floor
end

#heightObject

Returns the value of attribute height

Returns:

  • (Object)

    the current value of height



44
45
46
# File 'lib/dieses/application/paper.rb', line 44

def height
  @height
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



44
45
46
# File 'lib/dieses/application/paper.rb', line 44

def name
  @name
end

#scaleObject

Returns the value of attribute scale

Returns:

  • (Object)

    the current value of scale



44
45
46
# File 'lib/dieses/application/paper.rb', line 44

def scale
  @scale
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



44
45
46
# File 'lib/dieses/application/paper.rb', line 44

def type
  @type
end

#widthObject

Returns the value of attribute width

Returns:

  • (Object)

    the current value of width



44
45
46
# File 'lib/dieses/application/paper.rb', line 44

def width
  @width
end

Instance Method Details

#buildObject

rubocop:disable Metrics/MethodLength,Metrics/AbcSize



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/dieses/application/paper.rb', line 45

def build # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
  dim = Dim.(width, height)

  if scale.nil? || (short = Support.approx(dim.short * scale)) < floor
    short = floor
    scale = floor / dim.short
  end

  long   = Support.approx(dim.long * scale)
  margin = Margin.build(dim, short: short, long: long)

  variant = self

  Paper.define_singleton_method(name) do |**kwargs|
    klass = Class.new(Instance)

    klass.type    variant.type
    klass.variant variant.name

    klass.new(*dim.values, **margin.to_h.merge(**kwargs))
  end
end