Class: Gsk::RoundedRect

Inherits:
Object
  • Object
show all
Defined in:
lib/gsk4/rounded-rect.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ RoundedRect

Returns a new instance of RoundedRect.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/gsk4/rounded-rect.rb', line 50

def initialize(*args)
  super()
  case args.size
  when 0
  when 1
    init_copy(args[0])
  when 2
    init_from_rect(args[0], args[1])
  when 5
    init(*args)
  else
    message = +"wrong number of arguments "
    message << "(given #{args.size}, expected 0, 1, 2 or 5)"
    raise ArgumentError, message
  end
end

Class Method Details

.try_convert(value) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/gsk4/rounded-rect.rb', line 20

def try_convert(value)
  case value
  when Array
    n_values = value.size
    return nil if n_values < 2

    bounds = Graphene::Rect.try_convert(value[0])
    return nil if bounds.nil?
    case n_values
    when 2
      radius = value[1]
      new(bounds, radius)
    when 5
      corners = []
      (1..4).each do |i|
        corner = Graphene::Size.try_convert(value[i])
        return nil if corner.nil?
        corners << corner
      end
      new(bounds, *corners)
    else
      nil
    end
  else
    nil
  end
end

Instance Method Details

#==(other) ⇒ Object



67
68
69
70
71
# File 'lib/gsk4/rounded-rect.rb', line 67

def ==(other)
  other.is_a?(self.class) and
    bounds == other.bounds and
    corners == other.corners
end

#initialize_rawObject



49
# File 'lib/gsk4/rounded-rect.rb', line 49

alias_method :initialize_raw, :initialize

#inspectObject



73
74
75
76
77
# File 'lib/gsk4/rounded-rect.rb', line 73

def inspect
  super.sub(/>\z/) do
    " bounds=#{bounds.inspect} corners=#{corners.inspect}>"
  end
end