Skip to content

Commit

Permalink
add country class methods
Browse files Browse the repository at this point in the history
  • Loading branch information
gotascii committed Jan 17, 2011
1 parent 69e3493 commit 471971f
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 19 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -3,4 +3,5 @@ pkg/
.bundle
coverage
vendor
.bundle
.bundle
.rvmrc
22 changes: 22 additions & 0 deletions Gemfile.lock
@@ -0,0 +1,22 @@
GEM
remote: http://rubygems.org/
specs:
curb (0.7.9)
diff-lcs (1.1.2)
hpricot (0.8.3)
rspec (2.4.0)
rspec-core (~> 2.4.0)
rspec-expectations (~> 2.4.0)
rspec-mocks (~> 2.4.0)
rspec-core (2.4.0)
rspec-expectations (2.4.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.4.0)

PLATFORMS
ruby

DEPENDENCIES
curb
hpricot
rspec
8 changes: 4 additions & 4 deletions README.rdoc
Expand Up @@ -25,10 +25,10 @@ Categories using:

Search a single craigslist location (e.g. sfbay.craigslist.com)
s = Search::Location.new(:keyword => 'shoes')
s.keyword # this will shoes instead of the default
s.location # this will the sfbay Location
s.category # the for sale Category
s.items # will return a set of Items
s.keyword # shoes instead of bicycle
s.location # the sfbay Location
s.category # the 'for sale' Category
s.items # a set of Items that match the search criteria

Each Item has a title, url (which is the link to the item on craigslist), and
a date, which is the date the item was posted on craigslist.
Expand Down
14 changes: 2 additions & 12 deletions Rakefile
Expand Up @@ -15,21 +15,11 @@ rescue LoadError
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
end

require 'spec/rake/spectask'
Spec::Rake::SpecTask.new(:spec) do |spec|
spec.libs << 'lib' << 'spec'
spec.spec_files = FileList['spec/**/*_spec.rb']
end

Spec::Rake::SpecTask.new(:rcov) do |spec|
spec.libs << 'lib' << 'spec'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec) do |spec|
spec.pattern = 'spec/**/*_spec.rb'
spec.rcov = true
spec.rcov_opts = ['--exclude', 'spec,gems,crags.rb']
end

task :spec => :check_dependencies

task :default => :spec

require 'rake/rdoctask'
Expand Down
3 changes: 1 addition & 2 deletions lib/crags.rb
@@ -1,5 +1,4 @@
require 'bundler'
Bundler.require
require 'bundler/setup'
require 'erb'
require 'ostruct'
require 'ext/string'
Expand Down
8 changes: 8 additions & 0 deletions lib/crags/country.rb
Expand Up @@ -3,6 +3,14 @@ class Country
include Fetcher
attr_reader :code

def self.codes
Config.country_codes
end

def self.all
codes.collect {|code| new(code)}
end

def initialize(code)
@code = code
end
Expand Down
13 changes: 13 additions & 0 deletions spec/crags/country_spec.rb
@@ -1,5 +1,18 @@
require 'spec_helper'

describe Country, "the class" do
it "knows all of the codes store in the config" do
Crags::Config.stub(:country_codes) { ["code"] }
Country.codes.should == ["code"]
end

it "finds all countries" do
Country.stub(:codes) { ["code"] }
Country.should_receive(:new).with("code") { "country!" }
Country.all.should == ["country!"]
end
end

describe Country do
before do
@country = Country.new("us")
Expand Down

0 comments on commit 471971f

Please sign in to comment.