gus-importer 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- NzUxYmU3Njg2MDlkNGM2YjllZDE0YzdlMjQyOGU1NmMzNzlkNzJhMA==
5
- data.tar.gz: !binary |-
6
- NjNiOTYxY2VmNmI4ODBmYTk4ZTFiYTZiYWZkNzU3MmJiM2ZhZjdiMA==
2
+ SHA1:
3
+ metadata.gz: 99378b1ae14c8a63100d52dcbc362171bc2237d9
4
+ data.tar.gz: 86a9c531072bb6572b523f5f1dfc5e24c4206998
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- ZWQ0YWNhODM1NThjMjdjNzY2YTQxOTg1YjlkYzMyODQ1NzE0ZjlkM2M2OTcw
10
- OWZlNzE1M2MwOTMwZGZhYTRmYzM5M2RmOTE3NGMwYTVkZmQwYWE5ZGViOWM1
11
- NDQwODNhYzk0YjJmMjY1MDViNGE1YzdiYTAzY2JmNTU4NTA3M2Q=
12
- data.tar.gz: !binary |-
13
- OWJiN2IxNjI3ZTg1ZmQzNmQ5ZDU0Yzg3NjkwNzFhMGMwYzA2OGU3YTk0MjA4
14
- MDc1OWQxMDZhNTcyNjQ1MTM5N2UwNDc2OGZiM2FhZDBiMTVhODcwZDllMzk1
15
- ODMzNGNmY2Q1YTkwMTM2YjNjN2UwNzY3OWNhODJmZDI4N2UyMTg=
6
+ metadata.gz: f69b2376bd0b3f7086ddd39392b94d5f2528e2b71cdc4b81e86a85bf0b51b693fcc69a9f0db0a221e366322e45faf82a33993a87f836465d1a1ef585ad800a2a
7
+ data.tar.gz: 7e2bb8a4bf5586d9d0a4692f62b4fb544a4b61daabf3a2c1ed9aba4db5e23d4af447f2eca138230c9e739512373cd287af253885fa54b8bb225a109471994b45
data/README.md CHANGED
@@ -19,16 +19,11 @@ Or install it yourself as:
19
19
  ## Usage
20
20
 
21
21
  ``` ruby
22
- Gus::Importer::ProvinceParser.parse(file) do |name, uuid|
23
- puts "#{name} => #{uuid}"
22
+ Gus::Importer::HashParser.parse(file) do |name, uuid|
23
+ => {:WOJ=>"30", :POW=>"27", :GMI=>"01", :RODZ_GMI=>"1", :SYM=>"0949336", :SYM_UL=>"20291", :CECHA=>"ul.", :NAZWA_1=>"Słowackiego", :NAZWA_2=>"Juliusza ", :STAN_NA=>"2014-02-14"}
24
24
  end
25
25
  ```
26
26
 
27
- ``` ruby
28
- Gus::Importer::StreetsParser.parse(file) do |street|
29
- puts "#{street.feature} #{street.second_name} #{street.name} => #{street.uuid}, #{street.city_uuid}"
30
- end
31
- ```
32
27
  ## Contributing
33
28
 
