Class: CSSPool::LibCroco::CRSimpleSel

Inherits:
FFI::Struct
  • Object
show all
Defined in:
lib/csspool/lib_croco/cr_simple_sel.rb

Instance Method Summary collapse

Instance Method Details

#to_simple_selectorObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/csspool/lib_croco/cr_simple_sel.rb', line 18

def to_simple_selector
  klass = CSSPool::Selectors::Simple

  case self[:type_mask]
  when 1      # UNIVERSAL_SELECTOR
    klass = CSSPool::Selectors::Universal
  when 1 << 1 # TYPE_SELECTOR
    klass = CSSPool::Selectors::Type
  end

  simple_sel = klass.new(
    self[:name].null? ? nil :
      LibCroco.cr_string_peek_raw_str(self[:name]).read_string,
    self[:combinator]
  )
  simple_sel.parse_location = {
    :line         => self[:line],
    :column       => self[:column],
    :byte_offset  => self[:byte_offset]
  }

  additional_selectors = []
  pointer = self[:add_sel]
  until pointer.null?
    additional_selectors << CRAdditionalSel.new(pointer)
    pointer = additional_selectors.last[:next]
  end

  simple_sel.additional_selectors = additional_selectors.map { |as|
    as.to_additional_selector
  }

  simple_sel
end