class OFlow::Graffle
Attributes
line_info[RW]
name[RW]
task_info[RW]
Public Class Methods
get_key_value(nodes, key)
click to toggle source
# File lib/oflow/graffle.rb, line 93 def self.get_key_value(nodes, key) return if nodes.nil? nodes.each_with_index do |node,i| next unless 'key' == node.name && key == node.text n = nodes[i + 1] if 'dict' == n.name || 'array' == n.name return n.nodes else return n.text end end nil end
get_text(nodes)
click to toggle source
# File lib/oflow/graffle.rb, line 107 def self.get_text(nodes) return nil if nodes.nil? strip_rtf(get_key_value(nodes, 'Text')) end
load(env, filename)
click to toggle source
# File lib/oflow/graffle.rb, line 11 def self.load(env, filename) doc = Ox.load_file(filename, mode: :generic) g = Graffle.new(env, filename, doc) env.debug(g.to_s()) if Logger::Severity::DEBUG >= ::OFlow::Env.log_level end
new(env, filename, doc)
click to toggle source
# File lib/oflow/graffle.rb, line 17 def initialize(env, filename, doc) @line_info = { } # key is id @task_info = { } # key is id @name = File.basename(filename, '.graffle') nodes = doc.locate('plist/dict')[0].nodes sheets = Graffle.get_key_value(nodes, 'Sheets') if sheets.nil? nodes = Graffle.get_key_value(nodes, 'GraphicsList') else nodes = Graffle.get_key_value(sheets[0].nodes, 'GraphicsList') end raise ConfigError.new("Empty flow.") if nodes.nil? nodes.each do |node| load_node(node) end # set label in lines task_info.each do |id,ti| next if ti.line_id.nil? if !(li = line_info[ti.line_id]).nil? li.label, li.op = ti.first_option end end task_info.each do |_, ti| if ti.name.nil? && !(n = ti.options[:flow]).nil? @name = n.strip end end env.flow(@name.to_sym) { |f| task_info.each_value { |ti| next unless ti.line_id.nil? next if ti.name.nil? c = ti.get_class() next if c.nil? f.task(ti.name, c, ti.options) { |t| t.bounds = ti.bounds t.color = ti.color t.shape = ti.shape line_info.each_value { |li| next unless li.tail == ti.id target_info = task_info[li.head] if target_info.nil? flow_name, task_name, op = li.op.split('/') t.link(li.label, task_name, op, flow_name) else t.link(li.label, target_info.name, li.op) end } } } } end
rtf_ctrl_char(ctrl)
click to toggle source
# File lib/oflow/graffle.rb, line 172 def self.rtf_ctrl_char(ctrl) c = '' case ctrl when '', 'line' c = "\n" when 'tab' c = "\t" else if "'" == ctrl[0] c = ctrl[1..3].hex().chr end end c end
strip_rtf(rtf)
click to toggle source
# File lib/oflow/graffle.rb, line 112 def self.strip_rtf(rtf) return rtf unless rtf.start_with?('{\rtf') depth = 0 txt = '' ctrl = nil str = nil rtf.each_char do |c| case c when ' ' if !str.nil? str << ' ' unless 1 < depth elsif !ctrl.nil? txt << rtf_ctrl_char(ctrl) unless 1 < depth ctrl = nil str = '' else str = '' end when "\n", "\r" if !str.nil? # should not happen but... str << "\n" unless 1 < depth elsif !ctrl.nil? txt << rtf_ctrl_char(ctrl) unless 1 < depth ctrl = nil end when '\\' if !str.nil? txt << str unless 1 < depth str = nil elsif !ctrl.nil? txt << rtf_ctrl_char(ctrl) unless 1 < depth end ctrl = '' when '{' if !ctrl.nil? txt << rtf_ctrl_char(ctrl) unless 1 < depth ctrl = nil end depth += 1 when '}' if !ctrl.nil? txt << rtf_ctrl_char(ctrl) unless 1 < depth ctrl = nil end depth -= 1 else if !ctrl.nil? ctrl << c elsif 1 < depth # ignore else str = '' if str.nil? str << c end end end txt << str unless str.nil? txt end
Public Instance Methods
load_node(node)
click to toggle source
# File lib/oflow/graffle.rb, line 72 def load_node(node) nodes = node.nodes case Graffle.get_key_value(nodes, 'Class') when 'LineGraphic' line = LineInfo.new(nodes) @line_info[line.id] = line when 'ShapedGraphic' task = TaskInfo.new(nodes) @task_info[task.id] = task unless task.nil? end end
to_s()
click to toggle source
# File lib/oflow/graffle.rb, line 84 def to_s() s = "Graffle{\n name: #{@name}\n tasks{\n" task_info.each { |_,ti| s += " #{ti}\n" } s += " }\n lines{\n" line_info.each { |_,li| s += " #{li}\n" } s += " }\n}\n" s end