Class: ALib::ListFile

Inherits:
Array show all
Defined in:
lib/alib-0.5.1/listfile.rb

Overview

file of lines, comments and blank lines are ignored

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Array

step

Constructor Details

#initialize(arg) ⇒ ListFile

Returns a new instance of ListFile.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/alib-0.5.1/listfile.rb', line 26

def initialize arg 
#--{{{
  case arg
    when Pathname, String
      @path = path
      self.class.parse(arg){|line| self << line}
    when IO
      @path = arg.respond_to?('path') ? arg.path : arg.to_s
      self.class.loadio(arg){|line| self << line}
    else
      raise "cannot initialize from <#{ arg.inspect }>"
  end
#--}}}
end

Instance Attribute Details

#pathObject (readonly)

–}}}



25
26
27
# File 'lib/alib-0.5.1/listfile.rb', line 25

def path
  @path
end

Class Method Details

.loadio(io) ⇒ Object

–}}}



13
14
15
16
17
18
19
20
21
22
# File 'lib/alib-0.5.1/listfile.rb', line 13

def loadio io
#--{{{
  while((line = io.gets))
    line.gsub!(%r/#.*/o,'')
    next if line =~ %r/^[^\S]+$/o
    line.gsub!(%r/^[^\S]+|[^\S]+$/o,'')
    yield line
  end
#--}}}
end

.parse(arg, &b) ⇒ Object

–{{{



8
9
10
11
12
# File 'lib/alib-0.5.1/listfile.rb', line 8

def parse arg, &b
#--{{{
  arg.respond_to?('gets') ? loadio(arg, &b) : open(arg.to_s){|f| loadio(f, &b)}
#--}}}
end