companies-house 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,5 @@
1
+ v0.0.5. now sic_codes.sic_texts always returns array
2
+
1
3
  v0.0.4. cleaned up gem dependencies
2
4
 
3
5
  v0.0.3. can now set same_as, continuation_key, regression_key on name search request
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{companies-house}
5
- s.version = "0.0.4"
5
+ s.version = "0.0.5"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Rob McKinnon"]
@@ -1,4 +1,3 @@
1
- require 'rubygems'
2
1
  require 'net/http'
3
2
  require 'uri'
4
3
  require 'open-uri'
@@ -7,6 +6,7 @@ require 'digest/md5'
7
6
  require 'morph'
8
7
  require 'hpricot'
9
8
  require 'haml'
9
+ require 'yaml'
10
10
 
11
11
  require File.dirname(__FILE__) + '/companies_house/request'
12
12
  require File.dirname(__FILE__) + '/companies_house/exception'
@@ -14,7 +14,7 @@ require File.dirname(__FILE__) + '/companies_house/exception'
14
14
  $KCODE = 'UTF8' unless RUBY_VERSION >= "1.9"
15
15
 
16
16
  module CompaniesHouse
17
- VERSION = "0.0.4" unless defined? CompaniesHouse::VERSION
17
+ VERSION = "0.0.5" unless defined? CompaniesHouse::VERSION
18
18
 
19
19
  class << self
20
20
 
@@ -87,7 +87,20 @@ module CompaniesHouse
87
87
  if xml && xml.children.select(&:elem?).size > 0
88
88
  xml = xml.children.select(&:elem?).first.to_s
89
89
  hash = Hash.from_xml(xml)
90
- Morph.from_hash(hash, CompaniesHouse)
90
+ object = Morph.from_hash(hash, CompaniesHouse)
91
+ if object && object.class.name == 'CompaniesHouse::CompanyDetails'
92
+ if object.respond_to?(:sic_codes)
93
+ sic_codes = object.sic_codes
94
+ if sic_codes.respond_to?(:sic_text) && sic_codes.sic_text
95
+ sic_codes.morph(:sic_texts, [sic_codes.sic_text])
96
+ else
97
+ object.morph(:sic_codes, Morph.from_hash({:sic_codes => {'sic_texts' => []} }) )
98
+ end
99
+ else
100
+ object.morph(:sic_codes, Morph.from_hash({:sic_codes => {'sic_texts' => []} }) )
101
+ end
102
+ end
103
+ object
91
104
  else
92
105
  nil
93
106
  end
@@ -3,6 +3,11 @@ require File.dirname(__FILE__) + '/../spec_helper.rb'
3
3
  describe CompaniesHouse do
4
4
 
5
5
  describe 'when objectifying xml' do
6
+ it 'should return an instance of CompaniesHouse::CompanyDetails' do
7
+ xml = '<Body><company_details><company_name>£IBRA FINANCIAL SERVICES LIMITED</company_name></company_details></Body>'
8
+ object = CompaniesHouse.objectify xml
9
+ object.class.name.should == 'CompaniesHouse::CompanyDetails'
10
+ end
6
11
  describe 'and xml contains expanded unicode' do
7
12
  it 'should convert to utf8' do
8
13
  xml = '<Body><company_details><company_name>£IBRA FINANCIAL SERVICES LIMITED</company_name></company_details></Body>'
@@ -10,6 +15,27 @@ describe CompaniesHouse do
10
15
  object.company_name.should == "£IBRA FINANCIAL SERVICES LIMITED"
11
16
  end
12
17
  end
18
+ describe 'and xml contains single sic_text' do
19
+ it 'should convert to sic_code sic_texts' do
20
+ xml = '<Body><company_details><sic_codes><sic_text>9261 - Operate sports arenas &amp; stadiums</sic_text></sic_codes></company_details></Body>'
21
+
22
+ object = CompaniesHouse.objectify xml
23
+ object.sic_codes.sic_text.should == '9261 - Operate sports arenas & stadiums'
24
+ object.sic_codes.sic_texts.should == ['9261 - Operate sports arenas & stadiums']
25
+ end
26
+ end
27
+ describe 'and xml contains no sic_text' do
28
+ it 'should return empty sic_code sic_texts' do
29
+ xml = '<Body><company_details><sic_codes></sic_codes></company_details></Body>'
30
+ object = CompaniesHouse.objectify xml
31
+ object.sic_codes.sic_texts.should == []
32
+ end
33
+ it 'should return empty sic_code sic_texts again' do
34
+ xml = '<Body><company_details><sic_codes><sic_text></sic_text></sic_codes></company_details></Body>'
35
+ object = CompaniesHouse.objectify xml
36
+ object.sic_codes.sic_texts.should == []
37
+ end
38
+ end
13
39
  end
14
40
 
15
41
  describe 'when calling public methods' do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: companies-house
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Rob McKinnon