Module: Polygonfy

Defined in:
lib/polygonfy.rb,
lib/polygonfy/Point.rb,
lib/polygonfy/Polygon.rb,
lib/polygonfy/version.rb

Defined Under Namespace

Classes: Point, Polygon

Constant Summary collapse

VERSION =
"0.2.3"

Class Method Summary collapse

Class Method Details

.runObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/polygonfy.rb', line 6

def self.run
  if ARGV.length == 0
    puts "Use: polygonfy filename [id,x,y] [id,x,y] [..]"
    return
  end

  points = ARGV.length > 1 ? ARGV.drop(1) : STDIN.readline.split(' ')

  points.map! do |p|
    id, x, y = p.split(',')
    Point.new(id, x.to_i, y.to_i)
  end

  polygon = Polygon.new(points)

  File.open(ARGV[0], 'w') do |f|
    f.write(polygon.to_xml)
  end
end