moscow_metro 0.1.9 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,7 +5,6 @@ module MoscowMetro
5
5
 
6
6
  COLUMNS = [:color, :name, :name_en, :name_prepositional, :open_year, :uid]
7
7
  RECORDS = YAML.load_file(DB_DIR.join("lines.yml"))
8
- Record = Struct.new(*COLUMNS)
9
8
  UIDS = {
10
9
  mcd: %w[D1 D2 D3 D4 D5].freeze,
11
10
  mck: %w[14].freeze,
@@ -13,6 +12,12 @@ module MoscowMetro
13
12
  monorail: %w[13].freeze
14
13
  }
15
14
 
15
+ Record = Struct.new(*COLUMNS) do
16
+ def stations
17
+ MoscowMetro::Station.at_lines([uid])
18
+ end
19
+ end
20
+
16
21
  def self.all
17
22
  RECORDS.map { |record_data| Record.new(*hash_values(COLUMNS, record_data)) }
18
23
  end
@@ -8,7 +8,7 @@ module MoscowMetro
8
8
 
9
9
  Record = Struct.new(*COLUMNS) do
10
10
  def coordinates
11
- (latitude && longitude) ? [latitude, longitude] : []
11
+ [latitude, longitude] if (latitude && longitude)
12
12
  end
13
13
 
14
14
  def line
@@ -16,33 +16,48 @@ module MoscowMetro
16
16
  end
17
17
  end
18
18
 
19
- def self.all
20
- RECORDS.map { |record_data| Record.new(*hash_values(COLUMNS, record_data)) }
21
- end
19
+ class << self
22
20
 
23
- def self.names
24
- all.map(&:name).uniq
25
- end
21
+ def all
22
+ RECORDS.map { |record_data| to_record(record_data) }
23
+ end
26
24
 
27
- def self.at_lines(uids)
28
- all.select { |station| uids.include? station.line_uid }
29
- end
25
+ def first
26
+ to_record RECORDS.first
27
+ end
30
28
 
31
- def self.at_mcd
32
- at_lines Line::UIDS[:mck]
33
- end
29
+ def last
30
+ to_record RECORDS.last
31
+ end
34
32
 
35
- def self.at_mck
36
- at_lines Line::UIDS[:mck]
37
- end
33
+ def to_record(record_data)
34
+ Record.new(*hash_values(COLUMNS, record_data))
35
+ end
38
36
 
39
- def self.at_metro
40
- at_lines Line::UIDS[:metro]
41
- end
37
+ def names
38
+ all.map(&:name).uniq
39
+ end
42
40
 
43
- def self.at_monorail
44
- at_lines Line::UIDS[:monorail]
45
- end
41
+ def at_lines(uids)
42
+ all.select { |station| uids.include? station.line_uid }
43
+ end
44
+
45
+ def at_mcd
46
+ at_lines Line::UIDS[:mck]
47
+ end
48
+
49
+ def at_mck
50
+ at_lines Line::UIDS[:mck]
51
+ end
46
52
 
53
+ def at_metro
54
+ at_lines Line::UIDS[:metro]
55
+ end
56
+
57
+ def at_monorail
58
+ at_lines Line::UIDS[:monorail]
59
+ end
60
+
61
+ end
47
62
  end
48
63
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MoscowMetro
4
- VERSION = "0.1.9"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moscow_metro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Pedan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-14 00:00:00.000000000 Z
11
+ date: 2020-12-16 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Database of lines and stations metro & metro-like train transport of
14
14
  Moscow. Can be used as a database alongside a real database or as a source of data
@@ -30,6 +30,8 @@ files:
30
30
  - bin/console
31
31
  - bin/setup
32
32
  - lib/db/lines.yml
33
+ - lib/db/sources/data-en-2015-11-30.json
34
+ - lib/db/sources/data-ru-2020-10-26.json
33
35
  - lib/db/stations.yml
34
36
  - lib/moscow_metro.rb
35
37
  - lib/moscow_metro/line.rb
@@ -60,7 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
62
  - !ruby/object:Gem::Version
61
63
  version: '0'
62
64
  requirements: []
63
- rubygems_version: 3.1.4
65
+ rubygems_version: 3.2.0
64
66
  signing_key:
65
67
  specification_version: 4
66
68
  summary: Database of lines and stations metro & metro-like train transport of Moscow