diff --git a/final/.rspec b/final/.rspec new file mode 100644 index 0000000..b3eb8b4 --- /dev/null +++ b/final/.rspec @@ -0,0 +1,2 @@ +--color +--format documentation \ No newline at end of file diff --git a/final/README.md b/final/README.md new file mode 100644 index 0000000..70c1bd2 --- /dev/null +++ b/final/README.md @@ -0,0 +1,13 @@ +Instructions For Using The RadianDegreeConverter +------------------------------------------------ + +This converter will convert radians to decimal degrees or decimal degrees to radians. It can be run from the command line using the executable or added to your code with the require statement. Note that input validation is done to ensure the input is a float compatible number. If it is not, the conversion will be aborted and an error message will be returned. + +To install the gem: +* gem install radian_degree_converter + +To run from the command line: +* radian_degree_converter + +To add to your code: +* require 'radian_degree_converter' \ No newline at end of file diff --git a/final/Rakefile.rb b/final/Rakefile.rb new file mode 100644 index 0000000..8e2175c --- /dev/null +++ b/final/Rakefile.rb @@ -0,0 +1,5 @@ +require 'rspec/core/rake_task' + +RSpec::Core::RakeTask.new('spec') + +task :default => :spec \ No newline at end of file diff --git a/final/bin/radian_degree_converter b/final/bin/radian_degree_converter new file mode 100755 index 0000000..0c5f69b --- /dev/null +++ b/final/bin/radian_degree_converter @@ -0,0 +1,28 @@ +#!/usr/bin/env ruby + +require 'radian_degree_converter' + +@converter = RadianDegreeConverter.new +puts "Select one of the following options:" +puts "\t1. To convert radians to decimal degrees" +puts "\t2. To convert decimal degrees to radians" +print "\nEnter 1 or 2: " + +option = gets.chomp +if option == '1' + print "Enter radians value: " + r_value = gets + result = @converter.convert_radians_to_degrees(r_value) + if (!result.nil?) + puts "The decimal degrees equivalent is #{result}" + end +elsif option == '2' + print "Enter decimal degrees value: " + d_value = gets + result = @converter.convert_degrees_to_radians(d_value) + if (!result.nil?) + puts "The radians equivalent is #{result}" + end +else + puts "Invalid selection" +end \ No newline at end of file diff --git a/final/doc/RadianDegreeConverter.html b/final/doc/RadianDegreeConverter.html new file mode 100644 index 0000000..d996268 --- /dev/null +++ b/final/doc/RadianDegreeConverter.html @@ -0,0 +1,299 @@ + + + + + + +class RadianDegreeConverter - RDoc Documentation + + + + + + + + + + + + + + + + + +
+

+ class RadianDegreeConverter +

+ +
+ +

This class converts radians to decimal degrees and decimal degrees to +radians. It will validate the method input to make sure it is float +compatible and return an error message if the input cannot be converted to +a float.

+
Author +
+

Kevin LaFave

+
License +
+

MIT

+
+ +
+ + + + +
+ + + + + + + + + +
+
+

Public Instance Methods

+
+ + +
+ +
+ convert_degrees_to_radians(input) + + click to toggle source + +
+ + +
+ +

This method converts decimal degrees to its radians equivalent.

+
  • +

    input : The decimal degree value that needs to be converted to radians.

    +
+ + + + +
+
# File lib/radian_degree_converter.rb, line 39
+def convert_degrees_to_radians input
+        if is_numeric? input
+                @result = input.to_f * 0.0174532925
+        else
+                error_message
+                @result = nil
+        end
+end
+
+ +
+ + + + +
+ + +
+ +
+ convert_radians_to_degrees(input) + + click to toggle source + +
+ + +
+ +

This method converts radians to its decimal degrees equivalent.

+
  • +

    input : The radian value that needs to be converted to decimal degrees.

    +
+ + + + +
+
# File lib/radian_degree_converter.rb, line 28
+def convert_radians_to_degrees input
+        if is_numeric? input
+                @result = input.to_f * 57.2957795
+        else
+                error_message
+                @result = nil
+        end
+end
+
+ +
+ + + + +
+ + +
+ +
+ error_message() + + click to toggle source + +
+ + +
+ +

This method returns an error message when the convert method input was not +float compatible.

+ + + + +
+
# File lib/radian_degree_converter.rb, line 22
+def error_message
+        puts "Invalid input. Must enter an integer or decimal number"
+end
+
+ +
+ + + + +
+ + +
+ +
+ is_numeric?(input) + + click to toggle source + +
+ + +
+ +

This method validates the input to see if it is float compatible.

+
  • +

    input : The value that needs to be validated.

    +
