Class: SpreadsheetBuilder::CssParser
- Inherits:
-
Object
- Object
- SpreadsheetBuilder::CssParser
- Defined in:
- lib/spreadsheet_builder/css_parser.rb
Instance Attribute Summary collapse
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
-
#load_paths ⇒ Object
Returns the value of attribute load_paths.
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
Class Method Summary collapse
Instance Method Summary collapse
- #format_from_node(node) ⇒ Object
-
#initialize(load_paths = []) ⇒ CssParser
constructor
A new instance of CssParser.
- #reset(level = :parser) ⇒ Object
Constructor Details
#initialize(load_paths = []) ⇒ CssParser
Returns a new instance of CssParser.
28 29 30 31 32 |
# File 'lib/spreadsheet_builder/css_parser.rb', line 28 def initialize(load_paths = []) @load_paths = load_paths reset end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
25 26 27 |
# File 'lib/spreadsheet_builder/css_parser.rb', line 25 def cache @cache end |
#load_paths ⇒ Object
Returns the value of attribute load_paths.
26 27 28 |
# File 'lib/spreadsheet_builder/css_parser.rb', line 26 def load_paths @load_paths end |
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
25 26 27 |
# File 'lib/spreadsheet_builder/css_parser.rb', line 25 def rules @rules end |
Class Method Details
.pt_from_input(val, base = :width) ⇒ Object
21 22 23 |
# File 'lib/spreadsheet_builder/css_parser.rb', line 21 def self.pt_from_input(val, base = :width) px_from_input(val, base) * 12 / 16 end |
.px_from_input(val, base = :width) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/spreadsheet_builder/css_parser.rb', line 4 def self.px_from_input(val, base = :width) case val when /%$/ val.to_f / 100 * { width: 1024, height: 16 }[base] when /px$/ val.to_f when /cm$/ val.to_f * 37.795275591 when /em$/ val.to_f * 16 when /pt$/ val.to_f * 16 / 12 else nil end end |
Instance Method Details
#format_from_node(node) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/spreadsheet_builder/css_parser.rb', line 40 def format_from_node(node) formats = [] formats << format_from_klass_tree(klass_tree_from_node(node), node) if node.attributes["style"] declarations = node.attributes["style"].value.split(';').map { |line| k, v = line.split(':') [k, { value: v }] } formats << format_from_declarations(declarations, node) end formats.inject(&:merge) end |
#reset(level = :parser) ⇒ Object
34 35 36 37 38 |
# File 'lib/spreadsheet_builder/css_parser.rb', line 34 def reset(level = :parser) method = "reset_#{level}" __send__(method) end |