ekispert 0.0.1

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.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/.circleci/config.yml +48 -0
  3. data/.gitignore +14 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +110 -0
  6. data/.travis.yml +5 -0
  7. data/CODE_OF_CONDUCT.md +74 -0
  8. data/Gemfile +6 -0
  9. data/LICENSE.txt +21 -0
  10. data/README.md +118 -0
  11. data/Rakefile +6 -0
  12. data/bin/console +14 -0
  13. data/bin/setup +8 -0
  14. data/ekispert-sdk-ruby.gemspec +31 -0
  15. data/example/point_station.rb +20 -0
  16. data/example/search_course.rb +116 -0
  17. data/lib/ekispert.rb +43 -0
  18. data/lib/ekispert/client.rb +58 -0
  19. data/lib/ekispert/config.rb +30 -0
  20. data/lib/ekispert/course.rb +124 -0
  21. data/lib/ekispert/course/pass_status.rb +34 -0
  22. data/lib/ekispert/course/price.rb +71 -0
  23. data/lib/ekispert/course/route.rb +33 -0
  24. data/lib/ekispert/course/route/line.rb +86 -0
  25. data/lib/ekispert/course/route/line/arrival_state.rb +25 -0
  26. data/lib/ekispert/course/route/line/arrival_state/gate.rb +22 -0
  27. data/lib/ekispert/course/route/line/corporation.rb +22 -0
  28. data/lib/ekispert/course/route/line/departure_state.rb +25 -0
  29. data/lib/ekispert/course/route/line/departure_state/gate.rb +22 -0
  30. data/lib/ekispert/course/route/line/line_symbol.rb +22 -0
  31. data/lib/ekispert/course/route/line/stop.rb +30 -0
  32. data/lib/ekispert/course/route/line/stop/arrival_state.rb +28 -0
  33. data/lib/ekispert/course/route/line/stop/departure_state.rb +28 -0
  34. data/lib/ekispert/course/route/line/stop/point.rb +28 -0
  35. data/lib/ekispert/course/route/line/stop/point/prefecture.rb +26 -0
  36. data/lib/ekispert/course/route/line/stop/point/station.rb +30 -0
  37. data/lib/ekispert/course/route/point.rb +49 -0
  38. data/lib/ekispert/course/route/point/prefecture.rb +22 -0
  39. data/lib/ekispert/course/route/point/station.rb +34 -0
  40. data/lib/ekispert/data_version.rb +35 -0
  41. data/lib/ekispert/ekispert_base.rb +69 -0
  42. data/lib/ekispert/error.rb +29 -0
  43. data/lib/ekispert/information.rb +58 -0
  44. data/lib/ekispert/information/corporation.rb +20 -0
  45. data/lib/ekispert/information/exit.rb +24 -0
  46. data/lib/ekispert/information/line.rb +35 -0
  47. data/lib/ekispert/information/welfare_facilities.rb +24 -0
  48. data/lib/ekispert/point.rb +41 -0
  49. data/lib/ekispert/point/prefecture.rb +18 -0
  50. data/lib/ekispert/point/station.rb +65 -0
  51. data/lib/ekispert/point/station/gate_group.rb +14 -0
  52. data/lib/ekispert/point/station/gate_group/gate.rb +28 -0
  53. data/lib/ekispert/util.rb +11 -0
  54. data/lib/ekispert/version.rb +3 -0
  55. metadata +213 -0
