From 96ed067fbd0c9629f072db93356ec3a76d006239 Mon Sep 17 00:00:00 2001 From: Anthony Phillips Date: Thu, 8 Aug 2024 14:46:12 -0400 Subject: [PATCH 1/3] Create Ship and Pirate Classes --- Gemfile.lock | 112 +++++++++++++++++++++++-------------------- app.rb | 5 +- app/models/pirate.rb | 16 ++++++- app/models/ship.rb | 20 +++++++- spec/spec_helper.rb | 4 +- 5 files changed, 100 insertions(+), 57 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 6a38748..fc57472 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,36 +1,44 @@ GEM remote: https://rubygems.org/ specs: - addressable (2.5.2) - public_suffix (>= 2.0.2, < 4.0) - backports (3.11.0) + addressable (2.8.7) + public_suffix (>= 2.0.2, < 7.0) + base64 (0.2.0) bond (0.5.1) - capybara (2.17.0) + capybara (3.39.2) addressable + matrix mini_mime (>= 0.1.3) - nokogiri (>= 1.3.3) - rack (>= 1.0.0) - rack-test (>= 0.5.4) - xpath (>= 2.0, < 4.0) - coderay (1.1.2) - diff-lcs (1.3) - method_source (0.9.0) - mini_mime (1.0.0) - mini_portile2 (2.3.0) - multi_json (1.13.0) - mustermann (1.0.1) - nokogiri (1.8.1) - mini_portile2 (~> 2.3.0) - pry (0.11.3) - coderay (~> 1.1.0) - method_source (~> 0.9.0) - public_suffix (3.0.1) - rack (2.0.3) - rack-protection (2.0.0) - rack - rack-test (0.8.2) - rack (>= 1.0, < 3) - require_all (1.5.0) + nokogiri (~> 1.8) + rack (>= 1.6.0) + rack-test (>= 0.6.3) + regexp_parser (>= 1.5, < 3.0) + xpath (~> 3.2) + coderay (1.1.3) + diff-lcs (1.5.1) + matrix (0.4.2) + method_source (1.1.0) + mini_mime (1.1.5) + mini_portile2 (2.8.7) + multi_json (1.15.0) + mustermann (3.0.1) + ruby2_keywords (~> 0.0.1) + nokogiri (1.15.6) + mini_portile2 (~> 2.8.2) + racc (~> 1.4) + pry (0.14.2) + coderay (~> 1.1) + method_source (~> 1.0) + public_suffix (5.1.1) + racc (1.8.1) + rack (2.2.9) + rack-protection (3.2.0) + base64 (>= 0.1.0) + rack (~> 2.2, >= 2.2.4) + rack-test (2.1.0) + rack (>= 1.3) + regexp_parser (2.9.2) + require_all (3.0.0) ripl (0.7.1) bond (~> 0.5.1) ripl-multi_line (0.3.1) @@ -39,42 +47,42 @@ GEM rack (>= 1.0) rack-test (>= 0.5) ripl (>= 0.3.5) - rspec (3.7.0) - rspec-core (~> 3.7.0) - rspec-expectations (~> 3.7.0) - rspec-mocks (~> 3.7.0) - rspec-core (3.7.1) - rspec-support (~> 3.7.0) - rspec-expectations (3.7.0) + rspec (3.13.0) + rspec-core (~> 3.13.0) + rspec-expectations (~> 3.13.0) + rspec-mocks (~> 3.13.0) + rspec-core (3.13.0) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.1) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.7.0) - rspec-mocks (3.7.0) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.1) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.7.0) - rspec-support (3.7.0) + rspec-support (~> 3.13.0) + rspec-support (3.13.1) + ruby2_keywords (0.0.5) shotgun (0.9.2) rack (>= 1.0) - sinatra (2.0.0) - mustermann (~> 1.0) - rack (~> 2.0) - rack-protection (= 2.0.0) + sinatra (3.2.0) + mustermann (~> 3.0) + rack (~> 2.2, >= 2.2.4) + rack-protection (= 3.2.0) + tilt (~> 2.0) + sinatra-contrib (3.2.0) + multi_json (>= 0.0.2) + mustermann (~> 3.0) + rack-protection (= 3.2.0) + sinatra (= 3.2.0) tilt (~> 2.0) - sinatra-contrib (2.0.0) - backports (>= 2.0) - multi_json - mustermann (~> 1.0) - rack-protection (= 2.0.0) - sinatra (= 2.0.0) - tilt (>= 1.3, < 3) sinatra-reloader (1.0) sinatra-contrib - tilt (2.0.8) + tilt (2.4.0) tux (0.3.0) ripl (>= 0.3.5) ripl-multi_line (>= 0.2.4) ripl-rack (>= 0.2.0) sinatra (>= 1.2.1) - xpath (3.0.0) + xpath (3.2.0) nokogiri (~> 1.8) PLATFORMS @@ -92,4 +100,4 @@ DEPENDENCIES tux BUNDLED WITH - 1.16.0 + 2.1.4 diff --git a/app.rb b/app.rb index 585554a..5232688 100644 --- a/app.rb +++ b/app.rb @@ -3,7 +3,10 @@ module FormsLab class App < Sinatra::Base - # code other routes/actions here + get '/' do + erb :root + end + end end diff --git a/app/models/pirate.rb b/app/models/pirate.rb index 80a578b..8f38be3 100644 --- a/app/models/pirate.rb +++ b/app/models/pirate.rb @@ -1,2 +1,16 @@ class Pirate -end \ No newline at end of file + attr_accessor :name, :weight, :height + + @@prirates = [] + + def initialize(name, weight, height) + @name = name + @weight = weight + @height = height + @@prirates << self + end + + def self.all + @@prirates + end +end diff --git a/app/models/ship.rb b/app/models/ship.rb index 09d35d6..a2d0a57 100644 --- a/app/models/ship.rb +++ b/app/models/ship.rb @@ -1,2 +1,20 @@ class Ship -end \ No newline at end of file + attr_accessor :name, :type, :booty + + @@ships = [] + + def initialize(name, type, booty) + @name = name + @type = type + @booty = booty + @@ships << self + end + + def self.all + @@ships + end + + def self.clear + @@ships.clear + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 28c210f..c947c07 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -6,11 +6,11 @@ RSpec.configure do |config| config.include Capybara::DSL config.include Rack::Test::Methods - config.order = 'default' + # config.order = 'default' end def app Rack::Builder.parse_file('config.ru').first end -Capybara.app = app \ No newline at end of file +Capybara.app = app From 296c2a38b294cdb55dd1fc36b3a1a699a73f0b5b Mon Sep 17 00:00:00 2001 From: Anthony Phillips Date: Thu, 8 Aug 2024 15:08:53 -0400 Subject: [PATCH 2/3] Show Form --- app.rb | 3 +++ views/pirates/new.erb | 25 ++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/app.rb b/app.rb index 5232688..8149a81 100644 --- a/app.rb +++ b/app.rb @@ -7,6 +7,9 @@ class App < Sinatra::Base erb :root end + get '/new' do + erb :'pirates/new' + end end end diff --git a/views/pirates/new.erb b/views/pirates/new.erb index f407a19..aa5f202 100644 --- a/views/pirates/new.erb +++ b/views/pirates/new.erb @@ -1 +1,24 @@ -

