Class: Spider::DocType

Inherits:
Object show all
Defined in:
lib/spiderfw/templates/template.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type_or_str) ⇒ DocType

Returns a new instance of DocType.



1020
1021
1022
1023
1024
1025
1026
# File 'lib/spiderfw/templates/template.rb', line 1020

def initialize(type_or_str)
    if type_or_str.is_a?(Symbol)
        @type = type_or_str
    else
        parse(type_or_str.to_s)
    end
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



1018
1019
1020
# File 'lib/spiderfw/templates/template.rb', line 1018

def type
  @type
end

#variantObject (readonly)

Returns the value of attribute variant.



1018
1019
1020
# File 'lib/spiderfw/templates/template.rb', line 1018

def variant
  @variant
end

Instance Method Details

#html?Boolean

Returns:

  • (Boolean)


1043
1044
1045
# File 'lib/spiderfw/templates/template.rb', line 1043

def html?
    @type == :html4 || @type == :html5
end

#parse(str) ⇒ Object



1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
# File 'lib/spiderfw/templates/template.rb', line 1028

def parse(str)
    if str =~ /DOCTYPE HTML PUBLIC.+\sHTML/i
        @type = :html4
    elsif str =~ /DOCTYPE HTML PUBLIC.+\sXHTML/i
        @type = :xhtml
    elsif str.downcase == '<!doctype html>'
        @type = :html5
    end
    if str =~ /strict/i
        @variant = :strict
    elsif str =~ /transitional/i
        @variant = :transitional
    end
end

#strict?Boolean

Returns:

  • (Boolean)


1051
1052
1053
# File 'lib/spiderfw/templates/template.rb', line 1051

def strict?
    @variant == :strict
end

#xhtml?Boolean

Returns:

  • (Boolean)


1047
1048
1049
# File 'lib/spiderfw/templates/template.rb', line 1047

def xhtml?
    @type == :xhtml
end