Class: ALib::ListFile
- Inherits:
-
Array
- Object
- Array
- ALib::ListFile
- Defined in:
- lib/alib.rb,
lib/alib-0.3.1.rb
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.
Constructor Details
#initialize(arg) ⇒ ListFile
Returns a new instance of ListFile.
1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 |
# File 'lib/alib.rb', line 1239 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)
–}}}
1238 1239 1240 |
# File 'lib/alib.rb', line 1238 def path @path end |
Class Method Details
.loadio(io) ⇒ Object
–}}}
1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 |
# File 'lib/alib.rb', line 1226 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
–{{{
1221 1222 1223 1224 1225 |
# File 'lib/alib.rb', line 1221 def parse arg, &b #--{{{ arg.respond_to?('gets') ? loadio(arg, &b) : open("#{ path }"){|f| loadio(f, &b)} #--}}} end |