ShapeDoc 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/ShapeStruct.rb +13 -0
- data/lib/shapedoc.rb +100 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cb206204bb4a91950eb04506a21295742c3dbd4e
|
4
|
+
data.tar.gz: 0da09dfbb07091ba1964f7cc601d63e84d9300c0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ff978801889361bdc88bab8ec06be05e316c6a03814fec81a1588586a35d4e193a2a028d374603f215e48b47a628970ac54e0e4fdf0b6a032fb00abcdcb0e096
|
7
|
+
data.tar.gz: 0e7cf14ada02757503da2015584428b7b250d2fdd32b397d3fbb94a992a44e66c754d787a96152851861d646b033e22898e7d2e552ee7e5e395b5e68bd2ab7a7
|
data/lib/ShapeStruct.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
def Polygon(*sides)
|
2
|
+
s, s.sides = Polygon.new(sides), Array.new
|
3
|
+
for side in sides; s.sides << side; end
|
4
|
+
return s
|
5
|
+
end
|
6
|
+
def Quad(side1=rand, side2=rand, side3=rand, side4=rand); Quadrilateral.new(side1, side2, side3, side4); end
|
7
|
+
def Rect( l = rand, w = rand ); Rectangle.new(l,w); end
|
8
|
+
def Square(s = rand); Square.new(s); end
|
9
|
+
def Rhombus(arg = Hash.new); Rhombus.new arg; end
|
10
|
+
def Tri(s1=rand, s2=rand, s3=rand, arg = Hash.new); Triangle.new s1, s2, s3, arg; end
|
11
|
+
def Circle(r = rand); Circle.new r; end
|
12
|
+
def Parallel(args = Hash.new(0)); Parallelogram.new(args); end
|
13
|
+
def Pentagon(arg = rand); Pentagon.new arg; end
|
data/lib/shapedoc.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
require_relative "Shapestruct.rb"
|
2
|
+
class Polygon
|
3
|
+
attr_accessor :sides
|
4
|
+
def _sides; @sides.length; end
|
5
|
+
def initialize(*sides)
|
6
|
+
@sides, i = sides, 0
|
7
|
+
for side in @sides
|
8
|
+
side = @sides[i]
|
9
|
+
i += 1
|
10
|
+
end
|
11
|
+
end
|
12
|
+
def perimeter
|
13
|
+
p = 0
|
14
|
+
for side in @sides; p += side; end
|
15
|
+
return p
|
16
|
+
end
|
17
|
+
end
|
18
|
+
class Quadrilateral < Polygon
|
19
|
+
def _sides; 4; end
|
20
|
+
def initialize(side1, side2, side3, side4)
|
21
|
+
@sidelength = [side1, side2, side3, side4]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
class Rectangle < Quadrilateral
|
25
|
+
attr_reader :length, :width
|
26
|
+
def initialize(length, width); @length, @width = length, width; end
|
27
|
+
def perimeter; @width*2+@length*2; end
|
28
|
+
def area; @length*@width; end
|
29
|
+
def diagram; "\u25AD"; end
|
30
|
+
end
|
31
|
+
class Square < Rectangle
|
32
|
+
attr_reader :side
|
33
|
+
def initialize(side); @side = side; end
|
34
|
+
def perimeter; @side*4; end
|
35
|
+
def area; @side**2; end
|
36
|
+
def diagram
|
37
|
+
if @side < 25; "\u2b1e"
|
38
|
+
elsif @side < 50; "\u25ab"
|
39
|
+
elsif @side < 75; "\u25fb"
|
40
|
+
else; "\u2b1c"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
class Rhombus < Quadrilateral
|
45
|
+
attr_reader :base, :height, :side
|
46
|
+
def initialize(arg = Hash.new(0)); @base, @height, @side = arg[:base], arg[:height], arg[:side]; end
|
47
|
+
def area; (@base*@height)/2; end
|
48
|
+
def perimeter; @side**2; end
|
49
|
+
end
|
50
|
+
class Triangle < Polygon
|
51
|
+
def _sides; 3; end
|
52
|
+
attr_reader :base, :height
|
53
|
+
def initialize(s1, s2, s3, arg = Hash.new); @base, @height, @sides = arg[:base], arg[:height], [s1, s2, s3]; end
|
54
|
+
def area; (@base*@height)/2; end
|
55
|
+
def diagram
|
56
|
+
if self.equilateral?; "\u25b3"
|
57
|
+
else; "\u22bf"; end
|
58
|
+
end
|
59
|
+
def equilateral?
|
60
|
+
s, eq = @sides[1], true
|
61
|
+
for side in @sides
|
62
|
+
eq = false unless side == s
|
63
|
+
s = side
|
64
|
+
end
|
65
|
+
return eq
|
66
|
+
end
|
67
|
+
def isosceles?
|
68
|
+
unless self.equilateral?
|
69
|
+
if (@sides[0] == @sides[1] && @sides[0] != @sides[2]) || (@sides[0] != @sides[1] && @sides[0] == @sides[2]); return true
|
70
|
+
else return false
|
71
|
+
end
|
72
|
+
else; return false
|
73
|
+
end
|
74
|
+
end
|
75
|
+
def scalene?
|
76
|
+
true unless self.equilateral? || self.isosceles?
|
77
|
+
end
|
78
|
+
end
|
79
|
+
class Circle
|
80
|
+
attr_reader :radius
|
81
|
+
def initialize(radius); @radius = radius; end
|
82
|
+
def circumference; 2*Math::PI*@radius; end
|
83
|
+
def area; Math::PI*@radius**2; end
|
84
|
+
def diagram; "\u25cb"; end
|
85
|
+
end
|
86
|
+
class Parallelogram < Quadrilateral
|
87
|
+
attr_reader :base, :height, :side
|
88
|
+
def initialize(args = Hash.new(0)); @base, @height, @side = args[:base], args[:height], args[:side]; end
|
89
|
+
def area; @base*@height; end
|
90
|
+
def perimeter; @base*2+@side*2; end
|
91
|
+
end
|
92
|
+
class Pentagon < Polygon # Regular Pentagon
|
93
|
+
include Math
|
94
|
+
attr_reader :side
|
95
|
+
def initialize(side); @side = side; end
|
96
|
+
def _sides; 5; end
|
97
|
+
def diagram; "\u2b20"; end
|
98
|
+
def area; (5* @side ** 2 * tan(54))/4; end
|
99
|
+
end
|
100
|
+
__END__
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ShapeDoc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Zachary Perlmutter
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-18 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: |
|
14
|
+
Allows you to use shapes in your application. Shapes include cirles, squares, rectangles, and more.
|
15
|
+
email: zrp200@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/ShapeStruct.rb
|
21
|
+
- lib/shapedoc.rb
|
22
|
+
homepage:
|
23
|
+
licenses: []
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 2.3.0
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: Allows you to use shapes in your applications
|
45
|
+
test_files: []
|