Class: Squib::Args::Paragraph
- Inherits:
-
Object
- Object
- Squib::Args::Paragraph
show all
- Includes:
- ArgLoader
- Defined in:
- lib/squib/args/paragraph.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from ArgLoader
#[], #convert_units, #defaultify, #expand_and_set_and_defaultify, #expandable_singleton?, #extract!, #load!, #prep_layout_args, #validate
Constructor Details
#initialize(deck_font) ⇒ Paragraph
Returns a new instance of Paragraph.
36
37
38
|
# File 'lib/squib/args/paragraph.rb', line 36
def initialize(deck_font)
@deck_font = deck_font
end
|
Class Method Details
.expanding_parameters ⇒ Object
28
29
30
|
# File 'lib/squib/args/paragraph.rb', line 28
def self.expanding_parameters
parameters.keys end
|
.parameters ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/squib/args/paragraph.rb', line 13
def self.parameters
{ align: :left,
str: 'Hello, World!',
font: :use_set,
font_size: nil,
markup: false,
justify: false,
wrap: true,
ellipsize: :end,
spacing: nil,
valign: :top,
hint: :off
}
end
|
.params_with_units ⇒ Object
32
33
34
|
# File 'lib/squib/args/paragraph.rb', line 32
def self.params_with_units
[] end
|
Instance Method Details
#validate_align(arg, _i) ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/squib/args/paragraph.rb', line 50
def validate_align(arg, _i)
case arg.to_s.downcase.strip
when 'left'
Pango::Alignment::LEFT
when 'right'
Pango::Alignment::RIGHT
when 'center'
Pango::Alignment::CENTER
else
raise ArgumentError, 'align must be one of: center, left, right'
end
end
|
#validate_ellipsize(arg, _i) ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/squib/args/paragraph.rb', line 76
def validate_ellipsize(arg, _i)
case arg.to_s.downcase.strip
when 'none', 'false'
Pango::EllipsizeMode::NONE
when 'start'
Pango::EllipsizeMode::START
when 'middle'
Pango::EllipsizeMode::MIDDLE
when 'end', 'true'
Pango::EllipsizeMode::END
when 'autoscale'
:autoscale
else
raise ArgumentError, 'ellipsize must be one of: none, start, middle, end, true, false or autoscale'
end
end
|
#validate_font(arg, _i) ⇒ Object
44
45
46
47
48
|
# File 'lib/squib/args/paragraph.rb', line 44
def validate_font(arg, _i)
arg = @deck_font if arg == :use_set
arg = Squib::DEFAULT_FONT if arg == :default
arg
end
|
#validate_justify(arg, _i) ⇒ Object
93
94
95
96
97
98
99
100
|
# File 'lib/squib/args/paragraph.rb', line 93
def validate_justify(arg, _i)
case arg
when nil, true, false
arg
else
raise ArgumentError, 'justify must be one of: nil, true, or false'
end
end
|
#validate_spacing(arg, _i) ⇒ Object
102
103
104
105
106
|
# File 'lib/squib/args/paragraph.rb', line 102
def validate_spacing(arg, _i)
return nil if arg.nil?
raise ArgumentError, 'spacing must be a number or nil' unless arg.respond_to? :to_f
arg.to_f * Pango::SCALE
end
|
#validate_str(arg, _i) ⇒ Object
40
41
42
|
# File 'lib/squib/args/paragraph.rb', line 40
def validate_str(arg, _i)
arg.to_s
end
|
#validate_valign(arg, _i) ⇒ Object
108
109
110
111
112
113
114
|
# File 'lib/squib/args/paragraph.rb', line 108
def validate_valign(arg, _i)
if %w(top middle bottom).include? arg.to_s.downcase
arg.to_s.downcase
else
raise ArgumentError, 'valign must be one of: top, middle, bottom'
end
end
|
#validate_wrap(arg, _i) ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/squib/args/paragraph.rb', line 63
def validate_wrap(arg, _i)
case arg.to_s.downcase.strip
when 'word'
Pango::WrapMode::WORD
when 'char', 'false'
Pango::WrapMode::CHAR
when 'word_char', 'true'
Pango::WrapMode::WORD_CHAR
else
raise ArgumentError, 'wrap must be one of: word, char, word_char, true, or false'
end
end
|