Class: StyleFormat

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ StyleFormat

Returns a new instance of StyleFormat.



9
10
11
12
13
14
15
16
17
# File 'lib/surpass/style.rb', line 9

def initialize(hash = {})
  @number_format_string = hash[:number_format_string] || 'General'

  @font           = Font.new(hash_select(hash, /^font_/))
  @alignment      = Alignment.new(hash_select(hash, /^text_/))
  @borders        = Borders.new(hash_select(hash, /^border_/))
  @pattern        = Pattern.new(hash_select(hash, /^(fill|pattern)_/))
  @protection     = Protection.new
end

Instance Attribute Details

#alignmentObject

Returns the value of attribute alignment.



4
5
6
# File 'lib/surpass/style.rb', line 4

def alignment
  @alignment
end

#bordersObject

Returns the value of attribute borders.



5
6
7
# File 'lib/surpass/style.rb', line 5

def borders
  @borders
end

#fontObject

Returns the value of attribute font.



3
4
5
# File 'lib/surpass/style.rb', line 3

def font
  @font
end

#number_format_stringObject

Returns the value of attribute number_format_string.



2
3
4
# File 'lib/surpass/style.rb', line 2

def number_format_string
  @number_format_string
end

#patternObject

Returns the value of attribute pattern.



6
7
8
# File 'lib/surpass/style.rb', line 6

def pattern
  @pattern
end

#protectionObject

Returns the value of attribute protection.



7
8
9
# File 'lib/surpass/style.rb', line 7

def protection
  @protection
end

Instance Method Details

#hash_select(hash, pattern) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/surpass/style.rb', line 19

def hash_select(hash, pattern)
  new_hash = {}
  hash.keys.each do |k|
    next unless k.to_s =~ pattern
    new_key = k.to_s.gsub(pattern, '').to_sym
    new_hash[new_key] = hash[k]
  end
  new_hash
end