class FSObjects
This class concentrates all action on file-system-objects. It does not need to be instantiated and thus contains only static members.
Constants
- CONFIG
- FO
- FOLONG
- INI
- LONG
- MILLE
- SECTIONS
TODO add patterns for other sections
Public Class Methods
complete(dir)
click to toggle source
Returns an Array, describing the currently available configuration-files.
# File lib/fsobjects.rb, line 165 def self::complete(dir) if(!@@entries) read_config(dir) end items = [] nend = CONFIG + INI flen1 = flen2 = 0 @@entries.each do |n| sn = n[0..1] ln = LONG[sn] if(ln) item = [] field = n.sub(nend, '') flen1 = field.length if field.length > flen1 item << field field = ln.dup if (FO == n[2..3]) field << ' ' << FOLONG if(n[4..5].to_i > 0) field << ' ' << MILLE + n[4..5] end elsif (n[2..3].to_i > 0 ) field << ' ' << MILLE + n[2..3] end flen2 = field.length if field.length > flen2 item << field item << n items << item end end items.collect!{|it| "%#{flen1 + 2}s\t%-#{flen2 + 2}s %s" %it} end
get_sections(section, next_symbol, text)
click to toggle source
Returns an array of section-bodies (without label). Parameters are:
section - a pattern, describing the label of the section. next_symbol - a symbol which follows the section, and thus signals its end. text - the content or fragment, which shall be scrutinized.
# File lib/fsobjects.rb, line 154 def self::get_sections(section, next_symbol, text) return text.split(SECTIONS[section]).collect do |s| if !s.empty? s = s.split(next_symbol)[0].strip s.length > 1 ? s: nil end end.compact end
ini_for_short_name(sn, dir)
click to toggle source
# File lib/fsobjects.rb, line 200 def self::ini_for_short_name(sn, dir) list = read_config(dir) nend = CONFIG + INI list.detect {|fn| fn == sn + nend} end
maxSectionNumber(text, sectionPattern)
click to toggle source
Find the highest button-number in the target-file if applicable
# File lib/fsobjects.rb, line 127 def self::maxSectionNumber(text, sectionPattern) text.lines.collect do |l| label = l.match(sectionPattern) if(label) label[0].match(/\d{1,3}/)[0].to_i end end.compact.max end
read_config(dir)
click to toggle source
Called by other static members of this class, read_config
will just create the list of config-files in the given directory.
# File lib/fsobjects.rb, line 216 def self::read_config(dir) begin @@entries = Dir.entries(dir) rescue Exception => ex UserIO::msg_cannot_read_dir(dir, ex) exit false end @@entries.collect! {|fo| fo if fo.end_with?(CONFIG + INI) }.compact! if(@@entries.empty?) UserIO::msg_conf_dir_empty("Config-files look like this: *" << CONFIG << INI) exit false end @@entries end
short_names(dir)
click to toggle source
Returns an array of short application designators.
# File lib/fsobjects.rb, line 207 def self::short_names(dir) list = read_config(dir) nend = CONFIG + INI list.collect{|n| n.sub(nend, '') } end
vacantSectionNumbers(text, sectionPattern, max)
click to toggle source
Find and return a list of unallocated section numbers.
# File lib/fsobjects.rb, line 137 def self::vacantSectionNumbers(text, sectionPattern, max) sections = text.match(sectionPattern) if sections && sections.length > 0 section = sections[0].match(/(\D*)\d*\]/)[1] (1..max).collect do |n| n if !text.include?(section + n.to_s + ']') end.compact else [] end end