Skip to content

Commit

Permalink
Change app from procedural to class and method based
Browse files Browse the repository at this point in the history
  • Loading branch information
scherztc committed Nov 18, 2013
1 parent 784418d commit 96ce067
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--color
--format progress
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ GEM
treetop (~> 1.4.8)
mediashelf-loggable (0.4.9)
mime-types (1.25)
mini_portile (0.5.1)
mini_portile (0.5.2)
minitest (4.7.5)
multi_json (1.8.2)
nokogiri (1.6.0)
Expand Down Expand Up @@ -137,9 +137,9 @@ GEM
turbolinks (1.3.0)
coffee-rails
tzinfo (0.3.38)
uglifier (2.2.1)
uglifier (2.3.1)
execjs (>= 0.3.0)
multi_json (~> 1.0, >= 1.0.2)
json (>= 1.8.0)
xbel (0.2.7)
nokogiri
xml-simple (1.1.2)
Expand Down
24 changes: 24 additions & 0 deletions app/controllers/accessing_files.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
file = File.new('../models/bookmark_url.lst', 'r')
file.close

File.open('../models/bookmark_url.lst', 'r') do |file|
contentsArray = []
while line = file.gets
# puts "** " + line.chomp + " **"
contentsArray.push line
end

#f = File.open('bookmark_url.lst', 'r') do |file|
#File.each_line (|line| puts line)
# contentsArray = []
# f.each_line {|line|
# contentArray.push line
# }

puts contentsArray[rand(contentsArray.length)]

end




27 changes: 27 additions & 0 deletions lib/randomizer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class Randomizer

def initialize(name)
@name = name
end

def generate()
File.open("#{@name}", 'r') do |file|
@contentsArray = []
while line = file.gets
@contentsArray.push line
end
end
end

def display()
puts @contentsArray[rand(@contentsArray.length)]
end
end

url = Randomizer.new("../app/models/bookmark_url.lst")
url.generate
url.display




7 changes: 7 additions & 0 deletions spec/randomizer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require "spec_helper"
require "randomizer"

describe "A Randomizer" do
# Your examples go here
it "is named bookmark"
end
17 changes: 17 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This file was generated by the `rspec --init` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# Require this file using `require "spec_helper"` to ensure that it is only
# loaded once.
#
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
config.run_all_when_everything_filtered = true
config.filter_run :focus

# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = 'random'
end

0 comments on commit 96ce067

Please sign in to comment.