Class: Amline::Settings

Inherits:
Object
  • Object
show all
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

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,options)
 xml = %Q{
  <label>
    <x>#{options[:x]}</x>                                                 
    <y>#{options[:y]}20</y>                                   
    <rotate>#{options[:rotate]}</rotate>                     
    <width>#{options[:width]}</width>                
    <align>#{options[:align]}</align>                       
    <text_color>#{options[:text_color]}</text_color>             
    <text_size>#{options[:text_size]}</text_size>               
    <text>  
      <![CDATA[#{label}]]>
    </text>        
  </label>
} 
@config.root.search("labels").append(xml)
end

#config {|@config.settings| ... } ⇒ Object

Yields:



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

Yields:



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_xmlObject



191
192
193
# File 'lib/ruport/util/graph/amline.rb', line 191

def to_xml
  @config.to_xml
end