Class: Umlify::Runner
- Inherits:
-
Object
- Object
- Umlify::Runner
- Defined in:
- lib/umlify/runner.rb
Overview
Class to run to execute umlify. It parses the ruby sources provided and generates and save a uml diagram using yUML API.
Instance Attribute Summary collapse
-
#smart_mode ⇒ Object
readonly
Returns the value of attribute smart_mode.
Instance Method Summary collapse
-
#download_image ⇒ Object
Downloads the image of the uml diagram from yUML.
-
#initialize(args) ⇒ Runner
constructor
Takes as input an array with file names.
- #parse_options ⇒ Object
-
#run ⇒ Object
Runs the application.
-
#save_to_file(image) ⇒ Object
Saves the diagram to file.
Constructor Details
#initialize(args) ⇒ Runner
Takes as input an array with file names
13 14 15 16 |
# File 'lib/umlify/runner.rb', line 13 def initialize args @args = args @smart_mode = false end |
Instance Attribute Details
#smart_mode ⇒ Object (readonly)
Returns the value of attribute smart_mode.
10 11 12 |
# File 'lib/umlify/runner.rb', line 10 def smart_mode @smart_mode end |
Instance Method Details
#download_image ⇒ Object
Downloads the image of the uml diagram from yUML
61 62 63 64 65 |
# File 'lib/umlify/runner.rb', line 61 def download_image Net::HTTP.start("yuml.me", 80) do |http| http.get(URI.escape(@diagram.get_uri)) end end |
#parse_options ⇒ Object
54 55 56 57 58 |
# File 'lib/umlify/runner.rb', line 54 def OptionParser.new do |opts| opts.on("-s", "--smart") { @smart_mode = true } end.parse! @args end |
#run ⇒ Object
Runs the application
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/umlify/runner.rb', line 19 def run if @args.empty? puts "Usage: umlify [source directory]" else puts "umlifying" @parser = ParserSexp.new @args if classes = @parser.parse_sources! @diagram = Diagram.new if @smart_mode classes.each {|c| c.infer_types! classes} end @diagram.create do classes.each {|c| add c} end.compute! puts "Downloading the image from yUML, it shouldn't be long." image = download_image save_to_file image puts 'http://yuml.me'+@diagram.get_uri puts "Saved in uml.png" else puts "No ruby files in the directory" end end end |
#save_to_file(image) ⇒ Object
Saves the diagram to file
68 69 70 71 72 |
# File 'lib/umlify/runner.rb', line 68 def save_to_file image File.open('uml.png', 'wb') do |file| file << image.body end if image end |