34
29
  1. Fork it ( http://github.com/<my-github-username>/gus-importer/fork )
@@ -1,19 +1,13 @@
1
1
  module Gus::Importer
2
2
 
3
3
  class Cli < Thor
4
- desc "province file", ""
5
- def province(file)
6
- Gus::Importer::ProvinceParser.parse(file) do |name, uuid|
7
- puts "#{name} => #{uuid}"
4
+ desc "parse file", ""
5
+ def parse(file)
6
+ Gus::Importer::HashParser.parse(file) do |object|
7
+ puts object.inspect
8
8
  end
9
9
  end
10
10
 
11
- desc "streets file", ""
12
- def streets(file)
13
- Gus::Importer::StreetsParser.parse(file) do |street|
14
- puts "#{street.feature} #{street.second_name} #{street.name} => #{street.uuid}, #{street.city_uuid}"
15
- end
16
- end
17
11
  end
18
12
 
19
13
  end
@@ -3,8 +3,7 @@ require "uri"
3
3
  require "tempfile"
4
4
  require "net/http"
5
5
  require "libxml"
6
- require "gus/importer/province"
7
- require "gus/importer/streets"
6
+ require "gus/importer/hash_parser"
8
7
  require "pry"
9
8
  module Gus
10
9
  module Importer
@@ -1,18 +1,18 @@
1
1
  module Gus::Importer
2
2
 
3
- class ProvinceParser
3
+ class HashParser
4
4
  include LibXML::XML::SaxParser::Callbacks
5
5
 
6
6
  def initialize(callback)
7
7
  @callback = callback
8
+ @hash = {}
8
9
  end
9
10
 
10
11
  def on_start_element(element, attributes)
11
12
  @current_tag = element.to_sym
12
13
 
13
14
  if @current_tag == :row
14
- @name = ""
15
- @uuid = ""
15
+ @hash = {}
16
16
  elsif @current_tag == :col
17
17
  @current_attr_name = attributes["name"].to_sym
18
18
  end
@@ -23,12 +23,9 @@ module Gus::Importer
23
23
  end
24
24
 
25
25
  def on_characters(chars)
26
- if @current_tag == :col
27
- if @current_attr_name == :SYM
28
- @uuid += chars
29
- elsif @current_attr_name == :NAZWA
30
- @name += chars
31
- end
26
+ if @current_tag == :col && !@current_attr_name.nil?
27
+ @hash[@current_attr_name] ||= ""
28
+ @hash[@current_attr_name] += chars
32
29
  end
33
30
  end
34
31
 
@@ -36,9 +33,8 @@ module Gus::Importer
36
33
  if element.to_sym == :row
37
34
  @current_tag = nil
38
35
 
39
- @callback.call(@name, @uuid)
40
- @name = ""
41
- @uuid = ""
36
+ @callback.call(@hash)
37
+ @hash = {}
42
38
  end
43
39
 
44
40
  if element.to_sym == :col
@@ -48,7 +44,7 @@ module Gus::Importer
48
44
 
49
45
  def self.parse(file_path, &block)
50
46
  parser = LibXML::XML::SaxParser.file(file_path)
51
- parser.callbacks = ProvinceParser.new(block)
47
+ parser.callbacks = HashParser.new(block)
52
48
  parser.parse
53
49
  end
54
50
 
@@ -1,5 +1,5 @@
1
1
  module Gus
2
2
  module Importer
3
- VERSION = "0.0.1"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,83 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gus-importer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - macbury@gmail.com
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-17 00:00:00.000000000 Z
11
+ date: 2014-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.5'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: libxml-ruby
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: thor
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: pry
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ! '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ! '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  description: Simple gem for extracting data from gus XML
@@ -88,7 +88,7 @@ executables:
88
88
  extensions: []
89
89
  extra_rdoc_files: []
90
90
  files:
91
- - .gitignore
91
+ - ".gitignore"
92
92
  - Gemfile
93
93
  - LICENSE.txt
94
94
  - README.md
@@ -97,8 +97,7 @@ files:
97
97
  - gus-importer.gemspec
98
98
  - lib/gus/cli.rb
99
99
  - lib/gus/importer.rb
100
- - lib/gus/importer/province.rb
101
- - lib/gus/importer/streets.rb
100
+ - lib/gus/importer/hash_parser.rb
102
101
  - lib/gus/importer/version.rb
103
102
  homepage: https://github.com/macbury/gus-importer
104
103
  licenses:
@@ -110,12 +109,12 @@ require_paths:
110
109
  - lib
111
110
  required_ruby_version: !ruby/object:Gem::Requirement
112
111
  requirements:
113
- - - ! '>='
112
+ - - ">="
114
113
  - !ruby/object:Gem::Version
115
114
  version: '0'
116
115
  required_rubygems_version: !ruby/object:Gem::Requirement
117
116
  requirements:
118
- - - ! '>='
117
+ - - ">="
119
118
  - !ruby/object:Gem::Version
120
119
  version: '0'
121
120
  requirements: []
@@ -1,85 +0,0 @@
1
- module Gus::Importer
2
-
3
- class StreetsParser
4
- include LibXML::XML::SaxParser::Callbacks
5
-
6
- def initialize(callback)
7
- @callback = callback
8
- @street = nil
9
- end
10
-
11
- def on_start_element(element, attributes)
12
- @current_tag = element.to_sym
13
-
14
- if @current_tag == :row
15
- @street = Street.new
16
- elsif @current_tag == :col
17
- @current_attr_name = attributes["name"].to_sym
18
- end
19
- end
20
-
21
- def on_cdata_block(cdata)
22
- #puts "on on_cdata_block element: #{cdata}"
23
- end
24
-
25
- def on_characters(chars)
26
- if @current_tag == :col
27
- if @current_attr_name == :CECHA
28
- @street.feature += chars
29
- elsif @current_attr_name == :SYM
30
- @street.city_uuid += chars
31
- elsif @current_attr_name == :SYM_UL
32
- @street.uuid += chars
33
- elsif @current_attr_name == :NAZWA_1
34
- @street.name += chars
35
- elsif @current_attr_name == :NAZWA_2
36
- @street.second_name += chars
37
- end
38
- end
39
- end
40
-
41
- def on_end_element(element)
42
- if element.to_sym == :row
43
- @current_tag = nil
44
-
45
- @callback.call(@street.get!)
46
- @street = nil
47
- end
48
-
49
- if element.to_sym == :col
50
- @current_attr_name = nil
51
- end
52
- end
53
-
54
- def self.parse(file_path, &block)
55
- parser = LibXML::XML::SaxParser.file(file_path)
56
- parser.callbacks = StreetsParser.new(block)
57
- parser.parse
58
- end
59
-
60
- end
61
-
62
- class Street
63
- attr_accessor :name, :uuid, :city_uuid, :feature, :second_name
64
-
65
- def initialize
66
- self.second_name = ""
67
- self.name = ""
68
- self.uuid = ""
69
- self.city_uuid = ""
70
- self.feature = ""
71
- end
72
-
73
- def get!
74
- self.second_name.strip!
75
- self.name.strip!
76
- self.uuid.strip!
77
- self.city_uuid.strip!
78
- self.feature.strip!
79
-
80
- self.uuid = self.uuid.to_i
81
- self.city_uuid = self.city_uuid.to_i
82
- self
83
- end
84
- end
85
- end