+ + + + +
+
# File lib/radian_degree_converter.rb, line 11
+def is_numeric? input
+        begin
+                Float(input)
+        rescue
+                false
+        else
+                true
+        end
+end
+
+ +
+ + + + +
+ + +
+ +
+
+ + + + diff --git a/final/doc/created.rid b/final/doc/created.rid new file mode 100644 index 0000000..fbc5250 --- /dev/null +++ b/final/doc/created.rid @@ -0,0 +1,2 @@ +Sat, 08 Mar 2014 20:11:31 -0800 +lib/radian_degree_converter.rb Sat, 08 Mar 2014 20:11:08 -0800 diff --git a/final/doc/fonts.css b/final/doc/fonts.css new file mode 100644 index 0000000..e9e7211 --- /dev/null +++ b/final/doc/fonts.css @@ -0,0 +1,167 @@ +/* + * Copyright 2010, 2012 Adobe Systems Incorporated (http://www.adobe.com/), + * with Reserved Font Name "Source". All Rights Reserved. Source is a + * trademark of Adobe Systems Incorporated in the United States and/or other + * countries. + * + * This Font Software is licensed under the SIL Open Font License, Version + * 1.1. + * + * This license is copied below, and is also available with a FAQ at: + * http://scripts.sil.org/OFL + */ + +@font-face { + font-family: "Source Code Pro"; + font-style: normal; + font-weight: 400; + src: local("Source Code Pro"), + local("SourceCodePro-Regular"), + url("fonts/SourceCodePro-Regular.ttf") format("truetype"); +} + +@font-face { + font-family: "Source Code Pro"; + font-style: normal; + font-weight: 700; + src: local("Source Code Pro Bold"), + local("SourceCodePro-Bold"), + url("fonts/SourceCodePro-Bold.ttf") format("truetype"); +} + +/* + * Copyright (c) 2010, Łukasz Dziedzic (dziedzic@typoland.com), + * with Reserved Font Name Lato. + * + * This Font Software is licensed under the SIL Open Font License, Version + * 1.1. + * + * This license is copied below, and is also available with a FAQ at: + * http://scripts.sil.org/OFL + */ + +@font-face { + font-family: "Lato"; + font-style: normal; + font-weight: 300; + src: local("Lato Light"), + local("Lato-Light"), + url("fonts/Lato-Light.ttf") format("truetype"); +} + +@font-face { + font-family: "Lato"; + font-style: italic; + font-weight: 300; + src: local("Lato Light Italic"), + local("Lato-LightItalic"), + url("fonts/Lato-LightItalic.ttf") format("truetype"); +} + +@font-face { + font-family: "Lato"; + font-style: normal; + font-weight: 700; + src: local("Lato Regular"), + local("Lato-Regular"), + url("fonts/Lato-Regular.ttf") format("truetype"); +} + +@font-face { + font-family: "Lato"; + font-style: italic; + font-weight: 700; + src: local("Lato Italic"), + local("Lato-Italic"), + url("fonts/Lato-RegularItalic.ttf") format("truetype"); +} + +/* + * ----------------------------------------------------------- + * SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 + * ----------------------------------------------------------- + * + * PREAMBLE + * The goals of the Open Font License (OFL) are to stimulate worldwide + * development of collaborative font projects, to support the font creation + * efforts of academic and linguistic communities, and to provide a free and + * open framework in which fonts may be shared and improved in partnership + * with others. + * + * The OFL allows the licensed fonts to be used, studied, modified and + * redistributed freely as long as they are not sold by themselves. The + * fonts, including any derivative works, can be bundled, embedded, + * redistributed and/or sold with any software provided that any reserved + * names are not used by derivative works. The fonts and derivatives, + * however, cannot be released under any other type of license. The + * requirement for fonts to remain under this license does not apply + * to any document created using the fonts or their derivatives. + * + * DEFINITIONS + * "Font Software" refers to the set of files released by the Copyright + * Holder(s) under this license and clearly marked as such. This may + * include source files, build scripts and documentation. + * + * "Reserved Font Name" refers to any names specified as such after the + * copyright statement(s). + * + * "Original Version" refers to the collection of Font Software components as + * distributed by the Copyright Holder(s). + * + * "Modified Version" refers to any derivative made by adding to, deleting, + * or substituting -- in part or in whole -- any of the components of the + * Original Version, by changing formats or by porting the Font Software to a + * new environment. + * + * "Author" refers to any designer, engineer, programmer, technical + * writer or other person who contributed to the Font Software. + * + * PERMISSION & CONDITIONS + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of the Font Software, to use, study, copy, merge, embed, modify, + * redistribute, and sell modified and unmodified copies of the Font + * Software, subject to the following conditions: + * + * 1) Neither the Font Software nor any of its individual components, + * in Original or Modified Versions, may be sold by itself. + * + * 2) Original or Modified Versions of the Font Software may be bundled, + * redistributed and/or sold with any software, provided that each copy + * contains the above copyright notice and this license. These can be + * included either as stand-alone text files, human-readable headers or + * in the appropriate machine-readable metadata fields within text or + * binary files as long as those fields can be easily viewed by the user. + * + * 3) No Modified Version of the Font Software may use the Reserved Font + * Name(s) unless explicit written permission is granted by the corresponding + * Copyright Holder. This restriction only applies to the primary font name as + * presented to the users. + * + * 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font + * Software shall not be used to promote, endorse or advertise any + * Modified Version, except to acknowledge the contribution(s) of the + * Copyright Holder(s) and the Author(s) or with their explicit written + * permission. + * + * 5) The Font Software, modified or unmodified, in part or in whole, + * must be distributed entirely under this license, and must not be + * distributed under any other license. The requirement for fonts to + * remain under this license does not apply to any document created + * using the Font Software. + * + * TERMINATION + * This license becomes null and void if any of the above conditions are + * not met. + * + * DISCLAIMER + * THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT + * OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL + * DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM + * OTHER DEALINGS IN THE FONT SOFTWARE. + */ + diff --git a/final/doc/fonts/Lato-Light.ttf b/final/doc/fonts/Lato-Light.ttf new file mode 100644 index 0000000..b49dd43 Binary files /dev/null and b/final/doc/fonts/Lato-Light.ttf differ diff --git a/final/doc/fonts/Lato-LightItalic.ttf b/final/doc/fonts/Lato-LightItalic.ttf new file mode 100644 index 0000000..7959fef Binary files /dev/null and b/final/doc/fonts/Lato-LightItalic.ttf differ diff --git a/final/doc/fonts/Lato-Regular.ttf b/final/doc/fonts/Lato-Regular.ttf new file mode 100644 index 0000000..839cd58 Binary files /dev/null and b/final/doc/fonts/Lato-Regular.ttf differ diff --git a/final/doc/fonts/Lato-RegularItalic.ttf b/final/doc/fonts/Lato-RegularItalic.ttf new file mode 100644 index 0000000..bababa0 Binary files /dev/null and b/final/doc/fonts/Lato-RegularItalic.ttf differ diff --git a/final/doc/fonts/SourceCodePro-Bold.ttf b/final/doc/fonts/SourceCodePro-Bold.ttf new file mode 100644 index 0000000..61e3090 Binary files /dev/null and b/final/doc/fonts/SourceCodePro-Bold.ttf differ diff --git a/final/doc/fonts/SourceCodePro-Regular.ttf b/final/doc/fonts/SourceCodePro-Regular.ttf new file mode 100644 index 0000000..85686d9 Binary files /dev/null and b/final/doc/fonts/SourceCodePro-Regular.ttf differ diff --git a/final/doc/images/add.png b/final/doc/images/add.png new file mode 100644 index 0000000..6332fef Binary files /dev/null and b/final/doc/images/add.png differ diff --git a/final/doc/images/arrow_up.png b/final/doc/images/arrow_up.png new file mode 100644 index 0000000..1ebb193 Binary files /dev/null and b/final/doc/images/arrow_up.png differ diff --git a/final/doc/images/brick.png b/final/doc/images/brick.png new file mode 100644 index 0000000..7851cf3 Binary files /dev/null and b/final/doc/images/brick.png differ diff --git a/final/doc/images/brick_link.png b/final/doc/images/brick_link.png new file mode 100644 index 0000000..9ebf013 Binary files /dev/null and b/final/doc/images/brick_link.png differ diff --git a/final/doc/images/bug.png b/final/doc/images/bug.png new file mode 100644 index 0000000..2d5fb90 Binary files /dev/null and b/final/doc/images/bug.png differ diff --git a/final/doc/images/bullet_black.png b/final/doc/images/bullet_black.png new file mode 100644 index 0000000..5761970 Binary files /dev/null and b/final/doc/images/bullet_black.png differ diff --git a/final/doc/images/bullet_toggle_minus.png b/final/doc/images/bullet_toggle_minus.png new file mode 100644 index 0000000..b47ce55 Binary files /dev/null and b/final/doc/images/bullet_toggle_minus.png differ diff --git a/final/doc/images/bullet_toggle_plus.png b/final/doc/images/bullet_toggle_plus.png new file mode 100644 index 0000000..9ab4a89 Binary files /dev/null and b/final/doc/images/bullet_toggle_plus.png differ diff --git a/final/doc/images/date.png b/final/doc/images/date.png new file mode 100644 index 0000000..783c833 Binary files /dev/null and b/final/doc/images/date.png differ diff --git a/final/doc/images/delete.png b/final/doc/images/delete.png new file mode 100644 index 0000000..08f2493 Binary files /dev/null and b/final/doc/images/delete.png differ diff --git a/final/doc/images/find.png b/final/doc/images/find.png new file mode 100644 index 0000000..1547479 Binary files /dev/null and b/final/doc/images/find.png differ diff --git a/final/doc/images/loadingAnimation.gif b/final/doc/images/loadingAnimation.gif new file mode 100644 index 0000000..82290f4 Binary files /dev/null and b/final/doc/images/loadingAnimation.gif differ diff --git a/final/doc/images/macFFBgHack.png b/final/doc/images/macFFBgHack.png new file mode 100644 index 0000000..c6473b3 Binary files /dev/null and b/final/doc/images/macFFBgHack.png differ diff --git a/final/doc/images/package.png b/final/doc/images/package.png new file mode 100644 index 0000000..da3c2a2 Binary files /dev/null and b/final/doc/images/package.png differ diff --git a/final/doc/images/page_green.png b/final/doc/images/page_green.png new file mode 100644 index 0000000..de8e003 Binary files /dev/null and b/final/doc/images/page_green.png differ diff --git a/final/doc/images/page_white_text.png b/final/doc/images/page_white_text.png new file mode 100644 index 0000000..813f712 Binary files /dev/null and b/final/doc/images/page_white_text.png differ diff --git a/final/doc/images/page_white_width.png b/final/doc/images/page_white_width.png new file mode 100644 index 0000000..1eb8809 Binary files /dev/null and b/final/doc/images/page_white_width.png differ diff --git a/final/doc/images/plugin.png b/final/doc/images/plugin.png new file mode 100644 index 0000000..6187b15 Binary files /dev/null and b/final/doc/images/plugin.png differ diff --git a/final/doc/images/ruby.png b/final/doc/images/ruby.png new file mode 100644 index 0000000..f763a16 Binary files /dev/null and b/final/doc/images/ruby.png differ diff --git a/final/doc/images/tag_blue.png b/final/doc/images/tag_blue.png new file mode 100644 index 0000000..3f02b5f Binary files /dev/null and b/final/doc/images/tag_blue.png differ diff --git a/final/doc/images/tag_green.png b/final/doc/images/tag_green.png new file mode 100644 index 0000000..83ec984 Binary files /dev/null and b/final/doc/images/tag_green.png differ diff --git a/final/doc/images/transparent.png b/final/doc/images/transparent.png new file mode 100644 index 0000000..d665e17 Binary files /dev/null and b/final/doc/images/transparent.png differ diff --git a/final/doc/images/wrench.png b/final/doc/images/wrench.png new file mode 100644 index 0000000..5c8213f Binary files /dev/null and b/final/doc/images/wrench.png differ diff --git a/final/doc/images/wrench_orange.png b/final/doc/images/wrench_orange.png new file mode 100644 index 0000000..565a933 Binary files /dev/null and b/final/doc/images/wrench_orange.png differ diff --git a/final/doc/images/zoom.png b/final/doc/images/zoom.png new file mode 100644 index 0000000..908612e Binary files /dev/null and b/final/doc/images/zoom.png differ diff --git a/final/doc/index.html b/final/doc/index.html new file mode 100644 index 0000000..70b6d02 --- /dev/null +++ b/final/doc/index.html @@ -0,0 +1,83 @@ + + + + + + +RDoc Documentation + + + + + + + + + + + + + + + + + +
+

