Class: Amline::Settings
- Inherits:
-
Object
- Object
- Amline::Settings
- Defined in:
- lib/ruport/util/graph/amline.rb
Constant Summary collapse
- SETTINGS_FILE =
File.join(Ruport::Util::BASEDIR, 'example', 'data', 'amline_settings.xml')
- GRAPH_FILE =
File.join(Ruport::Util::BASEDIR, 'example','data', 'amline_graph.xml')
Instance Method Summary collapse
- #add_graph(gid) ⇒ Object
- #add_label(label, options) ⇒ Object
- #config {|@config.settings| ... } ⇒ Object
- #graph(gid) {|HpricotTraverser.new(@config.root.search("graph[@gid=#{gid}]"))| ... } ⇒ Object
-
#initialize(settings_file = SETTINGS_FILE, graph_file = GRAPH_FILE) ⇒ Settings
constructor
A new instance of Settings.
- #save(file) ⇒ Object
- #to_xml ⇒ Object
Constructor Details
#initialize(settings_file = SETTINGS_FILE, graph_file = GRAPH_FILE) ⇒ Settings
Returns a new instance of Settings.
153 154 155 156 |
# File 'lib/ruport/util/graph/amline.rb', line 153 def initialize(settings_file=SETTINGS_FILE,graph_file=GRAPH_FILE) @config = HpricotTraverser.new(Hpricot(File.read(settings_file))) @graph_file = graph_file end |
Instance Method Details
#add_graph(gid) ⇒ Object
181 182 183 184 185 |
# File 'lib/ruport/util/graph/amline.rb', line 181 def add_graph(gid) new_graph = Hpricot(File.read(@graph_file)) new_graph.at("graph")["gid"] = gid @config.root.search("graphs").append new_graph.to_s end |
#add_label(label, options) ⇒ Object
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/ruport/util/graph/amline.rb', line 163 def add_label(label,) xml = %Q{ <label> <x>#{[:x]}</x> <y>#{[:y]}20</y> <rotate>#{[:rotate]}</rotate> <width>#{[:width]}</width> <align>#{[:align]}</align> <text_color>#{[:text_color]}</text_color> <text_size>#{[:text_size]}</text_size> <text> <![CDATA[#{label}]]> </text> </label> } @config.root.search("labels").append(xml) end |
#config {|@config.settings| ... } ⇒ Object
158 159 160 161 |
# File 'lib/ruport/util/graph/amline.rb', line 158 def config yield @config.settings if block_given? @config.settings end |
#graph(gid) {|HpricotTraverser.new(@config.root.search("graph[@gid=#{gid}]"))| ... } ⇒ Object
187 188 189 |
# File 'lib/ruport/util/graph/amline.rb', line 187 def graph(gid) yield HpricotTraverser.new(@config.root.search("graph[@gid=#{gid}]")) end |
#save(file) ⇒ Object
195 196 197 |
# File 'lib/ruport/util/graph/amline.rb', line 195 def save(file) File.open(file,"w") { |f| f << @config.to_s } end |
#to_xml ⇒ Object
191 192 193 |
# File 'lib/ruport/util/graph/amline.rb', line 191 def to_xml @config.to_xml end |