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.



1028
1029
1030
1031
1032
1033
1034
# File 'lib/spiderfw/templates/template.rb', line 1028

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.



1026
1027
1028
# File 'lib/spiderfw/templates/template.rb', line 1026

def type
  @type
end

#variantObject (readonly)

Returns the value of attribute variant.



1026
1027
1028
# File 'lib/spiderfw/templates/template.rb', line 1026

def variant
  @variant
end

Instance Method Details

#html?Boolean

Returns:

  • (Boolean)


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

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

#parse(str) ⇒ Object



1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
# File 'lib/spiderfw/templates/template.rb', line 1036

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)


1059
1060
1061
# File 'lib/spiderfw/templates/template.rb', line 1059

def strict?
    @variant == :strict
end

#xhtml?Boolean

Returns:

  • (Boolean)


1055
1056
1057
# File 'lib/spiderfw/templates/template.rb', line 1055

def xhtml?
    @type == :xhtml
end