Guest User

Untitled

a guest
Aug 19th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. class Machine < Struct.new(:name,:ipaddress,:role,:env)
  2. def print_machine_csv
  3. name.length==0 ? printf(",") : printf("\"%s\",", name)
  4. address.length==0 ? printf(",") : printf("\"%s\",", address)
  5. role.length==0 ? printf(",") : printf("\"%s\",", role)
  6. env.length==0 ? printf(",") : printf("\"%s\",", env)
  7. printf("\n")
  8. end
  9. end unless defined? Machine
  10.  
  11. require 'csv'
  12. class NewMachine
  13. attr_accessor :name, :ipaddress, :role, :env
  14.  
  15. def initialize(name, ipaddress, role, env)
  16. @name, @ipaddress, @role, @env = name, ipaddress, role, env
  17. end
  18.  
  19. def to_csv
  20. [name, ipaddress, role, env].to_csv
  21. end
  22. end
Add Comment
Please, Sign In to add comment