Class: Osheet::Style

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

Constant Summary collapse

BORDER_POSITIONS =

this class is essentially a set of collectors for style settings each setting collects any arguments passed to it and it is up to the writer to determine how to use the settings

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*selectors, &build) ⇒ Style

Returns a new instance of Style.



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

def initialize(*selectors, &build)
  @selectors = verify(selectors)
  @build = build || Proc.new {}
  SETTINGS.each { |s| instance_variable_set("@#{s}", []) }
end

Instance Attribute Details

#buildObject (readonly)

Returns the value of attribute build.



12
13
14
# File 'lib/osheet/style.rb', line 12

def build
  @build
end

#selectorsObject (readonly)

Returns the value of attribute selectors.



12
13
14
# File 'lib/osheet/style.rb', line 12

def selectors
  @selectors
end

Instance Method Details

#align(*args) ⇒ Object



20
# File 'lib/osheet/style.rb', line 20

def align(*args); @align += args; end

#bg(*args) ⇒ Object



22
# File 'lib/osheet/style.rb', line 22

def bg(*args);    @bg    += args; end

#border(*args) ⇒ Object



29
30
31
# File 'lib/osheet/style.rb', line 29

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

#border_bottom(*args) ⇒ Object



26
# File 'lib/osheet/style.rb', line 26

def border_bottom(*args); @border_bottom += args; end

#border_left(*args) ⇒ Object



27
# File 'lib/osheet/style.rb', line 27

def border_left(*args);   @border_left   += args; end

#border_right(*args) ⇒ Object



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

def border_right(*args);  @border_right  += args; end

#border_top(*args) ⇒ Object



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

def border_top(*args);    @border_top    += args; end

#font(*args) ⇒ Object



21
# File 'lib/osheet/style.rb', line 21

def font(*args);  @font  += args; end

#match?(style_class) ⇒ Boolean

Returns:

  • (Boolean)


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

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