class Squib::Args::Paragraph

Public Class Methods

expanding_parameters() click to toggle source
# File lib/squib/args/paragraph.rb, line 28
def self.expanding_parameters
  parameters.keys # all of them
end
new(deck_font) click to toggle source
# File lib/squib/args/paragraph.rb, line 36
def initialize(deck_font)
  @deck_font = deck_font
end
parameters() click to toggle source
# 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() click to toggle source
# File lib/squib/args/paragraph.rb, line 32
def self.params_with_units
  [] # none of them
end

Public Instance Methods

validate_align(arg, _i) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/squib/args/paragraph.rb, line 40
def validate_str(arg, _i)
  arg.to_s
end
validate_valign(arg, _i) click to toggle source
# 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) click to toggle source
# 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