Make your form here

+
+

Pirate

+ + + + + + +

Ship 1

+ + + + + + +

Ship 2

+ + + + + + + +
From 2c8c4a3bcc4663b23f70def9db1c373c52ba03a0 Mon Sep 17 00:00:00 2001 From: Anthony Phillips Date: Thu, 8 Aug 2024 16:04:11 -0400 Subject: [PATCH 3/3] Display show page --- app.rb | 12 ++++++++++++ app/models/ship.rb | 8 ++++---- views/pirates/new.erb | 9 +++++---- views/pirates/show.erb | 13 ++++++++----- 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/app.rb b/app.rb index 8149a81..96e0c6b 100644 --- a/app.rb +++ b/app.rb @@ -11,5 +11,17 @@ class App < Sinatra::Base erb :'pirates/new' end + post '/pirates' do + @pirate = Pirate.new(params[:pirate][:name], params[:pirate][:weight], params[:pirate][:height]) + + params[:pirate][:ships].each do |details| + Ship.new(details) + end + + @ships = Ship.all + + erb :'pirates/show' + end + end end diff --git a/app/models/ship.rb b/app/models/ship.rb index a2d0a57..737dc28 100644 --- a/app/models/ship.rb +++ b/app/models/ship.rb @@ -3,10 +3,10 @@ class Ship @@ships = [] - def initialize(name, type, booty) - @name = name - @type = type - @booty = booty + def initialize(params) + @name = params [:name] + @type = params [:type] + @booty = params [:booty] @@ships << self end diff --git a/views/pirates/new.erb b/views/pirates/new.erb index aa5f202..3ded3b2 100644 --- a/views/pirates/new.erb +++ b/views/pirates/new.erb @@ -9,16 +9,17 @@

Ship 1

- + - +

Ship 2

- + - + + diff --git a/views/pirates/show.erb b/views/pirates/show.erb index f7832d2..171dbde 100644 --- a/views/pirates/show.erb +++ b/views/pirates/show.erb @@ -1,7 +1,10 @@ -

Display your Pirate here

+

Pirates

+

Name: <%=@pirate.name %>

+

Height: <%=@pirate.height %> Weight: <%=@pirate.weight %>

-

Display your first ship here

- - -

Display your second ship here

+

Ships

+<% @ships.each do |ship| %> +

Name: <%=ship.name%>

+

Type: <%=ship.type%> Booty: <%=ship.booty%>

+<%end%>