Skip to content

Instantly share code, notes, and snippets.

View KBeltz's full-sized avatar
🆗
Focusing

Kristin (Kikki) Beltz KBeltz

🆗
Focusing
  • Omaha, NE
View GitHub Profile
@KBeltz
KBeltz / app.rb
Created June 11, 2015 18:34
Resource Program: Yarn
# empower my program with SQLite
require "sqlite3"
# load/create our database for this program
DATABASE = SQLite3::Database.new("stash.db")
DATABASE.results_as_hash = true
DATABASE.execute("CREATE TABLE IF NOT EXISTS yarn (id INTEGER PRIMARY KEY, name TEXT, fiber TEXT, weight TEXT, yards INTEGER, price INTEGER);")
@KBeltz
KBeltz / paragraph_truncator_as.rb
Created June 10, 2015 18:01
Active Support Mini Programs
require "active_support"
require "active_support/core_ext/string/filters.rb"
# Truncates a given +text+ after a given <tt>length</tt> if +text+ is longer than <tt>length</tt>:
#
# Example
#
# 'And they found that many people were sleeping better.'.truncate(25, omission: '... (continued)')
# # => "And they f... (continued)"
puts "<inspirational paragraph prompt here>:"
words = gets.chomp
@KBeltz
KBeltz / rpsls.markdown
Created June 10, 2015 03:52
Rock Paper Scissors Lizard Spock Essay

#Rock Paper Scissors Lizard Spock The assignment was to write a program for a Rock Paper Scissors Lizard Spock game. The game should only accept valid moves, and should provide the option for a computer player.

The Player class exists to store player 1, player 2, and the computer player, as well as to update the player scores at the end of each round. The Game class contains the rules of the game, and also determines the winner of the round and match.

##Player.rb When the Player class is initialized, it accepts one string argument. Four attributes are created: @name is a string, @players_move is a string, @score is an integer with an initial value of zero, and @valid_moves is an array of symbols representing the valid moves in the game.

  def initialize(name)
 @name = name
@KBeltz
KBeltz / app.rb
Last active August 29, 2015 14:22
Word Connector
require_relative "word_connector.rb"
# gets user input in the form of a string
puts "Please list your favorite color or colors, without using commas:"
favorite_colors = gets.chomp
# allows only valid input
while favorite_colors.include?(",")
puts "Invalid. Please try again without using commas:"
favorite_colors = gets.chomp
@KBeltz
KBeltz / app.rb
Last active August 29, 2015 14:22
Paragraph Truncator
require_relative "paragraph_truncator.rb"
puts "<inspirational paragraph prompt here>:"
words = gets.chomp
puts "How many characters should be in that lovely paragraph of yours?"
number = gets.to_i
puts "What would you like to see at the end of your truncated paragraph?"
puts "(Ex: Read More, See More, ..., etc.)"
@KBeltz
KBeltz / checksplitter.rb
Created June 9, 2015 19:41
CheckSplitter Test
# Build a CheckSplitter class.
class CheckSplitter
# total_cost_of_meal - float, cost of meal without tip
# tip_percentage - float, tip percentage or decimal
# num_people - integer, number of guests
def initialize(total_cost_of_meal, tip_percentage, num_people)
@total_cost_of_meal = total_cost_of_meal
@tip_percentage = tip_percentage
@num_people = num_people
end
@KBeltz
KBeltz / app.rb
Last active August 29, 2015 14:22
Phone Number Formatter
require_relative "phone_number_formatter.rb"
# gets input from user
puts "Please enter a phone number: "
phone_number = gets.chomp
# creates a new instance of the PhoneNumberFormatter class
phone_number = PhoneNumberFormatter.new(phone_number)
# output string, phone number with correct format
@KBeltz
KBeltz / app.rb
Last active August 29, 2015 14:22
Rock Paper Scissors Lizard Spock
require_relative "game.rb"
require_relative "player.rb"
# array of symbols representing the valid moves
valid_moves = [:rock, :paper, :scissors, :lizard, :spock]
puts "Rock Paper Scissors Lizard Spock\n#{"=" * 40}"
# takes player 1 input, instantiates a new Player
puts "Please enter the name of player 1: "
player1 = gets.chomp.capitalize
@KBeltz
KBeltz / rps.rb
Last active August 29, 2015 14:22
Rock-Paper-Scissors
# rps = array of possible plays
rps = [:rock, :paper, :scissors]
puts "Player 1, choose your weapon: "
player1 = gets.chomp.downcase.to_sym
# accepts only valid input from player 1
if rps.include?(player1) == false
puts "ERROR! INVALID INPUT!"
else
@KBeltz
KBeltz / dinner_club_essay.markdown
Last active August 29, 2015 14:22
Dinner Club Essay

Dinner Club

Assignment

The assignment was to write a program that collects member names, restaurant names, and meal totals to track outings for a dinner club. The program should also include the ability to track attendance even if one member chose to pay for the entire meal.

The CheckSplitter class exists to calculate the meal total, including the tip, and then split that total evenly among the members who attended the outing. The DinnerClub class keeps track of member names and the outing history, as well as creating a case to allow a single member to pay for the entire meal if desired.

CheckSplitter

When CheckSplitter is initialized it requires three arguments, all of which are integer values: total_cost_of_meal, tip_percentage and num_people. Three corresponding attributes are created as well.