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.



982
983
984
985
986
987
988
# File 'lib/spiderfw/templates/template.rb', line 982

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.



980
981
982
# File 'lib/spiderfw/templates/template.rb', line 980

def type
  @type
end

#variantObject (readonly)

Returns the value of attribute variant.



980
981
982
# File 'lib/spiderfw/templates/template.rb', line 980

def variant
  @variant
end

Instance Method Details

#html?Boolean

Returns:

  • (Boolean)


1005
1006
1007
# File 'lib/spiderfw/templates/template.rb', line 1005

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

#parse(str) ⇒ Object



990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
# File 'lib/spiderfw/templates/template.rb', line 990

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)


1013
1014
1015
# File 'lib/spiderfw/templates/template.rb', line 1013

def strict?
    @variant == :strict
end

#xhtml?Boolean

Returns:

  • (Boolean)


1009
1010
1011
# File 'lib/spiderfw/templates/template.rb', line 1009

def xhtml?
    @type == :xhtml
end