Sha256: 24399472fa94c0a8221dcaa3c1e543fa0769397da22d747d3c398596c41fd760
Contents?: true
Size: 1.51 KB
Versions: 2
Compression:
Stored size: 1.51 KB
Contents
# frozen_string_literal: true require_relative "wv/shape_helper" class Scarpe class InvalidAttributeValueError < Scarpe::Error; end class Star < Scarpe::Widget include ShapeHelper display_properties :left, :top, :points, :outer, :inner, :color def initialize(left, top, points = 10, outer = 100, inner = 50) @points = convert_to_integer(points, "points", 10) @outer = convert_to_float(outer, "outer", 100.0) @inner = convert_to_float(inner, "inner", 50.0) @color = color_for_fill super() create_display_widget end private def convert_to_integer(value, attribute_name, default = 0) begin value = Integer(value) raise InvalidAttributeValueError, "Negative num '#{value}' not allowed for attribute '#{attribute_name}'" if value < 0 value rescue ArgumentError error_message = "Invalid value '#{value}' provided for attribute '#{attribute_name}'. The value should be a number." raise InvalidAttributeValueError, error_message end end def convert_to_float(value, attribute_name, default = 0.0) begin value = Float(value) raise InvalidAttributeValueError, "Negative num '#{value}' not allowed for attribute '#{attribute_name}'" if value < 0 value rescue ArgumentError error_message = "Invalid value '#{value}' provided for attribute '#{attribute_name}'. The value should be a number." raise InvalidAttributeValueError, error_message end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
scarpe-0.2.1 | lib/scarpe/star.rb |
scarpe-0.2.0 | lib/scarpe/star.rb |