This is the API documentation for RDoc Documentation. +

+ + + + + diff --git a/final/doc/js/darkfish.js b/final/doc/js/darkfish.js new file mode 100644 index 0000000..06fef3b --- /dev/null +++ b/final/doc/js/darkfish.js @@ -0,0 +1,140 @@ +/** + * + * Darkfish Page Functions + * $Id: darkfish.js 53 2009-01-07 02:52:03Z deveiant $ + * + * Author: Michael Granger + * + */ + +/* Provide console simulation for firebug-less environments */ +if (!("console" in window) || !("firebug" in console)) { + var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", + "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"]; + + window.console = {}; + for (var i = 0; i < names.length; ++i) + window.console[names[i]] = function() {}; +}; + + +/** + * Unwrap the first element that matches the given @expr@ from the targets and return them. + */ +$.fn.unwrap = function( expr ) { + return this.each( function() { + $(this).parents( expr ).eq( 0 ).after( this ).remove(); + }); +}; + + +function showSource( e ) { + var target = e.target; + var codeSections = $(target). + parents('.method-detail'). + find('.method-source-code'); + + $(target). + parents('.method-detail'). + find('.method-source-code'). + slideToggle(); +}; + +function hookSourceViews() { + $('.method-heading').click( showSource ); +}; + +function toggleDebuggingSection() { + $('.debugging-section').slideToggle(); +}; + +function hookDebuggingToggle() { + $('#debugging-toggle img').click( toggleDebuggingSection ); +}; + +function hookSearch() { + var input = $('#search-field').eq(0); + var result = $('#search-results').eq(0); + $(result).show(); + + var search_section = $('#search-section').get(0); + $(search_section).show(); + + var search = new Search(search_data, input, result); + + search.renderItem = function(result) { + var li = document.createElement('li'); + var html = ''; + + // TODO add relative path to + + + + + + + + + + +
+

Table of Contents - RDoc Documentation

+ + +

Classes and Modules

+ + +

Methods

+ +
+ + + + diff --git a/final/lib/radian_degree_converter.rb b/final/lib/radian_degree_converter.rb new file mode 100644 index 0000000..efbd6ee --- /dev/null +++ b/final/lib/radian_degree_converter.rb @@ -0,0 +1,48 @@ +# This class converts radians to decimal degrees and decimal degrees to radians. +# It will validate the method input to make sure it is float compatible and return +# an error message if the input cannot be converted to a float. +# +# Author :: Kevin LaFave +# License :: MIT +class RadianDegreeConverter + + # This method validates the input to see if it is float compatible. + # * input : The value that needs to be validated. + def is_numeric? input + begin + Float(input) + rescue + false + else + true + end + end + + # This method returns an error message when the convert method input was not float compatible. + def error_message + puts "Invalid input. Must enter an integer or decimal number" + end + + # This method converts radians to its decimal degrees equivalent. + # * input : The radian value that needs to be converted to decimal degrees. + def convert_radians_to_degrees input + if is_numeric? input + @result = input.to_f * 57.2957795 + else + error_message + @result = nil + end + end + + # This method converts decimal degrees to its radians equivalent. + # * input : The decimal degree value that needs to be converted to radians. + def convert_degrees_to_radians input + if is_numeric? input + @result = input.to_f * 0.0174532925 + else + error_message + @result = nil + end + end + +end diff --git a/final/radian_degree_converter-0.1.0.gem b/final/radian_degree_converter-0.1.0.gem new file mode 100644 index 0000000..9be6cea Binary files /dev/null and b/final/radian_degree_converter-0.1.0.gem differ diff --git a/final/radian_degree_converter-0.2.0.gem b/final/radian_degree_converter-0.2.0.gem new file mode 100644 index 0000000..64ddab4 Binary files /dev/null and b/final/radian_degree_converter-0.2.0.gem differ diff --git a/final/radian_degree_converter-0.2.1.gem b/final/radian_degree_converter-0.2.1.gem new file mode 100644 index 0000000..e8df43c Binary files /dev/null and b/final/radian_degree_converter-0.2.1.gem differ diff --git a/final/radian_degree_converter-0.3.0.gem b/final/radian_degree_converter-0.3.0.gem new file mode 100644 index 0000000..f8ddf53 Binary files /dev/null and b/final/radian_degree_converter-0.3.0.gem differ diff --git a/final/radian_degree_converter.gemspec b/final/radian_degree_converter.gemspec new file mode 100644 index 0000000..44ca118 --- /dev/null +++ b/final/radian_degree_converter.gemspec @@ -0,0 +1,13 @@ +Gem::Specification.new do |s| +s.name = 'radian_degree_converter' +s.version = '0.3.0' +s.date = '2014-03-08' +s.summary = 'Radian Degree Converter' +s.description = 'A gem to convert radians to decimal degrees' +s.authors = ['Kevin LaFave'] +s.email = 'kjlafave@gmail.com' +s.homepage = 'http://rubygems.org/gems/radian_degree_converter' +s.files = ['lib/radian_degree_converter.rb'] +s.license = 'MIT' +s.executables << 'radian_degree_converter' +end \ No newline at end of file diff --git a/final/spec/radian_degree_converter_spec.rb b/final/spec/radian_degree_converter_spec.rb new file mode 100644 index 0000000..796965b --- /dev/null +++ b/final/spec/radian_degree_converter_spec.rb @@ -0,0 +1,17 @@ +require 'spec_helper.rb' + +describe RadianDegreeConverter do + + before do + @converter = RadianDegreeConverter.new + end + + it "should convert radians to decimal degrees" do + @converter.convert_radians_to_degrees(1.0).should == 57.2957795 + end + + it "should convert decimal degrees to radians" do + @converter.convert_degrees_to_radians(1.0).should == 0.0174532925 + end + +end \ No newline at end of file diff --git a/final/spec/spec_helper.rb b/final/spec/spec_helper.rb new file mode 100644 index 0000000..52cb714 --- /dev/null +++ b/final/spec/spec_helper.rb @@ -0,0 +1,3 @@ +$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) + +require 'radian_degree_converter.rb' \ No newline at end of file diff --git a/week1/exercises/roster.txt b/week1/exercises/roster.txt index 21b0964..34d77eb 100644 --- a/week1/exercises/roster.txt +++ b/week1/exercises/roster.txt @@ -9,7 +9,7 @@ 7, emory christenson, neverless@gmail.com, @lightener, seattlecidal, lightener 8, jack,jack.howl@gmail.com,jackhowl,,jackhowl 9, John Wade, JohnRobertWade@gmail.com, THEJRRR, @THEJRRR, John Wade -10, Kevin LaFave, kjlafave@gmail.com, kjlafave, none, @Kevin +10, Kevin LaFave, kjlafave@gmail.com, kjlafave, none, @Kevin 11, 12, 13, Matt Spah, spahmatthew@gmail.com, MattsFace, @MatthewsFace, Matthew Spah diff --git a/week1/homework/questions.txt b/week1/homework/questions.txt index 2257bb9..acf3cdb 100644 --- a/week1/homework/questions.txt +++ b/week1/homework/questions.txt @@ -3,13 +3,19 @@ Chapter 3 Classes, Objects, and Variables p.86-90 Strings (Strings section in Chapter 6 Standard Types) 1. What is an object? +An instance of a class. 2. What is a variable? +A name assigned to a state or value of an item in an object. 3. What is the difference between an object and a class? +A class contains the variables and methods used by the object, but does not do anything until it is instantiated. At this time, it becomes an object and can change the state or value of its variables. 4. What is a String? +Sequences of characters, normally contained between single or double quotes or some other delimiter. 5. What are three messages that I can send to a string object? Hint: think methods +Three that were used in chapter 6 are chomp, split and squeeze. 6. What are two ways of defining a String literal? Bonus: What is the difference between them? +By surrounding a sequence of characters with single or double quotes. The double quotes support more escape sequences. diff --git a/week1/homework/strings_and_rspec_spec.rb b/week1/homework/strings_and_rspec_spec.rb index ea79e4c..85d2691 100644 --- a/week1/homework/strings_and_rspec_spec.rb +++ b/week1/homework/strings_and_rspec_spec.rb @@ -12,14 +12,17 @@ before(:all) do @my_string = "Renée is a fun teacher. Ruby is a really cool programming language" end - it "should be able to count the charaters" - it "should be able to split on the . charater" do - pending - result = #do something with @my_string here - result.should have(2).items + + it "should be able to count the characters" do + "ruby".should have(4).characters + end + + it "should be able to split on the . character" do + result = @my_string.split('.') end + it "should be able to give the encoding of the string" do - pending 'helpful hint: should eq (Encoding.find("UTF-8"))' + "Renée".encoding.should eq Encoding.find("UTF-8") end end end diff --git a/week2/homework/questions.txt b/week2/homework/questions.txt index 939e42d..56bcca8 100644 --- a/week2/homework/questions.txt +++ b/week2/homework/questions.txt @@ -3,11 +3,16 @@ Containers, Blocks, and Iterators Sharing Functionality: Inheritance, Modules, and Mixins 1. What is the difference between a Hash and an Array? +Both are a collection of object references. Arrays are accessed using an integer index. Hashes are accessed using an unique key, which can be of any type. Hashes also have key|value pairs. 2. When would you use an Array over a Hash and vice versa? +Arrays should be used when access with an integer index is sufficient. Otherwise, hashes should be used. 3. What is a module? Enumerable is a built in Ruby module, what is it? +Modules are containers of methods, classes and/or constants. They can be included in classes. Enumerable is a mixin that provides sorting of a collection in classes that contain an 'each' method. 4. Can you inherit more than one thing in Ruby? How could you get around this problem? +No. By using mixins. 5. What is the difference between a Module and a Class? +A module cannot be instantiated, does not support inheritance (but has mixins), and can be included in classes. A class can be instantiated, supports limited inheritiance and cannot be included in other classes. \ No newline at end of file diff --git a/week2/homework/simon_says.rb b/week2/homework/simon_says.rb new file mode 100644 index 0000000..d94dded --- /dev/null +++ b/week2/homework/simon_says.rb @@ -0,0 +1,42 @@ +module SimonSays + def echo(string) + #return string as is + return string + end + + def shout(string) + #return string in all uppercase + return string.upcase + end + + def repeat(*args) + #return string number of times indicated by count + string = nil + count = 0 + if args.length > 1 + string = args[0] + count = args[1] + else + string = args[0] + count = 2 + end + return ((string + " ") * count).strip + end + + def start_of_word(string, count) + #return number of letters indicated by count from start of word + tmp = string.split(/\s*/) + char = 0 + letters = "" + while char < count + letters += tmp[char] + char += 1 + end + return letters + end + + def first_word(string) + #return the first word of the string + return string.split[0] + end +end \ No newline at end of file diff --git a/week3/homework/calculator.rb b/week3/homework/calculator.rb new file mode 100644 index 0000000..8cbd825 --- /dev/null +++ b/week3/homework/calculator.rb @@ -0,0 +1,39 @@ +class Calculator + def sum input + if input.empty? + #input array is empty + result = 0 + else + #input array is not empty + result = input.inject(:+) + end + result + end + + def multiply input, n = 1 + if Array.try_convert(input) == nil + #input is not an array + result = input * n + else + #input is an array + result = input.inject(:*) + end + result + end + + def pow input, n = 1 + #raise input to the n power + result = input ** n + end + + def fac input + if input < 2 + #factorial of 0 and 1 is 1 + result = 1 + else + #multiply all positive integers from input down to 1 + result = input.downto(1).inject(:*) + end + result + end +end \ No newline at end of file diff --git a/week3/homework/questions.txt b/week3/homework/questions.txt index dfb158d..1738179 100644 --- a/week3/homework/questions.txt +++ b/week3/homework/questions.txt @@ -5,11 +5,22 @@ Please Read: - Chapter 22 The Ruby Language: basic types (symbols), variables and constants 1. What is a symbol? +An identifier corresponding to a string of characters. 2. What is the difference between a symbol and a string? +Symbols are immutable. Strings are mutable. 3. What is a block and how do I call a block? +A chunk of code enclosed between eith braces or the keywords 'do' and 'end'. A block is called by a method. 4. How do I pass a block to a method? What is the method signature? +By preceding the last argument in a method signature with an ampersand. +def speak(&block) + puts block.call +end +speak {"Hello"} 5. Where would you use regular expressions? +Where you want to test a string to see if it matches a pattern. +Where you want to extract a portion of a string when it matches a pattern. +Where you want to replace a portion of a string when mtaches a pattern. diff --git a/week4/homework/questions.txt b/week4/homework/questions.txt index 187b3d3..a60352c 100644 --- a/week4/homework/questions.txt +++ b/week4/homework/questions.txt @@ -3,12 +3,19 @@ Chapter 10 Basic Input and Output The Rake Gem: http://rake.rubyforge.org/ 1. How does Ruby read files? +By calling the 'gets' method from the File class or by using various iterators from the IO class. 2. How would you output "Hello World!" to a file called my_output.txt? +File.open("my_output.txt", "w") do |file| + file.puts "Hello World!" +end 3. What is the Directory class and what is it used for? +Objects of the Directory class represent directories in the file system. They provide a variety of ways to list directories and their contents. 4. What is an IO object? +A bidirectional channel between a Ruby program and some external resource. 5. What is rake and what is it used for? What is a rake task? +Rake is a version of Make written in Ruby that is used to build software. A rake task consists of a name, a list of prerequisites and a list of actions that should be performed. diff --git a/week4/homework/worker.rb b/week4/homework/worker.rb new file mode 100644 index 0000000..1fdf18e --- /dev/null +++ b/week4/homework/worker.rb @@ -0,0 +1,5 @@ +class Worker + def self.work(n=1) + (0..n).reduce { yield } + end +end \ No newline at end of file diff --git a/week6/homework/.rspec b/week6/homework/.rspec new file mode 100644 index 0000000..b3eb8b4 --- /dev/null +++ b/week6/homework/.rspec @@ -0,0 +1,2 @@ +--color +--format documentation \ No newline at end of file diff --git a/week6/homework/Rakefile.rb b/week6/homework/Rakefile.rb new file mode 100644 index 0000000..8e2175c --- /dev/null +++ b/week6/homework/Rakefile.rb @@ -0,0 +1,5 @@ +require 'rspec/core/rake_task' + +RSpec::Core::RakeTask.new('spec') + +task :default => :spec \ No newline at end of file diff --git a/week6/homework/bin/kjl_test_gem b/week6/homework/bin/kjl_test_gem new file mode 100755 index 0000000..d451d83 --- /dev/null +++ b/week6/homework/bin/kjl_test_gem @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby + +require 'kjl_test_gem' \ No newline at end of file diff --git a/week6/homework/kjl_test_gem-0.1.0.gem b/week6/homework/kjl_test_gem-0.1.0.gem new file mode 100644 index 0000000..a253a9a Binary files /dev/null and b/week6/homework/kjl_test_gem-0.1.0.gem differ diff --git a/week6/homework/kjl_test_gem-0.2.0.gem b/week6/homework/kjl_test_gem-0.2.0.gem new file mode 100644 index 0000000..cfe173f Binary files /dev/null and b/week6/homework/kjl_test_gem-0.2.0.gem differ diff --git a/week6/homework/kjl_test_gem.gemspec b/week6/homework/kjl_test_gem.gemspec new file mode 100644 index 0000000..da7f231 --- /dev/null +++ b/week6/homework/kjl_test_gem.gemspec @@ -0,0 +1,12 @@ +Gem::Specification.new do |s| +s.name = 'kjl_test_gem' +s.version = '0.2.0' +s.date = '2014-02-18' +s.summary = 'Test Gem Practice' +s.description = 'A gem to practice releasing a gem to RubyGems.org' +s.authors = ['Kevin LaFave'] +s.email = 'kjlafave@gmail.com' +s.homepage = 'http://rubygems.org/gems/kjl_test_gem' +s.files = ['lib/kjl_test_gem.rb'] +s.executables << 'kjl_test_gem' +end \ No newline at end of file diff --git a/week6/homework/lib/kjl_test_gem.rb b/week6/homework/lib/kjl_test_gem.rb new file mode 100644 index 0000000..73ed7fb --- /dev/null +++ b/week6/homework/lib/kjl_test_gem.rb @@ -0,0 +1,8 @@ +class KjlTestGem + + def success + "My test gem is successful!" + end + +end + diff --git a/week6/homework/spec/kjl_test_gem_spec.rb b/week6/homework/spec/kjl_test_gem_spec.rb new file mode 100644 index 0000000..4b34b0c --- /dev/null +++ b/week6/homework/spec/kjl_test_gem_spec.rb @@ -0,0 +1,9 @@ +require 'spec_helper.rb' + +describe KjlTestGem do + + it 'should indicate success' do + KjlTestGem.new().success.should eq "My test gem is successful!" + end + +end \ No newline at end of file diff --git a/week6/homework/spec/spec_helper.rb b/week6/homework/spec/spec_helper.rb new file mode 100644 index 0000000..faf74d2 --- /dev/null +++ b/week6/homework/spec/spec_helper.rb @@ -0,0 +1,3 @@ +$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) + +require 'kjl_test_gem.rb' \ No newline at end of file diff --git a/week7/exercises/features/step_definitions/converter.rb b/week7/exercises/features/step_definitions/converter.rb new file mode 100644 index 0000000..f64f7cc --- /dev/null +++ b/week7/exercises/features/step_definitions/converter.rb @@ -0,0 +1,19 @@ +class Converter + + attr_accessor :type + + def initialize value + @value = value.to_f + end + + def convert + send "#{type}_converter" + end + + private + def Fahrenheit_converter + ((@value - 32.0) * (5.0/9.0)).round(1) + end + + +end \ No newline at end of file diff --git a/week7/exercises/features/step_definitions/converter_steps.rb b/week7/exercises/features/step_definitions/converter_steps.rb new file mode 100644 index 0000000..63995fe --- /dev/null +++ b/week7/exercises/features/step_definitions/converter_steps.rb @@ -0,0 +1,15 @@ +Given(/^I have entered (\d+) into the converter$/) do |arg1| + @converter = Converter.new(arg1) +end + +Given(/^I set the type to "(.*?)"$/) do |type| + @converter.type = type +end + +When(/^I press convert$/) do + @result = @converter.convert +end + +Then(/^the result returned should be (\d+)\.(\d+)$/) do |arg1, arg2| + @result.should eq "#{arg1}.#{arg2}".to_f +end diff --git a/week7/homework/features/step_definitions/pirate_translator.rb b/week7/homework/features/step_definitions/pirate_translator.rb new file mode 100644 index 0000000..fc73164 --- /dev/null +++ b/week7/homework/features/step_definitions/pirate_translator.rb @@ -0,0 +1,15 @@ +class PirateTranslator + + attr_accessor :translator + + def say message + @translator = message + end + + def translate + if @translator = "Hello Friend" + "Ahoy Matey\n Shiber Me Timbers You Scurvey Dogs!!" + end + end + +end \ No newline at end of file diff --git a/week7/homework/features/step_definitions/tic-tac-toe.rb b/week7/homework/features/step_definitions/tic-tac-toe.rb new file mode 100644 index 0000000..2e802df --- /dev/null +++ b/week7/homework/features/step_definitions/tic-tac-toe.rb @@ -0,0 +1,68 @@ +class TicTacToe + + attr_accessor :player, :computer, :player_symbol, :computer_symbol + attr_accessor :current_player, :board, :open_spots, :computer_move + + SYMBOLS = [:X, :O] + + + def initialize player="", symbol="" + #@player = player + if player == :computer + @player = "Computer" + @current_player = "Computer" + else + @player = player + @current_player = player + end + if symbol == :X + @player_symbol = SYMBOLS[0] + @computer_symbol = SYMBOLS[1] + else + @player_symbol = SYMBOLS[1] + @computer_symbol = SYMBOLS[0] + end + @open_spots = [:A1, :A2, :A3, :B1, :B2, :B3, :C1, :C2, :C3] + end + + def welcome_player + "Welcome #{player}" + end + + def current_player + @player + end + + def indicate_palyer_turn + "#{player}'s Move:" + end + + def get_player_move + end + + def determine_winner + end + + def spots_open? + end + + def draw? + true + end + + def over? + true + end + + def computer_move + @open_spots[0] + end + + def include? + true + end + + def current_state + end + +end \ No newline at end of file diff --git a/week7/homework/questions.txt b/week7/homework/questions.txt index d55387d..ff2dd77 100644 --- a/week7/homework/questions.txt +++ b/week7/homework/questions.txt @@ -3,7 +3,16 @@ Please Read Chapters 23 and 24 DuckTyping and MetaProgramming Questions: 1. What is method_missing and how can it be used? +Method_missing is a built-in method that raises a NoMethodError or NameError exception. It can be used to intercept the every use of an undefined method and handle it. It can also be used to intercept all calls, but only handle some of them. + 2. What is and Eigenclass and what is it used for? Where Do Singleton methods live? +An eigenclass is a singleton class used to define singleton methods on a specific object. The singleton methods live in the singleton class. + 3. When would you use DuckTypeing? How would you use it to improve your code? +You would use duck typing when you want to determine an object's type by what it can do and not by its class. You would use it to reduce garbage collection and improve performance. + 4. What is the difference between a class method and an instance method? What is the difference between instance_eval and class_eval? +Class methods are called on a class and instance methods are called on an instance of a class. The instance_eval works inside the singleton class of self, resulting in class methods. The class_eval works inside the body of the class definition, resulting in instance methods. + 5. What is the difference between a singleton class and a singleton method? +A singleton class is an anonymous class for an object. A singleton method is a method that is specific to a particular object.