Class: Remotebackup::Node
- Inherits:
-
Object
- Object
- Remotebackup::Node
- Defined in:
- lib/node.rb
Constant Summary collapse
- Month =
{"Jan" => 1, "Feb" => 2, "Mar" => 3, "Apr" => 4, "May" => 5, "Jun" => 6, "Jul" => 7, "Aug" => 8, "Sep" => 9, "Oct" => 10, "Nov" => 11, "Dec" => 12}
- LS_INFO =
{ :redhat => { :ls_file => /([-a-z]*)\s+(\d+)\s+(\S+)\s+(\S+)\s+(\d*)\s+([A-Z][a-z]*)\s+(\d+)\s+([\d:]*)\s+(.*)/, :ls_link => /([-a-z]*)\s+(\d+)\s+(\S+)\s+(\S+)\s+(\d*)\s+([A-Z][a-z]*)\s+(\d+)\s+([\d:]*)\s+(.*)\s+->\s+(.*)/, :position => {:access=>1,:link_num=>2,:user=>3,:group=>4,:size=>5,:month=>6,:day=>7,:yt=>8,:name=>9,:arrow=>10,:source=>11} }, :debian => { :ls_file => /([-a-z]*)\s+(\d+)\s+(\S+)\s+(\S+)\s+(\d*)\s+([-0-9]*)\s+([\d:]*)\s+(.*)/, :ls_link => /([-a-z]*)\s+(\d+)\s+(\S+)\s+(\S+)\s+(\d*)\s+([-0-9]*)\s+([\d:]*)\s+(.*)\s+->\s+(.*)/, :position => {:access=>1,:link_num=>2,:user=>3,:group=>4,:size=>5,:day =>6,:time =>7,:name=>8,:arrow=>9,:source=>10} } }
Instance Attribute Summary collapse
-
#ftype ⇒ Object
Returns the value of attribute ftype.
-
#make_map ⇒ Object
Returns the value of attribute make_map.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(type, out) ⇒ Node
constructor
A new instance of Node.
- #ls_file ⇒ Object
- #ls_link ⇒ Object
- #position ⇒ Object
- #to_date_time(match) ⇒ Object
Constructor Details
#initialize(type, out) ⇒ Node
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/node.rb', line 62 def initialize(type,out) @type = type case out when /^-/ if m = ls_file.match(out) @ftype = :file @name = m[position[:name]] @size = m[position[:size]].to_i @date = to_date_time(m) @make_map = lambda{ return {"size" => @size, "date" => @date}} end when /^l/ if m = ls_link.match(out) @ftype = :symbolic @name = m[position[:name]] @source = m[position[:source]] @make_map = lambda{ return {"source" => @source}} end when /^d/ if m = ls_file.match(out) @ftype = :directory @name = m[position[:name]] end else @ftype = :special $log.error("#{out} is not regular file. ignore.") end end |
Instance Attribute Details
#ftype ⇒ Object
Returns the value of attribute ftype.
3 4 5 |
# File 'lib/node.rb', line 3 def ftype @ftype end |
#make_map ⇒ Object
Returns the value of attribute make_map.
3 4 5 |
# File 'lib/node.rb', line 3 def make_map @make_map end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/node.rb', line 3 def name @name end |
Class Method Details
Instance Method Details
#ls_file ⇒ Object
50 51 52 |
# File 'lib/node.rb', line 50 def ls_file LS_INFO[@type][:ls_file] end |
#ls_link ⇒ Object
54 55 56 |
# File 'lib/node.rb', line 54 def ls_link LS_INFO[@type][:ls_link] end |
#position ⇒ Object
58 59 60 |
# File 'lib/node.rb', line 58 def position LS_INFO[@type][:position] end |
#to_date_time(match) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/node.rb', line 30 def to_date_time(match) if @type == :redhat month = Month[match[position[:month]]] day = match[position[:day]].to_i hour = 0 minute = 0 tmp_time = match[position[:yt]] if t = /(.*):(.*)/.match(tmp_time) year = DateTime.now.year hour = t[1].to_i minute = t[2].to_i else year = tmp_time.to_i end DateTime.new(year,month,day,hour,minute).to_s else DateTime.parse(match[position[:time]]).to_s end end |