Class: Bulldog::StyleSet

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/bulldog/style_set.rb

Overview

An ordered set of Styles.

Lookup is by style name.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(styles = []) ⇒ StyleSet

Create a StyleSet containing the given styles.



11
12
13
# File 'lib/bulldog/style_set.rb', line 11

def initialize(styles=[])
  @styles = styles.to_a
end

Class Method Details

.[](*styles) ⇒ Object

Create a StyleSet containing the given styles.



26
27
28
# File 'lib/bulldog/style_set.rb', line 26

def self.[](*styles)
  new(styles)
end

Instance Method Details

#<<(style) ⇒ Object

Add the given style to the set.



48
49
50
# File 'lib/bulldog/style_set.rb', line 48

def <<(style)
  @styles << style
end

#==(other) ⇒ Object

Return true if the given object has the same styles as this one.

The argument must have #to_a defined. Style comparison is done by name only.



58
59
60
# File 'lib/bulldog/style_set.rb', line 58

def ==(other)
  other.to_a == @styles
end

#[](arg) ⇒ Object

Return the style with the given name.



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/bulldog/style_set.rb', line 33

def [](arg)
  if arg.is_a?(Symbol)
    if arg == :original
      Style::ORIGINAL
    else
      @styles.find{|style| style.name == arg}
    end
  else
    @styles[arg]
  end
end

#initialize_copy(other) ⇒ Object

Initialize a StyleSet from another.



18
19
20
21
# File 'lib/bulldog/style_set.rb', line 18

def initialize_copy(other)
  super
  @styles = @styles.clone
end

#slice(*names) ⇒ Object

Return the style with the given names.



94
95
96
97
# File 'lib/bulldog/style_set.rb', line 94

def slice(*names)
  styles = names.map{|name| self[name]}
  StyleSet[*styles]
end

#to_aObject

Return the list of styles as an Array.



65
66
67
# File 'lib/bulldog/style_set.rb', line 65

def to_a
  @styles.dup
end