linear_graph 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8c38193e5e1bbcf5013c2f2fe45a3adc80344ee2
4
+ data.tar.gz: cef822e6dff8de1c54325566a2174114b172e458
5
+ SHA512:
6
+ metadata.gz: cee3f9e1fe4af21e21e67735f869c5704f56d90aabd9cbdfafa4051982c409ab35964ca41d6e5b217576b75d5f495e7eeab0ce3313bca1506da80176aa0a9bc1
7
+ data.tar.gz: 4913a0af6b0d56f238a5267e2526602daa98c630fc29d36bc4028beba26716c1c33d252a62d03eb33c0e89abb97a1b7a8e49d925a4234df31dd1af7e4b9bfa2b
data/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Zachary Perlmutter
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # quad1
2
+ A gem to graph lines on the first quadrent
3
+ ## Installation
4
+
5
+ | Method |Code|
6
+ |:------:|:---------:|
7
+ |`Gemfile`|`gem 'quad1'`
8
+ |Terminal|`$ gem install quad1`|
9
+ |`.gemspec`|`gem.add_runtime_dependency "quad1"`|
10
+ ## Usage
11
+ `$ coordinate_plane slope y-intercept [--zero]`
12
+
13
+ `$ coordinate_plane --help`
14
+ ## Badges
15
+ [![Build Status](https://travis-ci.org/Zrp200/quad1.svg?branch=master)](https://travis-ci.org/Zrp200/quad1)
data/bin/linear_graph ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ require "linear_graph"
3
+
4
+ if ARGV.include? "--help"
5
+ puts <<HELP
6
+ Usage: coordinate_plane slope y-intercept [--zero] [--help]
7
+ \u00B7 default -> Displays the line of the function in quadrent 1
8
+ \u00B7 --zero -> Displays the zero of the function
9
+ \u00B7 --help -> Displays this message
10
+ HELP
11
+
12
+ elsif ARGV.include? "--zero"
13
+ puts LinearGraph.(ARGV[0].to_f, ARGV[1].to_f).zero
14
+ exit
15
+ else
16
+ puts LinearGraph.new(ARGV[0].to_f, ARGV[1].to_f)
17
+ end
@@ -0,0 +1,125 @@
1
+ class LinearGraph
2
+
3
+ @@borders, @@x_axis, @@y_axis = true, 140, 70
4
+
5
+ def self.x_axis
6
+ (0..(@@x_axis)).to_a
7
+ end
8
+
9
+ def self.x_axis=(num)
10
+ caa(num)
11
+ @@x_axis = num
12
+ end
13
+
14
+ def self.y_axis
15
+ (0..(@@y_axis)).to_a
16
+ end
17
+
18
+ def self.y_axis=(num)
19
+ caa num
20
+ @@y_axis = num
21
+ end
22
+
23
+ def self.has_borders?
24
+ @@borders
25
+ end
26
+ def graph
27
+ y = -1
28
+ graph = Array.new(@@y_axis) do
29
+ y += 1
30
+ x = -1
31
+ Array.new(@@x_axis) do
32
+ x += 1
33
+ format_pair x, y
34
+ end
35
+ end
36
+ end
37
+
38
+ def self.borders=(bool)
39
+ raise ArgumentError, "Argument must be true or false" unless bool == true | false
40
+ @@borders = bool
41
+ end
42
+
43
+ # @return [Integer] the x intercept of the graph
44
+ attr_reader :slope
45
+ alias m slope
46
+
47
+ attr_reader :y_intercept
48
+ alias b y_intercept
49
+
50
+ def initialize(slope, y_int)
51
+ @slope, @y_intercept = slope, y_int
52
+ end
53
+
54
+ def x_intercept
55
+ f(0)
56
+ end
57
+ alias x_int x_intercept
58
+ alias zero x_intercept
59
+ alias solution x_intercept
60
+
61
+ =begin
62
+ The XY table
63
+ @note There are no floats
64
+ @return [Hash]
65
+ =end
66
+ def xy
67
+ table = Hash.new
68
+ for y in LinearGraph.y_axis
69
+ for x in LinearGraph.x_axis
70
+ table[y] = x if f(x) == y
71
+ end
72
+ end
73
+ return table
74
+ end
75
+
76
+ def domain # @return [Array<Integer>] the values of the xy hash
77
+ xy.values
78
+ end
79
+
80
+ def range # @return [Array<Integer>] the keys of the xy hash
81
+ xy.keys
82
+ end
83
+
84
+ =begin
85
+ Displays graph
86
+ @return [String] the graph
87
+ =end
88
+ def to_s
89
+ result = String.new
90
+ for y_index in graph.reverse
91
+ for x_index in y_index
92
+ result << x_index
93
+ end
94
+ result << ?\n
95
+ end
96
+ return result.center 80
97
+ end
98
+
99
+ def f(x)
100
+ @slope * x + @y_intercept
101
+ end
102
+
103
+ private
104
+
105
+ def check_axis_argument(arg)
106
+ if !(num.kind_of?(Integer) )
107
+ raise ArgumentError, "Argument must be a kind of Integer"
108
+ elsif num % 2 != 0
109
+ raise ArgumentError, "Argument must be even"
110
+ end
111
+ end
112
+
113
+ alias caa check_axis_argument
114
+
115
+ def format_pair(x, y)
116
+ if @@borders && ( (x == 0 || x == @@x_axis - 1) || (y == 0 || y == @@y_axis - 1 ) )
117
+ "#"
118
+ elsif xy[y] == x
119
+ ?\u00B7
120
+ else
121
+ " "
122
+ end
123
+ end
124
+
125
+ end
@@ -0,0 +1,12 @@
1
+ require "linear_graph"
2
+ RSpec.describe LinearGraph
3
+ it {is_expected.to have_borders}
4
+ describe "#new" do
5
+ describe "f(x)" do
6
+ context "slope, y_int, x = 1, 0, 5" do
7
+ subject {(Quad1.new 1, 0).f(5)}
8
+ it {is_expected.to eq 5}
9
+ end
10
+ end
11
+ end
12
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: linear_graph
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Zachary Perlmutter
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-02 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email: zrp200@gmail.com
15
+ executables:
16
+ - linear_graph
17
+ extensions: []
18
+ extra_rdoc_files:
19
+ - LICENSE.md
20
+ - README.md
21
+ files:
22
+ - LICENSE.md
23
+ - README.md
24
+ - bin/linear_graph
25
+ - lib/linear_graph.rb
26
+ - spec/lib/linear_graph_spec.rb
27
+ homepage:
28
+ licenses:
29
+ - MIT
30
+ metadata: {}
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ requirements:
46
+ - Terminal length => 70
47
+ - Terminal width => 140
48
+ rubyforge_project:
49
+ rubygems_version: 2.4.5
50
+ signing_key:
51
+ specification_version: 4
52
+ summary: A gem to graph lines
53
+ test_files:
54
+ - spec/lib/linear_graph_spec.rb
55
+ has_rdoc: