Class: XML::Feed::Parser::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/xml/libxml/feed/parser.rb

Direct Known Subclasses

Rss

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version, io, auto_validate = true) ⇒ Base

Returns a new instance of Base.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/xml/libxml/feed/parser.rb', line 48

def initialize(version, io, auto_validate=true)
    @version = version

    case io
    when IO
        @xml = io.read
        io.close
    when StringIO
        @xml = io.read
        io.close
    when String
        @xml = io.dup
    else
        raise XML::Feed::Parser::InvalidHandle, "Must be IO, StringIO, or String object"
    end

    @xml.freeze
    @version.freeze
    @validated = false

    if @xml.length == 0
        raise XML::Feed::Parser::InvalidHandle, "Resulting XML String must have a length greater than 0"
    end

    @doc = XML::Parser.string(@xml).parse

    if auto_validate 
        validate!
    end
end

Instance Attribute Details

#docObject (readonly)

Returns the value of attribute doc.



46
47
48
# File 'lib/xml/libxml/feed/parser.rb', line 46

def doc
  @doc
end

#validatedObject (readonly)

Returns the value of attribute validated.



45
46
47
# File 'lib/xml/libxml/feed/parser.rb', line 45

def validated
  @validated
end

#versionObject (readonly)

Returns the value of attribute version.



44
45
46
# File 'lib/xml/libxml/feed/parser.rb', line 44

def version
  @version
end

#xmlObject (readonly)

Returns the value of attribute xml.



43
44
45
# File 'lib/xml/libxml/feed/parser.rb', line 43

def xml
  @xml
end