diff --git a/ch5/challenge/9_file_string_regex_capture_groups.rb b/ch5/challenge/9_file_string_regex_capture_groups.rb deleted file mode 100644 index b721f2cb..00000000 --- a/ch5/challenge/9_file_string_regex_capture_groups.rb +++ /dev/null @@ -1,67 +0,0 @@ -# One of the courses I took last semester was Information Delivery on the Internet -# For one of the problems, the instructions required creating an HTML table based on -# a list of different types of trees, their sizes, and their prices -# -# It sounds fairly simple, but there were 14 of these trees, and 4 for -# each one, plus two for each one. That came out to 84 lines of code -# -# And what happens if later I realize I made some mistake and have to go change each one of these? -# I have to sift through all this code to make the same change 14 times in a row. -# I realized that this was a perfect opportunity to write a script to do this for me. -# -# The data comes in the following format: -# "Royal Empress Tree, which ships at 2 to 4 feet, cost: $4.50" -# Where the name is "Royal Empress Tree", the size is "2 to 4 feet", the cost is "$4.50", the id is "RoyalEmpressTree" -# Note that this information was entered by hand by my instructor, occasionally he would forget to put the colon after cost. -# The output format can be seen in the examples below. -# -# (Whitespace formatting should not be important, but the tests will guide you to what they expect.) -# -# YOUR TASK: -# create a method that receives a file name, or a string, or an array of Strings. -# It must pull from this the tree name, the tree size, and the tree price. -# It must generate a unique id which is the name with all its spaces removed -# It must return the html (as a String) that will be placed into the table in the file for the homework assignment -# Except for the things above, the html will be exactly the same for each tree. -# -# EXAMPLES: -# INVOCATION: -# tableize("American Redbud Tree, which ships at 1 to 2 feet, cost $5.95") -# RETURNS (as a string): -# -# American Redbud Tree -# 1 to 2 feet -# $5.95 -# -# -# -# INVOCATION: -# tableize(["Autumn Flowering Cherry, which ships at 2 to 4 feet, cost: $8.95" , -# "Black Walnut Tree, which ships at 1 to 2 feet, cost: $4.95" ]) -# RETURNS: -# -# Autumn Flowering Cherry -# 2 to 4 feet -# $8.95 -# -# -# -# Black Walnut Tree -# 1 to 2 feet -# $4.95 -# -# -# -# INVOCATION: -# (note, file named "tree.txt" contains only the single line "Cherokee Chief Dogwood, which ships at 2 to 4 feet, cost: $8.95") -# tableize("tree.txt") -# RETURNS: -# -# Cherokee Chief Dogwood -# 2 to 4 feet -# $8.95 -# -# - -def tableize -end diff --git a/ch5/solved/9.rb b/ch5/solved/9.rb deleted file mode 100644 index 8afb126f..00000000 --- a/ch5/solved/9.rb +++ /dev/null @@ -1,54 +0,0 @@ -def tableize(str) - if str !~ /^([^,]*), which ships at ([^,]*), cost:? (.*)$/ - puts "FAILED ON #{line}" - end - name , size , price = $1 , $2 , $3 - id = name.to_s.gsub(' ','') - <<-END_OF_ROW.gsub(/^ /,'') - - #{name} - #{size} - #{price} - - - END_OF_ROW -end - - -__END__ -elements = Array.new - -DATA.each do |line| - if line !~ /^([^,]*), which ships at ([^,]*), cost:? (.*)$/ - puts "FAILED ON #{line}" - end - name , size , price = $1 , $2 , $3 - id = name.to_s.gsub(' ','') - elements << [ id , price ] - puts <<-END_OF_ROW.gsub(/^ /,'') - - #{name} - #{size} - #{price} - - - END_OF_ROW -end - -puts -require 'pp' -pp elements - -__END__ -American Redbud Tree, which ships at 1 to 2 feet, cost $5.95 -Autumn Flowering Cherry, which ships at 2 to 4 feet, cost: $8.95 -Black Walnut Tree, which ships at 1 to 2 feet, cost: $4.95 -Cherokee Chief Dogwood, which ships at 2 to 4 feet, cost: $8.95 -English Walnut Tree, which ships at 1 to 2 feet, cost $10.95 -Flowering Peach Tree, which ships at 2 to 4 feet, cost: $7.95 -Flowering Pear Tree, which ships at 2 to 4 feet, cost: $8.50 -Hydrangea Tree, which ships at 1 to 2 feet, cost: $5.95 -Pecan Tree, which ships at 1 to 2 feet, cost: $5.95 -Purple Leaf Plum Tree, which ships at 2 to 3 feet, cost: $5.95 -Royal Empress Tree, which ships at 2 to 4 feet, cost: $4.50 -White Dogwood Tree, which ships at 2 to 3 feet, cost: $5.95 \ No newline at end of file diff --git a/ch5/spec/1.rb b/ch5/spec/1.rb index d032fc94..00803c93 100644 --- a/ch5/spec/1.rb +++ b/ch5/spec/1.rb @@ -4,10 +4,6 @@ @ac = ApplicationController.new end - it 'should not have its own initialize method' do - ApplicationController.new.method(:initialize).owner.should == if RUBY_VERSION =~ /1\.9/ then BasicObject else Object end - end - it 'should return an empty string on first invocation' do ApplicationController.new.body_class.should == "" end diff --git a/ch5/spec/9.rb b/ch5/spec/9.rb deleted file mode 100644 index a09301c4..00000000 --- a/ch5/spec/9.rb +++ /dev/null @@ -1,58 +0,0 @@ -def make_regex(*elements) - elements.flatten! - /^\s*#{elements.join '\s*'}\s*$/ -end - -class String - def should_match_tree( name , smallsize , bigsize , price) - (split("\n").size % 6).should == 0 - split("\n").each_cons 6 do |one,two,three,four,five,six| - one.should =~ make_regex( %w{} ) - two.should =~ make_regex( %w{} , name.split , %w{} ) - three.should =~ make_regex( %w{} , smallsize , 'to' , bigsize , %w{feet } ) - four.should =~ make_regex( %w{ \$} , price , %w{} ) - five.should =~ make_regex( %w{ } ) - six.should =~ make_regex( %w{} ) - end - end -end - -describe 'tableize' do - - it 'one tree should span 6 lines' do - tableize("American Redbud Tree, which ships at 1 to 2 feet, cost $5.95").split("\n").size.should == 6 - end - - it 'should work for a single tree in a string' do - tableize("American Redbud Tree, which ships at 1 to 2 feet, cost $5.95").should_match_tree 'American Redbud Tree' , 1 , 2 , 5.95 - end - -end -# -# INVOCATION: -# tableize(["Autumn Flowering Cherry, which ships at 2 to 4 feet, cost: $8.95" , -# "Black Walnut Tree, which ships at 1 to 2 feet, cost: $4.95" ]) -# RETURNS: -# -# Autumn Flowering Cherry -# 2 to 4 feet -# $8.95 -# -# -# -# Black Walnut Tree -# 1 to 2 feet -# $4.95 -# -# -# -# INVOCATION: -# (note, file named "tree.txt" contains only the single line "Cherokee Chief Dogwood, which ships at 2 to 4 feet, cost: $8.95") -# tableize("tree.txt") -# RETURNS: -# -# Cherokee Chief Dogwood -# 2 to 4 feet -# $8.95 -# -#