Class: Osheet::Style

Inherits:
Object
  • Object
show all
Includes:
Instance
Defined in:
lib/osheet/style.rb

Constant Summary collapse

BORDER_POSITIONS =
[:top, :right, :bottom, :left]
BORDERS =
BORDER_POSITIONS.collect{|p| "border_#{p}".to_sym}
SETTINGS =
[:align, :font, :bg] + BORDERS

Instance Method Summary collapse

Constructor Details

#initialize(*selectors, &block) ⇒ Style

Returns a new instance of Style.



14
15
16
17
18
19
20
21
# File 'lib/osheet/style.rb', line 14

def initialize(*selectors, &block)
  set_ivar(:selectors, verify(selectors))
  SETTINGS.each {|setting| set_ivar(setting, [])}
  if block_given?
    set_binding_ivars(block.binding)
    instance_eval(&block)
  end
end

Instance Method Details

#attributesObject



39
40
41
42
43
44
# File 'lib/osheet/style.rb', line 39

def attributes
  SETTINGS.inject({}) do |attrs, s|
    attrs[s] = get_ivar(s)
    attrs
  end
end

#border(*args) ⇒ Object



33
34
35
36
37
# File 'lib/osheet/style.rb', line 33

def border(*args)
  BORDERS.each do |border|
    send(border, *args)
  end
end

#match?(style_class) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
49
50
51
52
# File 'lib/osheet/style.rb', line 46

def match?(style_class)
  selectors.inject(false) do |match, s|
    match ||= s.split('.').inject(true) do |result, part|
      result && (part.empty? || style_class.include?(part))
    end
  end
end

#selectorsObject



23
24
25
# File 'lib/osheet/style.rb', line 23

def selectors
  get_ivar(:selectors)
end