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
-
#html_mode ⇒ Object
readonly
Returns the value of attribute html_mode.
-
#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 17 |
# File 'lib/umlify/runner.rb', line 13 def initialize args @args = args @smart_mode = false @html_mode = false end |
Instance Attribute Details
#html_mode ⇒ Object (readonly)
Returns the value of attribute html_mode.
10 11 12 |
# File 'lib/umlify/runner.rb', line 10 def html_mode @html_mode end |
#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
63 64 65 66 67 |
# File 'lib/umlify/runner.rb', line 63 def download_image Net::HTTP.start("yuml.me", 80) do |http| http.get(URI.escape(@diagram.get_uri)) end end |
#parse_options ⇒ Object
55 56 57 58 59 60 |
# File 'lib/umlify/runner.rb', line 55 def OptionParser.new do |opts| opts.on("-s", "--smart") { @smart_mode = true } opts.on("-h", "--html") { @html_mode = true } end.parse! @args end |
#run ⇒ Object
Runs the application
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 53 |
# File 'lib/umlify/runner.rb', line 20 def run if @args.empty? puts "Usage: umlify [source directory]" else puts "umlifying" @parser_sexp = ParserSexp.new @args if classes = @parser_sexp.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 if @html_mode 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
70 71 72 73 74 |
# File 'lib/umlify/runner.rb', line 70 def save_to_file image File.open('uml.png', 'wb') do |file| file << image.body end if image end |