@@ -0,0 +1,26 @@
1
+ module Ekispert
2
+ class Course < EkispertBase
3
+ class Route < EkispertBase
4
+ class Line < EkispertBase
5
+ class Stop < EkispertBase
6
+ class Point < EkispertBase
7
+ class Prefecture < EkispertBase
8
+ attr_accessor :name_list
9
+
10
+ def initialize(element)
11
+ @name_list = []
12
+ super(element)
13
+ end
14
+
15
+ def name
16
+ @name_list[0].text
17
+ end
18
+
19
+ class Name < EkispertBase; end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,30 @@
1
+ module Ekispert
2
+ class Course < EkispertBase
3
+ class Route < EkispertBase
4
+ class Line < EkispertBase
5
+ class Stop < EkispertBase
6
+ class Point < EkispertBase
7
+ class Station < EkispertBase
8
+ attr_accessor :name_list, :prefecture_list
9
+
10
+ def initialize(element)
11
+ @name_list = []
12
+ super(element)
13
+ end
14
+
15
+ def name
16
+ @name_list[0].text
17
+ end
18
+
19
+ def prefecture
20
+ @prefecture_list[0].name
21
+ end
22
+
23
+ class Name < EkispertBase; end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,49 @@
1
+ module Ekispert
2
+ class Course < EkispertBase
3
+ class Route < EkispertBase
4
+ class Point < EkispertBase
5
+ attr_accessor :station_list, :prefecture_list, :geo_point_list
6
+ attr_accessor :name_list
7
+
8
+ def initialize(element)
9
+ @station_list = []
10
+ @prefecture_list = []
11
+ @geo_point_list = []
12
+ @name_list = []
13
+ super(element)
14
+ set_station_instance_variables if station?
15
+ end
16
+
17
+ def station
18
+ @station_list[0]
19
+ end
20
+
21
+ def prefecture
22
+ @prefecture_list[0]
23
+ end
24
+
25
+ def geo_point
26
+ @geo_point_list[0]
27
+ end
28
+
29
+ def name
30
+ @name_list[0]&.text
31
+ end
32
+
33
+ def station?
34
+ station.instance_of?(Ekispert::Course::Route::Point::Station)
35
+ end
36
+
37
+ class GeoPoint < EkispertBase; end
38
+ class Name < EkispertBase; end
39
+
40
+ private
41
+
42
+ def set_station_instance_variables
43
+ station.prefecture_list = prefecture_list
44
+ station.geo_point_list = geo_point_list
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,22 @@
1
+ module Ekispert
2
+ class Course < EkispertBase
3
+ class Route < EkispertBase
4
+ class Point < EkispertBase
5
+ class Prefecture < EkispertBase
6
+ attr_accessor :name_list
7
+
8
+ def initialize(element)
9
+ @name_list = []
10
+ super(element)
11
+ end
12
+
13
+ def name
14
+ @name_list[0].text
15
+ end
16
+
17
+ class Name < EkispertBase; end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,34 @@
1
+ module Ekispert
2
+ class Course < EkispertBase
3
+ class Route < EkispertBase
4
+ class Point < EkispertBase
5
+ class Station < Point
6
+ attr_accessor :name_list, :yomi_list, :type_list
7
+
8
+ def initialize(element)
9
+ @name_list = []
10
+ @yomi_list = []
11
+ @type_list = []
12
+ super(element)
13
+ end
14
+
15
+ def name
16
+ @name_list[0].text
17
+ end
18
+
19
+ def yomi
20
+ @yomi_list[0].text
21
+ end
22
+
23
+ def type
24
+ @type_list[0].text
25
+ end
26
+
27
+ class Name < EkispertBase; end
28
+ class Yomi < EkispertBase; end
29
+ class Type < EkispertBase; end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,35 @@
1
+ module Ekispert
2
+ class DataVersion
3
+ extend Ekispert::Util
4
+ attr_accessor :version_list, :copyrights_list
5
+
6
+ def initialize
7
+ @version_list = []
8
+ @copyrights_list = []
9
+ end
10
+
11
+ def self.get
12
+ to_data_version(Ekispert::Client.get('dataversion'))
13
+ end
14
+
15
+ def self.to_data_version(elem_arr)
16
+ data_version = self.new
17
+ elem_arr.children.each do |element|
18
+ elem_name = element.name.to_sym
19
+ next unless self.constants.include?(elem_name)
20
+
21
+ # Ex. Ekispert::DataVersion::Version.new
22
+ sub_instance = self.const_get(elem_name).new(element)
23
+ class_list_name = "#{snakecase(elem_name)}_list"
24
+ # Ex. data_version.version_list << sub_instance
25
+ data_version.send(class_list_name) << sub_instance
26
+ end
27
+ data_version
28
+ end
29
+
30
+ private_class_method :to_data_version
31
+
32
+ class Version < EkispertBase; end
33
+ class Copyrights < EkispertBase; end
34
+ end
35
+ end
@@ -0,0 +1,69 @@
1
+ module Ekispert
2
+ class EkispertBase
3
+ include Ekispert::Util
4
+
5
+ # argument:
6
+ # element: XML element (parsed Nokogiri)
7
+ def initialize(element)
8
+ set_methods_from_attributes(element)
9
+ set_method_from_text(element)
10
+ update_class_list_variable(element)
11
+ end
12
+
13
+ private
14
+
15
+ # Ex. Station class
16
+ # XML: <Station code = '22828'>...</Station>
17
+ # element.attributes = {
18
+ # 'code' => #(Attr:0x3fe7b6a050a4 { name = 'code', value = '22828' })
19
+ # }
20
+ # result:
21
+ # Ekispert::Point::Station#code #=> '22828'
22
+ def set_methods_from_attributes(element)
23
+ return if element.attributes.size == 0
24
+
25
+ element.attributes.each do |name, attribute|
26
+ define_singleton_method(snakecase(name)) { attribute.value }
27
+ end
28
+ end
29
+
30
+ # Ex. Station::Name class
31
+ # XML: <Name>東京</Name>
32
+ # result:
33
+ # Ekispert::Point::Statio::Name#text #=> '東京'
34
+ # Ekispert::Point::Statio::Name#to_s #=> '東京'
35
+ def set_method_from_text(element)
36
+ child_elem = element.children[0]
37
+ return if child_elem&.element?
38
+
39
+ define_singleton_method(:text) { child_elem&.text || '' }
40
+ instance_eval { alias to_s text }
41
+ end
42
+
43
+ # Ex. Point class (When child elements Station and Prefecture)
44
+ # XML:
45
+ # <Point>
46
+ # <Station></Station>
47
+ # <Prefecture></Prefecture>
48
+ # </Point>
49
+ # result:
50
+ # before:
51
+ # Ekispert::Point#station_list #=> []
52
+ # Ekispert::Point#prefecture_list #=> []
53
+ # after:
54
+ # Ekispert::Point#station_list #=> [#<Ekispert::Point::Station @...>]
55
+ # Ekispert::Point#prefecture_list #=> [#<Ekispert::Point::Prefecture @...>]
56
+ def update_class_list_variable(element)
57
+ element.children.each do |child_elem|
58
+ elem_name = child_elem.name.to_sym
59
+ next unless self.class.constants.include?(elem_name)
60
+
61
+ # Ex. Ekispert::DataVersion.new(child_elem)
62
+ sub_instance = self.class.const_get(elem_name).new(child_elem)
63
+ class_list_name = "#{snakecase(elem_name)}_list"
64
+ # Ex. sub_instance.version_list << sub_instance
65
+ self.send(class_list_name) << sub_instance
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,29 @@
1
+ module Ekispert
2
+ class Error < StandardError
3
+ class ClientError < Error
4
+ def initialize(res)
5
+ @res = res
6
+ super(format_error_body)
7
+ end
8
+
9
+ private
10
+
11
+ def format_error_body
12
+ %(
13
+ status : #{@res.status}
14
+ URL : #{@res.env.url}
15
+ message : #{split_message(@res.body).join("\n")}
16
+ )
17
+ end
18
+
19
+ def split_message(res_body)
20
+ Nokogiri::XML(res_body).xpath('/ResultSet/Error/Message').map(&:text)
21
+ end
22
+ end
23
+ class InternalError < Error; end # 1
24
+ class BadRequest < ClientError; end # 400
25
+ class Forbidden < ClientError; end # 403
26
+ class NotFound < ClientError; end # 404
27
+ class ServerError < Error; end # 500..599
28
+ end
29
+ end
@@ -0,0 +1,58 @@
1
+ module Ekispert
2
+ class Information < EkispertBase
3
+ attr_accessor :line_list, :corporation_list, :welfare_facilities_list, :exit_list, :type_list
4
+
5
+ def initialize(element)
6
+ @line_list = []
7
+ @corporation_list = []
8
+ @welfare_facilities_list = []
9
+ @exit_list = []
10
+ @type_list = []
11
+ super(element)
12
+ relate_line_and_corporation
13
+ end
14
+
15
+ def relate_line_and_corporation
16
+ # Set Information::Line#corporation
17
+ @line_list.each do |line|
18
+ line.corporation = @corporation_list.find { |corp| corp.index == line.corporation_index }
19
+ end
20
+ # Set Information::Corporation#line_list
21
+ @corporation_list.each do |corp|
22
+ corp.line_list = @line_list.select { |line| corp.index == line.corporation_index }
23
+ end
24
+ end
25
+
26
+ def type
27
+ @type_list[0].text
28
+ end
29
+
30
+ def rail?
31
+ type == 'rail'
32
+ end
33
+
34
+ def nearrail?
35
+ type == 'nearrail'
36
+ end
37
+
38
+ def welfare?
39
+ type == 'welfare'
40
+ end
41
+
42
+ def exit?
43
+ type == 'exit'
44
+ end
45
+
46
+ def self.get(params={})
47
+ to_information(Ekispert::Client.get('station/info', params))
48
+ end
49
+
50
+ def self.to_information(elem_arr)
51
+ elem_arr.xpath('//Information').map { |elem| self.new(elem) if elem.children.size > 1 }.compact
52
+ end
53
+
54
+ private_class_method :to_information
55
+
56
+ class Type < EkispertBase; end
57
+ end
58
+ end
@@ -0,0 +1,20 @@
1
+ module Ekispert
2
+ class Information < EkispertBase
3
+ class Corporation < EkispertBase
4
+ attr_reader :name_list
5
+ attr_accessor :line_list
6
+
7
+ def initialize(element)
8
+ @name_list = []
9
+ @line_list = [] # Use Information#relate_line_and_corporation
10
+ super(element)
11
+ end
12
+
13
+ def name
14
+ @name_list[0].text
15
+ end
16
+
17
+ class Name < EkispertBase; end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,24 @@
1
+ module Ekispert
2
+ class Information < EkispertBase
3
+ class Exit < EkispertBase
4
+ attr_reader :name_list, :comment_list
5
+
6
+ def initialize(element)
7
+ @name_list = []
8
+ @comment_list = []
9
+ super(element)
10
+ end
11
+
12
+ def name
13
+ @name_list[0]&.text
14
+ end
15
+
16
+ def comment
17
+ @comment_list[0]&.text
18
+ end
19
+
20
+ class Name < EkispertBase; end
21
+ class Comment < EkispertBase; end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,35 @@
1
+ module Ekispert
2
+ class Information < EkispertBase
3
+ class Line < EkispertBase
4
+ attr_reader :name_list, :type_list, :color_list
5
+ attr_accessor :corporation
6
+
7
+ def initialize(element)
8
+ @name_list = []
9
+ @type_list = []
10
+ @color_list = []
11
+ super(element)
12
+ end
13
+
14
+ def name
15
+ @name_list[0].text
16
+ end
17
+
18
+ def type
19
+ @type_list[0].text
20
+ end
21
+
22
+ def type_detail
23
+ @type_list[0].respond_to?(:detail) ? @type_list[0].detail : nil
24
+ end
25
+
26
+ def color
27
+ @color_list[0].text
28
+ end
29
+
30
+ class Name < EkispertBase; end
31
+ class Type < EkispertBase; end
32
+ class Color < EkispertBase; end
33
+ end
34
+ end
35
+ end