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.



935
936
937
938
939
940
941
# File 'lib/spiderfw/templates/template.rb', line 935

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

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



933
934
935
# File 'lib/spiderfw/templates/template.rb', line 933

def type
  @type
end

#variantObject (readonly)

Returns the value of attribute variant.



933
934
935
# File 'lib/spiderfw/templates/template.rb', line 933

def variant
  @variant
end

Instance Method Details

#html?Boolean

Returns:

  • (Boolean)


958
959
960
# File 'lib/spiderfw/templates/template.rb', line 958

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

#parse(str) ⇒ Object



943
944
945
946
947
948
949
950
951
952
953
954
955
956
# File 'lib/spiderfw/templates/template.rb', line 943

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)


966
967
968
# File 'lib/spiderfw/templates/template.rb', line 966

def strict?
    @variant == :strict
end

#xhtml?Boolean

Returns:

  • (Boolean)


962
963
964
# File 'lib/spiderfw/templates/template.rb', line 962

def xhtml?
    @type == :xhtml
end