payone_connect 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1699947db054ca9586dc360c38956b741339e9ef
4
+ data.tar.gz: 03990fa223508e7f8aca009811c2084bc97f9214
5
+ SHA512:
6
+ metadata.gz: fe4aff31eac09a35bc0cfd27d19e595c4ba403e5d0bfd6fc7a80bb38c71b0fd9f9bedfcf4a1e63c153bf0bcd9d2c76a784bf1ec184bf8ffa95e2920575ac205f
7
+ data.tar.gz: ae195a103bbcc840323d422539244a1257da9113dcf9062a1f2838c760ba2f9af1bf3596d0065cc50abcdd086e23fd04bc5d7b608e8e2d0d5e520ab3874e4d0a
data/.gitignore CHANGED
@@ -4,3 +4,5 @@
4
4
  coverage
5
5
  rdoc
6
6
  pkg
7
+ .ruby-gemset
8
+ .ruby-version
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ rvm:
2
+ - 1.9.3
3
+ - 2.0.0
4
+ - 2.1.0
5
+ - 2.1.2
6
+ script: bundle exec rake
data/CHANGELOG ADDED
@@ -0,0 +1,7 @@
1
+ = VERSION 0.2.0
2
+
3
+ * Fix URI encoding (Jan Raasch)
4
+ * Fixes error when response contains key without value
5
+ * Add to travis (Alexander Lang)
6
+ * Move to bundler (Alexander Lang)
7
+ * Fixes error when response contains multiple consecutive newlines
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,42 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ payone_connect (0.1.3)
5
+ activesupport
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (4.0.4)
11
+ i18n (~> 0.6, >= 0.6.9)
12
+ minitest (~> 4.2)
13
+ multi_json (~> 1.3)
14
+ thread_safe (~> 0.1)
15
+ tzinfo (~> 0.3.37)
16
+ atomic (1.1.16)
17
+ diff-lcs (1.2.5)
18
+ fakeweb (1.3.0)
19
+ i18n (0.6.9)
20
+ minitest (4.7.5)
21
+ multi_json (1.9.0)
22
+ rake (10.1.1)
23
+ rspec (2.14.1)
24
+ rspec-core (~> 2.14.0)
25
+ rspec-expectations (~> 2.14.0)
26
+ rspec-mocks (~> 2.14.0)
27
+ rspec-core (2.14.7)
28
+ rspec-expectations (2.14.4)
29
+ diff-lcs (>= 1.1.3, < 2.0)
30
+ rspec-mocks (2.14.4)
31
+ thread_safe (0.2.0)
32
+ atomic (>= 1.1.7, < 2)
33
+ tzinfo (0.3.39)
34
+
35
+ PLATFORMS
36
+ ruby
37
+
38
+ DEPENDENCIES
39
+ fakeweb
40
+ payone_connect!
41
+ rake
42
+ rspec (~> 2.1)
data/README.rdoc CHANGED
@@ -3,22 +3,18 @@
3
3
  This is a super simple wrapper around the API for the payment service provider payone (http://www.payone.de)
4
4
 
5
5
  == Installation
6
- === Via github
7
- gem install phuesler-payone_connect
8
- === Via gem cutter (http://www.gemcutter.org)
9
- gem install gemcutter
10
- gem tumble
6
+
11
7
  gem install payone_connect
12
8
 
13
9
  == Usage
14
10
 
15
11
  require 'payone_connect'
16
-
12
+
17
13
  payone = PayoneConnect.new(api_key,params_hash)
18
14
  puts payone.request[:status]
19
15
 
20
16
  == Note on Patches/Pull Requests
21
-
17
+
22
18
  * Fork the project.
23
19
  * Make your feature addition or bug fix.
24
20
  * Add tests for it. This is important so I don't break it in a
data/Rakefile CHANGED
@@ -1,50 +1,6 @@
1
- require 'rubygems'
2
- require 'rake'
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
3
 
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "payone_connect"
8
- gem.summary = %Q{Simple http client for the psp payone api (http://www.payone.de/)}
9
- gem.description = %Q{Connects to the payone gateway and passes the parameters}
10
- gem.email = "patrick.huesler@gmail.com"
11
- gem.homepage = "http://github.com/phuesler/payone_connect"
12
- gem.authors = ["Patrick Huesler"]
13
- gem.add_development_dependency "rspec"
14
- gem.add_development_dependency "fakeweb"
15
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
- end
17
- Jeweler::GemcutterTasks.new
18
- rescue LoadError
19
- puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
20
- end
4
+ RSpec::Core::RakeTask.new(:spec)
21
5
 
22
- require 'spec/rake/spectask'
23
- Spec::Rake::SpecTask.new(:spec) do |spec|
24
- spec.libs << 'lib' << 'spec'
25
- spec.spec_files = FileList['spec/**/*_spec.rb']
26
- end
27
-
28
- Spec::Rake::SpecTask.new(:rcov) do |spec|
29
- spec.libs << 'lib' << 'spec'
30
- spec.pattern = 'spec/**/*_spec.rb'
31
- spec.rcov = true
32
- end
33
-
34
- task :spec => :check_dependencies
35
-
36
- task :default => :spec
37
-
38
- require 'rake/rdoctask'
39
- Rake::RDocTask.new do |rdoc|
40
- if File.exist?('VERSION')
41
- version = File.read('VERSION')
42
- else
43
- version = ""
44
- end
45
-
46
- rdoc.rdoc_dir = 'rdoc'
47
- rdoc.title = "payone_connect #{version}"
48
- rdoc.rdoc_files.include('README*')
49
- rdoc.rdoc_files.include('lib/**/*.rb')
50
- end
6
+ task default: :spec
@@ -0,0 +1,3 @@
1
+ class PayoneConnect
2
+ VERSION = "0.2.0"
3
+ end
@@ -1,7 +1,8 @@
1
1
  require 'net/http'
2
2
  require 'net/https'
3
3
  require 'uri'
4
- require 'payone_connect/core_ext'
4
+ require 'active_support/core_ext/hash/keys'
5
+ require 'active_support/core_ext/object/blank'
5
6
 
6
7
  class PayoneConnect
7
8
  attr_reader :request_data, :request_header
@@ -17,19 +18,19 @@ class PayoneConnect
17
18
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
18
19
  handle_response(http.post(@api_url.path, @request_data,@request_header))
19
20
  end
20
-
21
+
21
22
  protected
22
-
23
+
23
24
  def handle_response(http_response)
24
25
  return nil if http_response.body.blank?
25
26
  response = {}
26
- http_response.body.split("\n").each do |param|
27
- key,value = param.scan(/([^=]+)=(.+)/).first
27
+ http_response.body.split(/\n+/).each do |param|
28
+ key,value = param.scan(/([^=]+)=(.*)/).first
28
29
  response[key.to_sym] = value
29
30
  end
30
31
  response
31
32
  end
32
-
33
+
33
34
  def process_data(data)
34
35
  data.stringify_keys!
35
36
  %w(mid portalid key mode).each do |required_field|
@@ -39,12 +40,12 @@ class PayoneConnect
39
40
  data.each do |key,value|
40
41
  if value.is_a?(Hash)
41
42
  value.each do |nested_key, nested_value|
42
- post_data << "#{key.to_s}[#{nested_key.to_s}]=#{URI.encode(nested_value.to_s)}"
43
+ post_data << "#{key.to_s}[#{nested_key.to_s}]=#{URI.encode_www_form_component(nested_value.to_s)}"
43
44
  end
44
45
  else
45
- post_data << "#{key.to_s}=#{URI.encode(value.to_s)}"
46
+ post_data << "#{key.to_s}=#{URI.encode_www_form_component(value.to_s)}"
46
47
  end
47
48
  end
48
49
  post_data.join("&")
49
50
  end
50
- end
51
+ end
@@ -1,58 +1,23 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
- # -*- encoding: utf-8 -*-
1
+ require File.expand_path('../lib/payone_connect/version', __FILE__)
5
2
 
6
3
  Gem::Specification.new do |s|
7
4
  s.name = %q{payone_connect}
8
- s.version = "0.1.2"
5
+ s.version = "0.2.0"
9
6
 
10
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Patrick Huesler"]
12
- s.date = %q{2010-02-18}
8
+ s.authors = ["Patrick Huesler", "Alexander Lang", "Jan Raasch", "Christoph Hugo"]
9
+ s.date = %q{2009-10-04}
13
10
  s.description = %q{Connects to the payone gateway and passes the parameters}
14
11
  s.email = %q{patrick.huesler@gmail.com}
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- ".document",
21
- ".gitignore",
22
- "LICENSE",
23
- "README.rdoc",
24
- "Rakefile",
25
- "VERSION",
26
- "lib/payone_connect.rb",
27
- "lib/payone_connect/core_ext.rb",
28
- "payone_connect.gemspec",
29
- "spec/payone_connect_spec.rb",
30
- "spec/spec_helper.rb"
31
- ]
12
+ s.version = PayoneConnect::VERSION
32
13
  s.homepage = %q{http://github.com/phuesler/payone_connect}
33
- s.rdoc_options = ["--charset=UTF-8"]
34
14
  s.require_paths = ["lib"]
35
- s.rubygems_version = %q{1.3.5}
36
15
  s.summary = %q{Simple http client for the psp payone api (http://www.payone.de/)}
37
- s.test_files = [
38
- "spec/payone_connect_spec.rb",
39
- "spec/spec_helper.rb"
40
- ]
16
+ s.files = `git ls-files`.split($\)
17
+ s.test_files = s.files.grep(%r{^spec/})
41
18
 
42
- if s.respond_to? :specification_version then
43
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
44
- s.specification_version = 3
45
-
46
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
47
- s.add_development_dependency(%q<rspec>, [">= 0"])
48
- s.add_development_dependency(%q<fakeweb>, [">= 0"])
49
- else
50
- s.add_dependency(%q<rspec>, [">= 0"])
51
- s.add_dependency(%q<fakeweb>, [">= 0"])
52
- end
53
- else
54
- s.add_dependency(%q<rspec>, [">= 0"])
55
- s.add_dependency(%q<fakeweb>, [">= 0"])
56
- end
19
+ s.add_dependency 'activesupport'
20
+ s.add_development_dependency(%q<rspec>, ["~> 2.1"])
21
+ s.add_development_dependency(%q<fakeweb>, [">= 0"])
22
+ s.add_development_dependency(%q<rake>, [">= 0"])
57
23
  end
58
-
@@ -24,65 +24,81 @@ describe PayoneConnect do
24
24
  @finance_gate_connection = PayoneConnect.new("https://testapi.pay1.de/post-gateway/",@request_data)
25
25
  @uri = URI.parse("https://testapi.pay1.de/post-gateway/")
26
26
  end
27
-
27
+
28
28
  describe "connection" do
29
- it "should connect to the payone gateway" do
29
+ it "connects to the payone gateway" do
30
30
  https_connection = Net::HTTP.new(@uri.host, @uri.port)
31
- Net::HTTP.should_receive(:new).with(@uri.host,@uri.port).and_return(https_connection)
31
+
32
+ expect(Net::HTTP).to receive(:new).with(@uri.host,@uri.port) { https_connection }
33
+
32
34
  @finance_gate_connection.request
33
35
  end
34
-
35
- it "should set the x form header" do
36
- @finance_gate_connection.request_header.should == {'Content-Type'=> 'application/x-www-form-urlencoded'}
36
+
37
+ it "sets the x form header" do
38
+ expect(@finance_gate_connection.request_header).to eql('Content-Type'=> 'application/x-www-form-urlencoded')
37
39
  end
38
40
  end
39
-
41
+
40
42
  describe "general parameter assignment" do
41
43
  %w(portalid mid mode key encoding request).each do |parameter|
42
- it "should set the #{parameter} parameter" do
43
- @finance_gate_connection.request_data.should include("#{parameter}=#{@request_data[parameter]}")
44
+ it "sets the #{parameter} parameter" do
45
+ expect(@finance_gate_connection.request_data).to include("#{parameter}=#{@request_data[parameter]}")
44
46
  end
45
47
  end
46
48
  end
47
-
49
+
48
50
  describe "successful request" do
49
51
  before(:each) do
50
52
  FakeWeb.register_uri(:post, "https://testapi.pay1.de/post-gateway/", :body => "status=APPROVED\ntxid=18059493\nuserid=4923401")
51
53
  end
52
-
53
- it "should return the status" do
54
- @finance_gate_connection.request[:status].should == "APPROVED"
54
+
55
+ it "returns the status" do
56
+ expect(@finance_gate_connection.request[:status]).to eql("APPROVED")
57
+ end
58
+
59
+ it "returns payone's transaction id" do
60
+ expect(@finance_gate_connection.request[:txid]).to eql("18059493")
61
+ end
62
+
63
+ it "returns payone's user id" do
64
+ expect(@finance_gate_connection.request[:userid]).to eql("4923401")
55
65
  end
56
-
57
- it "should return payones transaction id" do
58
- @finance_gate_connection.request[:txid].should == "18059493"
66
+
67
+ it 'ignores empty lines' do
68
+ FakeWeb.register_uri(:post, "https://testapi.pay1.de/post-gateway/", :body => "status=APPROVED\n\ntxid=18059493\nuserid=4923401")
69
+
70
+ expect(@finance_gate_connection.request[:userid]).to eql("4923401")
59
71
  end
60
-
61
- it "should return payones user id" do
62
- @finance_gate_connection.request[:userid].should == "4923401"
72
+
73
+ it 'parses empty values' do
74
+ FakeWeb.register_uri(:post, "https://testapi.pay1.de/post-gateway/", :body => "status=APPROVED\nmandate_identification=PO-11190784\nmandate_status=active\nmandate_text=\ncreditor_identifier=DE16ZZZ00000961533\niban=DE76460500010209043724\nbic=WELADED1SIE\n")
75
+
76
+ expect(@finance_gate_connection.request[:mandate_text]).to eql("")
77
+ expect(@finance_gate_connection.request[:mandate_identification]).to eql("PO-11190784")
63
78
  end
64
79
  end
65
-
80
+
66
81
  describe "response is redirect" do
67
- it "should parse the redirect url correctly" do
82
+ it "parses the redirect url correctly" do
68
83
  FakeWeb.register_uri(:post, "https://testapi.pay1.de/post-gateway/", :body => "status=REDIRECT\ntxid=18059493\nuserid=4923401\nredirecturl=https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=ABC&useraction=commit")
69
- @finance_gate_connection.request[:redirecturl].should == "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=ABC&useraction=commit"
84
+
85
+ expect(@finance_gate_connection.request[:redirecturl]).to eql("https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=ABC&useraction=commit")
70
86
  end
71
87
  end
72
-
88
+
73
89
  describe "authorization parameter assignment" do
74
90
  %w(aid reference currency amount clearingtype).each do |parameter|
75
- it "should set the #{parameter} parameter" do
76
- @finance_gate_connection.request_data.should include("#{parameter}=#{@request_data[parameter]}")
91
+ it "sets the #{parameter} parameter" do
92
+ expect(@finance_gate_connection.request_data).to include("#{parameter}=#{@request_data[parameter]}")
77
93
  end
78
94
  end
79
95
  end
80
-
96
+
81
97
  describe "credit card payment parameter assignment" do
82
98
  %w(cardpan cardtype cardexpiredate cardcvc2 cardholder).each do |parameter|
83
- it "should set the #{parameter} parameter" do
84
- @finance_gate_connection.request_data.should include("#{parameter}=#{URI.encode(@request_data[parameter].to_s)}")
99
+ it "sets the #{parameter} parameter" do
100
+ expect(@finance_gate_connection.request_data).to include("#{parameter}=#{URI.encode_www_form_component(@request_data[parameter].to_s)}")
85
101
  end
86
102
  end
87
- end
88
- end
103
+ end
104
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,11 +1,5 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
3
  require 'payone_connect'
4
- require 'spec'
5
- require 'spec/autorun'
6
- require 'rubygems'
4
+ require 'rspec'
7
5
  require 'fake_web'
8
-
9
- Spec::Runner.configure do |config|
10
-
11
- end
metadata CHANGED
@@ -1,86 +1,117 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: payone_connect
3
- version: !ruby/object:Gem::Version
4
- version: 0.1.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
5
  platform: ruby
6
- authors:
6
+ authors:
7
7
  - Patrick Huesler
8
+ - Alexander Lang
9
+ - Jan Raasch
10
+ - Christoph Hugo
8
11
  autorequire:
9
12
  bindir: bin
10
13
  cert_chain: []
11
-
12
- date: 2010-02-18 00:00:00 +01:00
13
- default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
14
+ date: 2009-10-04 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: activesupport
18
+ requirement: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
16
31
  name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - "~>"
35
+ - !ruby/object:Gem::Version
36
+ version: '2.1'
17
37
  type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: "0"
24
- version:
25
- - !ruby/object:Gem::Dependency
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '2.1'
44
+ - !ruby/object:Gem::Dependency
26
45
  name: fakeweb
46
+ requirement: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
27
51
  type: :development
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
30
- requirements:
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ - !ruby/object:Gem::Dependency
59
+ name: rake
60
+ requirement: !ruby/object:Gem::Requirement
61
+ requirements:
31
62
  - - ">="
32
- - !ruby/object:Gem::Version
33
- version: "0"
34
- version:
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ type: :development
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
35
72
  description: Connects to the payone gateway and passes the parameters
36
73
  email: patrick.huesler@gmail.com
37
74
  executables: []
38
-
39
75
  extensions: []
40
-
41
- extra_rdoc_files:
42
- - LICENSE
43
- - README.rdoc
44
- files:
45
- - .document
46
- - .gitignore
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".document"
79
+ - ".gitignore"
80
+ - ".travis.yml"
81
+ - CHANGELOG
82
+ - Gemfile
83
+ - Gemfile.lock
47
84
  - LICENSE
48
85
  - README.rdoc
49
86
  - Rakefile
50
- - VERSION
51
87
  - lib/payone_connect.rb
52
- - lib/payone_connect/core_ext.rb
88
+ - lib/payone_connect/version.rb
53
89
  - payone_connect.gemspec
54
90
  - spec/payone_connect_spec.rb
55
91
  - spec/spec_helper.rb
56
- has_rdoc: true
57
92
  homepage: http://github.com/phuesler/payone_connect
58
93
  licenses: []
59
-
94
+ metadata: {}
60
95
  post_install_message:
61
- rdoc_options:
62
- - --charset=UTF-8
63
- require_paths:
96
+ rdoc_options: []
97
+ require_paths:
64
98
  - lib
65
- required_ruby_version: !ruby/object:Gem::Requirement
66
- requirements:
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
67
101
  - - ">="
68
- - !ruby/object:Gem::Version
69
- version: "0"
70
- version:
71
- required_rubygems_version: !ruby/object:Gem::Requirement
72
- requirements:
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
73
106
  - - ">="
74
- - !ruby/object:Gem::Version
75
- version: "0"
76
- version:
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
77
109
  requirements: []
78
-
79
110
  rubyforge_project:
80
- rubygems_version: 1.3.5
111
+ rubygems_version: 2.2.2
81
112
  signing_key:
82
- specification_version: 3
113
+ specification_version: 4
83
114
  summary: Simple http client for the psp payone api (http://www.payone.de/)
84
- test_files:
115
+ test_files:
85
116
  - spec/payone_connect_spec.rb
86
117
  - spec/spec_helper.rb
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.1.2
@@ -1,76 +0,0 @@
1
- class Hash
2
- # Return a new hash with all keys converted to strings.
3
- def stringify_keys
4
- inject({}) do |options, (key, value)|
5
- options[key.to_s] = value
6
- options
7
- end
8
- end
9
-
10
- # Destructively convert all keys to strings.
11
- def stringify_keys!
12
- keys.each do |key|
13
- self[key.to_s] = delete(key)
14
- end
15
- self
16
- end
17
- end
18
-
19
- class Object
20
- # An object is blank if it's false, empty, or a whitespace string.
21
- # For example, "", " ", +nil+, [], and {} are blank.
22
- #
23
- # This simplifies
24
- #
25
- # if !address.nil? && !address.empty?
26
- #
27
- # to
28
- #
29
- # if !address.blank?
30
- def blank?
31
- respond_to?(:empty?) ? empty? : !self
32
- end
33
-
34
- # An object is present if it's not blank.
35
- def present?
36
- !blank?
37
- end
38
- end
39
-
40
- class NilClass #:nodoc:
41
- def blank?
42
- true
43
- end
44
- end
45
-
46
- class FalseClass #:nodoc:
47
- def blank?
48
- true
49
- end
50
- end
51
-
52
- class TrueClass #:nodoc:
53
- def blank?
54
- false
55
- end
56
- end
57
-
58
- class Array #:nodoc:
59
- alias_method :blank?, :empty?
60
- end
61
-
62
- class Hash #:nodoc:
63
- alias_method :blank?, :empty?
64
- end
65
-
66
- class String #:nodoc:
67
- def blank?
68
- self !~ /\S/
69
- end
70
- end
71
-
72
- class Numeric #:nodoc:
73
- def blank?
74
- false
75
- end
76
- end