module Timelime

Constants

VERSION

Public Class Methods

dump(axis) click to toggle source
# File lib/timelime/dump.rb, line 3
def self.dump axis

  data = axis.buffer

  for c in 0...data[0].size
    for l in 0...data[0][c].size
      if l - 1 < 0 or l + 1 >= data[0][c].size
        next
      end
      e = data[0][c][l]
      check = [e.to_s, "*"]
      above = data[0][c][l - 1].to_s
      below = data[0][c][l + 1].to_s
      if e.nil?
        next
      elsif check.include? above and check.include? below
        data[0][c][l] = "*"
      end
    end
  end

  data.map! do |s|
    s.map! do |c|
      c.map! do |e|
        if e.class == Timelime::Event
          "[#{e.head}]"
        elsif !e.nil? and e == "*"
          "* "
        else
          e
        end
      end
    end
  end

  tabs = [
    Array.new(data[0].size, 0),
    Array.new(data[1].size, 0),
  ]

  for s in 0..1
    for c in 0...data[s].size
      for l in 0...axis.lines
        tmp = data[s][c][l].to_s.length
        if tmp > tabs[s][c]
          tabs[s][c] = tmp
        end
      end
    end
  end

  data[0] = data[0].transpose
  data[1] = data[1].transpose

  buf = []

  for l in 0...axis.lines

    buf += [""]

    for s in 0..1

      if s == 1
        buf[-1] += " │ " + tab(axis.label(l), 6, 0) + " │ "
      end

      if data[s][l].nil?
        next
      end

      data[s][l].each_with_index do |txt, c|

        buf[-1] += tab(txt, tabs[s][c], s)

      end

    end

  end

  buf.each do |line|
    puts line
  end

end
parse(path) { |buf, number| ... } click to toggle source
# File lib/timelime/parse.rb, line 3
def self.parse path

  lines = IO.readlines(path)
  lines += ["FEND"]
  number = 0
  err = false
  buf = nil

  lines.each do |line|

    number += 1
    begin

      line.rstrip!
      if line.empty?
        next
      end

      # new entry
      if line.lstrip == line
        if !buf.nil? and !err and buf.complete?
          yield(buf, number)
        end
        buf = Timelime::Event.new(line)
        err = false
        next
      end

      if err
        next
      end

      line.strip!
      case line[0]
      when "*"
        buf.time.push(line)
      when "@"
        buf.tags.push(line)
      else
      end

    rescue
      err = true
      $stderr.puts "WARN: invalid definition: #{path} line #{number}"
      $stderr.puts "      skipping to next entry"
    end

  end

end

Private Class Methods

tab(txt, num, side = 1) click to toggle source
# File lib/timelime/dump.rb, line 91
def self.tab(txt, num, side = 1)
  txt = txt.to_s
  buf = " "
  if side == 0
    buf += " " * (num - txt.size)
  end
  buf += txt
  if side == 1
    buf += " " * (num - txt.size)
  end
  buf += " "
  buf
end