moscow_metro 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,16 @@
1
+ require "pathname"
2
+ require "yaml"
3
+
4
+ require_relative "moscow_metro/version"
5
+ require_relative "moscow_metro/record_from_yaml"
6
+
7
+ module MoscowMetro
8
+
9
+ class Error < StandardError; end
10
+
11
+ DB_DIR = Pathname.new(File.expand_path("../db", __FILE__))
12
+
13
+ end
14
+
15
+ require_relative "moscow_metro/line"
16
+ require_relative "moscow_metro/station"
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MoscowMetro
4
+ class Line < RecordFromYaml
5
+
6
+ COLUMNS = [:color, :name, :open_year, :uid]
7
+ RECORDS = YAML.load_file(DB_DIR.join("lines.yml"))
8
+ Record = Struct.new(*COLUMNS)
9
+
10
+ def self.all
11
+ RECORDS.map { |record_data| Record.new(*hash_values(COLUMNS, record_data)) }
12
+ end
13
+
14
+ def self.find_by_uid(uid)
15
+ all.find { |line| line.uid == uid }
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MoscowMetro
4
+ class RecordFromYaml
5
+
6
+ def self.first
7
+ all.first
8
+ end
9
+
10
+ def self.last
11
+ all.last
12
+ end
13
+
14
+ private
15
+
16
+ def self.hash_values(columns, hash)
17
+ columns.map(&:to_s).map { |column_name| hash[column_name] }
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MoscowMetro
4
+ class Station < RecordFromYaml
5
+
6
+ COLUMNS = [:coordinates, :latitude, :longitude, :name, :name_en, :name_uniq, :line_uid]
7
+ RECORDS = YAML.load_file(DB_DIR.join("stations.yml"))
8
+
9
+ Record = Struct.new(*COLUMNS) do
10
+ def coordinates
11
+ (latitude && longitude) ? [latitude, longitude] : []
12
+ end
13
+
14
+ def line
15
+ MoscowMetro::Line.find_by_uid(line_uid)
16
+ end
17
+ end
18
+
19
+ def self.all
20
+ RECORDS.map { |record_data| Record.new(*hash_values(COLUMNS, record_data)) }
21
+ end
22
+
23
+ def self.names
24
+ all.map(&:name).uniq
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ module MoscowMetro
2
+ VERSION = "0.1.6"
3
+ end
@@ -0,0 +1,28 @@
1
+ require_relative 'lib/moscow_metro/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "moscow_metro"
5
+ spec.version = MoscowMetro::VERSION
6
+
7
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
8
+
9
+ spec.authors = ["Sergey Pedan"]
10
+ spec.email = ["sergey.pedan@gmail.com"]
11
+
12
+ spec.summary = %q{Database of lines and stations of Moscow metro.}
13
+ spec.description = %q{Database of lines and stations of Moscow metro.}
14
+
15
+ spec.homepage = "https://github.com/sergeypedan/moscow-metro"
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://github.com/sergeypedan/moscow-metro"
18
+ spec.metadata["changelog_uri"] = "https://github.com/sergeypedan/moscow-metro/Changelog.md"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = "bin"
26
+ spec.executables = spec.files.grep(%r{^#{spec.bindir}/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: moscow_metro
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.6
5
+ platform: ruby
6
+ authors:
7
+ - Sergey Pedan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-12-12 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Database of lines and stations of Moscow metro.
14
+ email:
15
+ - sergey.pedan@gmail.com
16
+ executables:
17
+ - console
18
+ - setup
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - ".gitignore"
23
+ - ".rspec"
24
+ - ".travis.yml"
25
+ - Changelog.md
26
+ - Gemfile
27
+ - Gemfile.lock
28
+ - README.md
29
+ - Rakefile
30
+ - bin/console
31
+ - bin/setup
32
+ - lib/db/lines.yml
33
+ - lib/db/stations.yml
34
+ - lib/moscow_metro.rb
35
+ - lib/moscow_metro/line.rb
36
+ - lib/moscow_metro/record_from_yaml.rb
37
+ - lib/moscow_metro/station.rb
38
+ - lib/moscow_metro/version.rb
39
+ - moscow_metro.gemspec
40
+ homepage: https://github.com/sergeypedan/moscow-metro
41
+ licenses: []
42
+ metadata:
43
+ homepage_uri: https://github.com/sergeypedan/moscow-metro
44
+ source_code_uri: https://github.com/sergeypedan/moscow-metro
45
+ changelog_uri: https://github.com/sergeypedan/moscow-metro/Changelog.md
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 2.3.0
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubygems_version: 3.1.4
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: Database of lines and stations of Moscow metro.
65
+ test_files: []