Class: ALib::ListFile
Overview
file of lines, comments and blank lines are ignored
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
–}}}.
Class Method Summary collapse
-
.loadio(io) ⇒ Object
–}}}.
-
.parse(arg, &b) ⇒ Object
–{{{.
Instance Method Summary collapse
-
#initialize(arg) ⇒ ListFile
constructor
A new instance of ListFile.
Methods inherited from Array
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
#path ⇒ Object (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 |