Class: XMLScan::Input

Inherits:
Object
  • Object
show all
Defined in:
lib/xmlscan/scanner.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(src) ⇒ Input

Returns a new instance of Input.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/xmlscan/scanner.rb', line 46

def initialize(src)
  @src = src
  unless src.respond_to? :gets then
    if src.respond_to? :to_ary then
      @v = src.to_ary
      @n = -1
      def self.gets ; @v.at(@n += 1) ; end
      def self.lineno ; @n + 1 ; end
    else
      @v = @src
      def self.gets ; s = @v ; @v = nil ; s ; end
    end
  end
  if src.respond_to? :lineno then
    def self.lineno ; @src.lineno ; end
  end
  if src.respond_to? :path then
    def self.path ; @src.path ; end
  end
end

Instance Attribute Details

#srcObject (readonly)

Returns the value of attribute src.



67
68
69
# File 'lib/xmlscan/scanner.rb', line 67

def src
  @src
end

Class Method Details

.unwrap(obj) ⇒ Object



81
82
83
84
85
86
87
# File 'lib/xmlscan/scanner.rb', line 81

def self.unwrap(obj)
  if self === obj then
    obj.src
  else
    obj
  end
end

.wrap(src) ⇒ Object



73
74
75
76
77
78
79
# File 'lib/xmlscan/scanner.rb', line 73

def self.wrap(src)
  unless src.respond_to? :gets and src.respond_to? :lineno and
      src.respond_to? :path then
    src = new(src)
  end
  src
end

Instance Method Details

#getsObject



69
# File 'lib/xmlscan/scanner.rb', line 69

def gets ; @src.gets ; end

#linenoObject



70
# File 'lib/xmlscan/scanner.rb', line 70

def lineno ; 0 ; end

#pathObject



71
# File 'lib/xmlscan/scanner.rb', line 71

def path ; '-' ; end