Class: Slideck::Alignment Private

Inherits:
Object
  • Object
show all
Defined in:
lib/slideck/alignment.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Responsible for accessing alignment configuration

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(horizontal, vertical) ⇒ Alignment

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Create an Alignment

Examples:

Slideck::Alignment.new("left", "top")

Parameters:

  • horizontal (String)

    the horizontal value

  • vertical (String)

    the vertical value

Raises:



97
98
99
100
101
102
# File 'lib/slideck/alignment.rb', line 97

def initialize(horizontal, vertical)
  @horizontal = validate_horizontal(horizontal)
  @vertical = validate_vertical(vertical)

  freeze
end

Instance Attribute Details

#horizontalString (readonly)

The horizontal alignment

Examples:

alignemnt.horizontal

Returns:

  • (String)


72
73
74
# File 'lib/slideck/alignment.rb', line 72

def horizontal
  @horizontal
end

#verticalString (readonly)

The vertical alignment

Examples:

alignment.vertical

Returns:

  • (String)


82
83
84
# File 'lib/slideck/alignment.rb', line 82

def vertical
  @vertical
end

Class Method Details

.[](horizontal, vertical) ⇒ Slideck::Alignment

Create an Alignment instance with an array-like initialiser

Examples:

Slideck::Alignment["right", "top"]

Parameters:

  • horizontal (String)

    the horizontal value

  • vertical (String)

    the vertical value

Returns:



60
61
62
# File 'lib/slideck/alignment.rb', line 60

def self.[](horizontal, vertical)
  new(horizontal, vertical)
end

.from(value, default: "center") ⇒ Slideck::Alignment

Create an Alignment instance from a string

Examples:

Slideck::Alignment.from("right top")
Slideck::Alignment.from("right,top")

Parameters:

  • value (String)

    the value to extract alignments from

  • default (String) (defaults to: "center")

    the default vertical alignment

Returns:



40
41
42
43
44
45
# File 'lib/slideck/alignment.rb', line 40

def self.from(value, default: "center")
  horizontal, vertical = *value.split(/[ ,]+/)
  vertical = default if vertical.nil?

  new(horizontal, vertical)
end

Instance Method Details

#==(other) ⇒ Boolean

Determine equivalence with another object

Examples:

alignment == other

Parameters:

  • other (Object)

    the other object to determine equivalence with

Returns:

  • (Boolean)

    true if this object is equivalent to the other, false otherwise



117
118
119
120
# File 'lib/slideck/alignment.rb', line 117

def ==(other)
  other.is_a?(self.class) &&
    horizontal == other.horizontal && vertical == other.vertical
end

#eql?(other) ⇒ Boolean

Determine equality with another object

Examples:

alignment.eql?(other)

Parameters:

  • other (Object)

    the other object to determine equality with

Returns:

  • (Boolean)

    true if this object is equal to the other, false otherwise



134
135
136
137
# File 'lib/slideck/alignment.rb', line 134

def eql?(other)
  instance_of?(other.class) &&
    horizontal.eql?(other.horizontal) && vertical.eql?(other.vertical)
end

#hashInteger

Generate hash value of this alignment

Examples:

alignment.hash

Returns:

  • (Integer)


147
148
149
# File 'lib/slideck/alignment.rb', line 147

def hash
  [self.class, horizontal, vertical].hash
end

#to_aArray<String, String>

Convert this alignment into an array

Examples:

alignment.to_a

Returns:

  • (Array<String, String>)


159
160
161
# File 'lib/slideck/alignment.rb', line 159

def to_a
  [horizontal, vertical]
end