Class: UDRS::Components::Text

Inherits:
Object
  • Object
show all
Defined in:
lib/udrs/components/text.rb

Constant Summary collapse

SIZES =
i(tiny small normal medium large huge)
ALIGNENTS =
i(left center right)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text, options = {}) ⇒ Text



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/udrs/components/text.rb', line 11

def initialize(text, options = {})
  @text = text.to_s

  # Text size
  @size = :normal
  @size = options[:size] if options[:size].present?
  fail ArgumentError, "Invalid size: #{@size}" unless SIZES.include?(@size)

  # Style(s)
  style = [*options[:style]]
  @is_bold = style.delete(:bold)
  @is_italic = style.delete(:italic)
  @is_underline = style.delete(:underline)
  fail ArgumentError, "Invalid style(s): #{style.join(', ')}" unless style.empty?

  # Alignment
  @alignment = :left
  @alignment = options[:align] if options[:align].present?
  fail ArgumentError, "Invalid alignment: #{@alignment}" unless ALIGNENTS.include?(@alignment)
end

Instance Attribute Details

#alignmentObject (readonly)

Returns the value of attribute alignment.



6
7
8
# File 'lib/udrs/components/text.rb', line 6

def alignment
  @alignment
end

#is_boldObject (readonly)

Returns the value of attribute is_bold.



6
7
8
# File 'lib/udrs/components/text.rb', line 6

def is_bold
  @is_bold
end

#is_italicObject (readonly)

Returns the value of attribute is_italic.



6
7
8
# File 'lib/udrs/components/text.rb', line 6

def is_italic
  @is_italic
end

#is_underlineObject (readonly)

Returns the value of attribute is_underline.



6
7
8
# File 'lib/udrs/components/text.rb', line 6

def is_underline
  @is_underline
end

#sizeObject (readonly)

Returns the value of attribute size.



6
7
8
# File 'lib/udrs/components/text.rb', line 6

def size
  @size
end

#textObject (readonly)

Returns the value of attribute text.



6
7
8
# File 'lib/udrs/components/text.rb', line 6

def text
  @text
end