Class: Squib::Args::Draw
Class Method Summary
collapse
Instance Method Summary
collapse
#colorify
Methods included from ArgLoader
#[], #convert_units, #defaultify, #expand_and_set_and_defaultify, #expandable_singleton?, #extract!, #load!, #prep_layout_args, #validate
Constructor Details
#initialize(custom_colors, dsl_method_defaults = {}) ⇒ Draw
Returns a new instance of Draw.
15
16
17
18
|
# File 'lib/squib/args/draw.rb', line 15
def initialize(custom_colors, dsl_method_defaults = {})
@custom_colors = custom_colors
@dsl_method_defaults = dsl_method_defaults
end
|
Class Method Details
.expanding_parameters ⇒ Object
32
33
34
|
# File 'lib/squib/args/draw.rb', line 32
def self.expanding_parameters
parameters.keys end
|
.parameters ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/squib/args/draw.rb', line 20
def self.parameters
{ color: :black,
fill_color: '#0000',
stroke_color: :black,
stroke_width: 2.0,
stroke_strategy: :fill_first,
join: :miter,
cap: 'butt',
dash: ''
}
end
|
.params_with_units ⇒ Object
36
37
38
|
# File 'lib/squib/args/draw.rb', line 36
def self.params_with_units
[:stroke_width]
end
|
Instance Method Details
#validate_cap(arg, _i) ⇒ Object
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/squib/args/draw.rb', line 51
def validate_cap(arg, _i)
case arg.to_s.strip.downcase
when 'butt'
Cairo::LINE_CAP_BUTT
when 'round'
Cairo::LINE_CAP_ROUND
when 'square'
Cairo::LINE_CAP_SQUARE
end
end
|
#validate_color(arg, _i) ⇒ Object
76
77
78
|
# File 'lib/squib/args/draw.rb', line 76
def validate_color(arg, _i)
colorify(arg, @custom_colors)
end
|
#validate_dash(arg, _i) ⇒ Object
62
63
64
65
66
|
# File 'lib/squib/args/draw.rb', line 62
def validate_dash(arg, _i)
arg.to_s.split.collect do |x|
UnitConversion.parse(x, @dpi, @cell_px).to_f
end
end
|
#validate_fill_color(arg, _i) ⇒ Object
68
69
70
|
# File 'lib/squib/args/draw.rb', line 68
def validate_fill_color(arg, _i)
colorify(arg, @custom_colors)
end
|
#validate_join(arg, _i) ⇒ Object
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/squib/args/draw.rb', line 40
def validate_join(arg, _i)
case arg.to_s.strip.downcase
when 'miter'
Cairo::LINE_JOIN_MITER
when 'round'
Cairo::LINE_JOIN_ROUND
when 'bevel'
Cairo::LINE_JOIN_BEVEL
end
end
|
#validate_stroke_color(arg, _i) ⇒ Object
72
73
74
|
# File 'lib/squib/args/draw.rb', line 72
def validate_stroke_color(arg, _i)
colorify(arg, @custom_colors)
end
|
#validate_stroke_strategy(arg, _i) ⇒ Object
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/squib/args/draw.rb', line 80
def validate_stroke_strategy(arg, _i)
case arg.to_s.downcase.strip
when 'fill_first'
:fill_first
when 'stroke_first'
:stroke_first
else
raise "Only 'stroke_first' or 'fill_first' allowed"
end
end
|