widgeo 0.0.3 → 0.0.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e846be8a47e0a351ffd5d668240e57946c83177d
4
- data.tar.gz: 618ac392fcae389f28b00fe87008071dda72ef08
2
+ SHA256:
3
+ metadata.gz: 75b0f3149f3e737c6196fcef3d49c3c006c64ba09efeb2ee1470957339d45fdf
4
+ data.tar.gz: 0c5d3ecd23769a697ff07317b39e758ddd27b8beff2bd5f1f3224f2e9619a065
5
5
  SHA512:
6
- metadata.gz: f26d6769ed5a683efb39901c9ff84f2194b8f65054c04c6cdb79d646ed65a283774523979ce2404273bdab14726954873b61544549b03cf074302acdc8cf82ea
7
- data.tar.gz: c28b788e703b6f43c9e1a0df117c8f2dfcdf0b20793154cd35bd2152d67d1064f6f58f73c26f4d695b09fe6248e06d2266db369ac74c37951f422f4e9bacdf77
6
+ metadata.gz: a8381e432e2c16b88b37c974039fe9cac523ecf79e2ca853be975cae6296a394e798ab0d6ef25de450119c7ce8fe619e6b3e1492969095a2b27d66814e0a6bf9
7
+ data.tar.gz: d83b75e37671765a5c32c49cda425ee794598a7655ec99dcefcc4a23024ce8f2eb0e3f4a41c9089a671e5348d3da6de8b69f93e0f09d8316c4dc122e885a9984
data/.rubocop.yml ADDED
@@ -0,0 +1,17 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.7
3
+ NewCops: enable
4
+ SuggestExtensions: false
5
+
6
+ Naming/VariableNumber:
7
+ AllowedIdentifiers:
8
+ - alpha_2
9
+ - continent_alpha_2
10
+
11
+ Metrics/BlockLength:
12
+ Max: 35
13
+ Exclude:
14
+ - "spec/**/*"
15
+
16
+ Gemspec/DevelopmentDependencies:
17
+ Enabled: false
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in widgeo.gemspec
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2015 Chris G
1
+ Copyright (c) 2015 Chris Garrett
2
2
 
3
3
  MIT License
4
4
 
data/Rakefile CHANGED
@@ -1,10 +1,10 @@
1
- require "rspec/core/rake_task"
2
- require "bundler/gem_tasks"
1
+ # frozen_string_literal: true
3
2
 
4
- RSpec::Core::RakeTask.new(:spec) do |task|
5
-
6
- task.rspec_opts = ["--color"]
3
+ require 'rspec/core/rake_task'
4
+ require 'bundler/gem_tasks'
7
5
 
6
+ RSpec::Core::RakeTask.new(:spec) do |task|
7
+ task.rspec_opts = ['--color']
8
8
  end
9
9
 
10
- task :default => :spec
10
+ task default: :spec
@@ -1,58 +1,43 @@
1
- module Widgeo
1
+ # frozen_string_literal: true
2
2
 
3
+ module Widgeo
4
+ # Methods for working with collection of entities
3
5
  module Collection
4
-
5
6
  # Set/Get the dataset file name
6
- def dataset_file file_name = nil
7
-
7
+ def dataset_file(file_name = nil)
8
8
  @dataset_file ||= file_name
9
-
10
9
  end
11
10
 
12
11
  # Return the dataset
13
12
  def dataset
14
-
15
13
  # Raise an exception if the dataset file has not been set on the class
16
14
  raise UndefinedDatasetError unless dataset_file
17
15
 
18
16
  @dataset ||= YAML.load_file(
19
- File.join(File.dirname(__FILE__), "../", "data", "#{dataset_file}.yml")
17
+ File.join(File.dirname(__FILE__), '../', 'data', "#{dataset_file}.yml")
20
18
  )
21
-
22
19
  end
23
20
 
24
21
  # Does the item match the requested attributes?
25
- def matches? item, attributes
26
-
27
- attributes.map { |attribute, value|
28
-
22
+ def matches?(item, attributes)
23
+ attributes.map do |attribute, value|
29
24
  item.send(attribute) == value
30
-
31
- }.flatten == [true]
32
-
25
+ end.flatten == [true]
33
26
  end
34
27
 
35
28
  # Filter the items by a combination of values
36
- def filter_by attributes
37
-
29
+ def filter_by(attributes)
38
30
  all.select { |item| matches? item, attributes }
39
-
40
31
  end
41
32
 
42
33
  # Find an item by an attribute
43
- def find_by attribute, value
44
-
34
+ def find_by(attribute, value)
45
35
  all.detect { |continent| continent.send(attribute) == value }
46
-
47
36
  end
48
37
 
49
38
  # Parse full list and memoize it
50
39
  def all
51
-
52
- @all ||= dataset.map { |item| self.new item }
53
-
40
+ @all ||= dataset.map { |item| new item }
54
41
  end
55
-
56
42
  end
57
-
58
43
  end
@@ -1,14 +1,13 @@
1
- module Widgeo
1
+ # frozen_string_literal: true
2
2
 
3
+ module Widgeo
4
+ # Working with continents
3
5
  class Continent
4
-
5
6
  extend Widgeo::Collection
6
7
  include Widgeo::Model
7
8
 
8
9
  attr_reader :name, :alpha_2
9
10
 
10
11
  dataset_file :continents
11
-
12
12
  end
13
-
14
13
  end
data/lib/widgeo/model.rb CHANGED
@@ -1,21 +1,16 @@
1
- module Widgeo
1
+ # frozen_string_literal: true
2
2
 
3
+ module Widgeo
4
+ # Work with an entity
3
5
  module Model
4
-
5
6
  # Set attributes on the instance
6
- def initialize properties
7
-
8
- properties.each { |name, value|
9
-
7
+ def initialize(properties)
8
+ properties.each do |name, value|
10
9
  # Raise an exception if we don't have a getter for the property
11
10
  raise UndefinedFieldError unless respond_to? name
12
11
 
13
- instance_variable_set("@#{name}", value)
14
-
15
- }
16
-
12
+ instance_variable_set(:"@#{name}", value)
13
+ end
17
14
  end
18
-
19
15
  end
20
-
21
16
  end
@@ -1,7 +1,8 @@
1
- module Widgeo
1
+ # frozen_string_literal: true
2
2
 
3
+ module Widgeo
4
+ # Working with territories
3
5
  class Territory
4
-
5
6
  extend Widgeo::Collection
6
7
  include Widgeo::Model
7
8
 
@@ -11,11 +12,7 @@ module Widgeo
11
12
 
12
13
  # Load an instance of the continent
13
14
  def continent
14
-
15
15
  Continent.find_by :alpha_2, continent_alpha_2
16
-
17
16
  end
18
-
19
17
  end
20
-
21
18
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Widgeo
2
- VERSION = "0.0.3"
4
+ VERSION = '0.0.4'
3
5
  end
data/lib/widgeo.rb CHANGED
@@ -1,14 +1,15 @@
1
- require "widgeo/version"
2
- require "widgeo/collection"
3
- require "widgeo/model"
4
- require "widgeo/continent"
5
- require "widgeo/territory"
1
+ # frozen_string_literal: true
6
2
 
7
- module Widgeo
3
+ require 'widgeo/version'
4
+ require 'widgeo/collection'
5
+ require 'widgeo/model'
6
+ require 'widgeo/continent'
7
+ require 'widgeo/territory'
8
8
 
9
- require "yaml"
9
+ # Provides territory and continent utilities for ruby
10
+ module Widgeo
11
+ require 'yaml'
10
12
 
11
13
  class UndefinedDatasetError < StandardError; end
12
14
  class UndefinedFieldError < StandardError; end
13
-
14
15
  end
data/spec/spec_helper.rb CHANGED
@@ -1 +1,3 @@
1
- require "widgeo"
1
+ # frozen_string_literal: true
2
+
3
+ require 'widgeo'
@@ -1,42 +1,36 @@
1
- require "spec_helper"
1
+ # frozen_string_literal: true
2
2
 
3
- describe Widgeo::Continent do
3
+ require 'spec_helper'
4
4
 
5
- CONTINENT_COUNT = 7
6
- INVALID_CONTINENT = { bad_field: "BAD FIELD" }
7
- CONTINENT_ALPHA = "EU"
8
- VALID_CONTINENT = { name: "Beatland", alpha_2: "BE" }
9
- CONTINENT_FIELDS = [:name, :alpha_2]
5
+ CONTINENT_COUNT = 7
6
+ INVALID_CONTINENT = { bad_field: 'BAD FIELD' }.freeze
7
+ CONTINENT_ALPHA = 'EU'
8
+ VALID_CONTINENT = { name: 'Beatland', alpha_2: 'BE' }.freeze
9
+ CONTINENT_FIELDS = %i[name alpha_2].freeze
10
10
 
11
+ describe Widgeo::Continent do
11
12
  subject { Widgeo::Continent.new VALID_CONTINENT }
12
13
 
13
- it { is_expected.to respond_to *CONTINENT_FIELDS }
14
-
15
- context "given an invalid dataset" do
16
-
17
- subject { -> { Widgeo::Continent.new INVALID_CONTINENT } }
18
-
19
- it { is_expected.to raise_error Widgeo::UndefinedFieldError }
14
+ it { is_expected.to respond_to(*CONTINENT_FIELDS) }
20
15
 
16
+ context 'given an invalid dataset' do
17
+ it 'raises UndefinedFieldError' do
18
+ expect { Widgeo::Continent.new INVALID_CONTINENT }.to raise_error Widgeo::UndefinedFieldError
19
+ end
21
20
  end
22
21
 
23
- describe ".find_by" do
24
-
22
+ describe '.find_by' do
25
23
  subject(:continent) { Widgeo::Continent.find_by :alpha_2, CONTINENT_ALPHA }
26
24
 
27
25
  it { expect(continent).to be_kind_of Widgeo::Continent }
28
26
  it { expect(continent.alpha_2).to eq CONTINENT_ALPHA }
29
-
30
27
  end
31
28
 
32
- describe ".all" do
33
-
29
+ describe '.all' do
34
30
  subject(:continents) { Widgeo::Continent.all }
35
31
 
36
32
  it { expect(continents).to be_kind_of Array }
37
33
  it { expect(continents.size).to be CONTINENT_COUNT }
38
34
  it { expect(continents.first).to be_kind_of Widgeo::Continent }
39
-
40
35
  end
41
-
42
36
  end
@@ -1,72 +1,62 @@
1
- require "spec_helper"
1
+ # frozen_string_literal: true
2
2
 
3
- describe Widgeo::Territory do
3
+ require 'spec_helper'
4
4
 
5
- TERRITORY_COUNT = 254
6
- INVALID_TERRITORY = { bad_field: "BAD FIELD" }
7
- TERRITORY_ALPHA = "GB"
8
- EU_TERRITORY_COUNT = 50
9
- PARENT_CONTINENT_ALPHA = "EU"
5
+ TERRITORY_COUNT = 254
6
+ INVALID_TERRITORY = { bad_field: 'BAD FIELD' }.freeze
7
+ TERRITORY_ALPHA = 'GB'
8
+ EU_TERRITORY_COUNT = 50
9
+ PARENT_CONTINENT_ALPHA = 'EU'
10
10
 
11
- VALID_TERRITORY = {
12
- name: "Beatland", long_name: "Peoples republic of Beatland",
13
- alpha_2: "BE", continent_alpha_2: "EU"
14
- }
11
+ VALID_TERRITORY = {
12
+ name: 'Beatland', long_name: 'Peoples republic of Beatland',
13
+ alpha_2: 'BE', continent_alpha_2: 'EU'
14
+ }.freeze
15
15
 
16
- TERRITORY_FIELDS = [:name, :long_name, :alpha_2, :continent_alpha_2]
16
+ TERRITORY_FIELDS = %i[name long_name alpha_2 continent_alpha_2].freeze
17
17
 
18
+ describe Widgeo::Territory do
18
19
  subject { Widgeo::Territory.new VALID_TERRITORY }
19
20
 
20
- it { is_expected.to respond_to *TERRITORY_FIELDS }
21
-
22
- context "given an invalid dataset" do
23
-
24
- subject { -> { Widgeo::Territory.new INVALID_TERRITORY } }
25
-
26
- it { is_expected.to raise_error Widgeo::UndefinedFieldError }
21
+ it { is_expected.to respond_to(*TERRITORY_FIELDS) }
27
22
 
23
+ context 'given an invalid dataset' do
24
+ it 'raises UndefinedFieldError' do
25
+ expect { Widgeo::Territory.new INVALID_TERRITORY }.to raise_error Widgeo::UndefinedFieldError
26
+ end
28
27
  end
29
28
 
30
- describe "#continent" do
31
-
32
- subject (:continent) {
29
+ describe '#continent' do
30
+ subject(:continent) do
33
31
  Widgeo::Territory.find_by(:alpha_2, TERRITORY_ALPHA).continent
34
- }
32
+ end
35
33
 
36
34
  it { expect(continent).to be_kind_of Widgeo::Continent }
37
35
  it { expect(continent.alpha_2).to eq PARENT_CONTINENT_ALPHA }
38
-
39
36
  end
40
37
 
41
- describe ".find_by" do
42
-
38
+ describe '.find_by' do
43
39
  subject(:territory) { Widgeo::Territory.find_by :alpha_2, TERRITORY_ALPHA }
44
40
 
45
41
  it { expect(territory).to be_kind_of Widgeo::Territory }
46
42
  it { expect(territory.alpha_2).to eq TERRITORY_ALPHA }
47
-
48
43
  end
49
44
 
50
- describe ".filter_by" do
51
-
52
- subject(:territories) {
45
+ describe '.filter_by' do
46
+ subject(:territories) do
53
47
  Widgeo::Territory.filter_by continent_alpha_2: PARENT_CONTINENT_ALPHA
54
- }
48
+ end
55
49
 
56
50
  it { expect(territories).to be_kind_of Array }
57
51
  it { expect(territories.size).to be EU_TERRITORY_COUNT }
58
52
  it { expect(territories.first).to be_kind_of Widgeo::Territory }
59
-
60
53
  end
61
54
 
62
- describe ".all" do
63
-
55
+ describe '.all' do
64
56
  subject(:territories) { Widgeo::Territory.all }
65
57
 
66
- it { expect(territories).to be_kind_of Array }
58
+ it { expect(territories).to be_a_kind_of(Array) }
67
59
  it { expect(territories.size).to be TERRITORY_COUNT }
68
60
  it { expect(territories.first).to be_kind_of Widgeo::Territory }
69
-
70
61
  end
71
-
72
62
  end
data/widgeo.gemspec CHANGED
@@ -1,27 +1,31 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'widgeo/version'
5
6
 
6
7
  Gem::Specification.new do |spec|
8
+ spec.required_ruby_version = '>= 2.7.0'
9
+ spec.name = 'widgeo'
10
+ spec.version = Widgeo::VERSION
11
+ spec.authors = ['Chris Garrett']
12
+ spec.email = ['chris@hyperlaunch.com']
13
+ spec.summary = 'Provides easy access to the worlds territories and their continents.'
14
+ spec.description = 'Listing and filtering of continents and territories. ' \
15
+ 'Includes short names, long names and alpha codes, ' \
16
+ 'following the ISO 3166 standard.'
7
17
 
8
- spec.name = "widgeo"
9
- spec.version = Widgeo::VERSION
10
- spec.authors = ["Chris G"]
11
- spec.email = ["chris@abstraktion.co.uk"]
12
- spec.summary = "Provides easy access to the worlds territories and their continents."
13
- spec.description = "Listing and filtering of continents and territories. Includes short names, long names and alpha codes, following the ISO 3166 standard."
14
- spec.homepage = "https://github.com/BeatrootApp/Widgeo"
15
- spec.license = "MIT"
16
-
17
- spec.files = `git ls-files -z`.split("\x0")
18
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
- spec.require_paths = ["lib"]
21
-
22
- spec.add_development_dependency "bundler", "~> 1.7"
23
- spec.add_development_dependency "rake", "~> 10.0"
18
+ spec.homepage = 'https://github.com/hyperlaunch/widgeo'
19
+ spec.license = 'MIT'
24
20
 
25
- spec.add_development_dependency "rspec", "~> 3.1"
21
+ spec.files = `git ls-files -z`.split("\x0")
22
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
23
+ spec.require_paths = ['lib']
26
24
 
25
+ spec.add_development_dependency 'bundler', '~> 2.0'
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
+ spec.add_development_dependency 'rspec', '~> 3.1'
28
+ spec.add_development_dependency 'rubocop', '~> 1.67'
29
+ spec.add_development_dependency 'ruby-lsp', '~> 0.20.1'
30
+ spec.metadata['rubygems_mfa_required'] = 'true'
27
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: widgeo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
- - Chris G
8
- autorequire:
7
+ - Chris Garrett
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-24 00:00:00.000000000 Z
11
+ date: 2024-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.7'
19
+ version: '2.0'
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
- version: '1.7'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,15 +52,44 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.67'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.67'
69
+ - !ruby/object:Gem::Dependency
70
+ name: ruby-lsp
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.20.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.20.1
55
83
  description: Listing and filtering of continents and territories. Includes short names,
56
84
  long names and alpha codes, following the ISO 3166 standard.
57
85
  email:
58
- - chris@abstraktion.co.uk
86
+ - chris@hyperlaunch.com
59
87
  executables: []
60
88
  extensions: []
61
89
  extra_rdoc_files: []
62
90
  files:
63
91
  - ".gitignore"
92
+ - ".rubocop.yml"
64
93
  - Gemfile
65
94
  - LICENSE.txt
66
95
  - README.md
@@ -77,11 +106,12 @@ files:
77
106
  - spec/widgeo/continent_spec.rb
78
107
  - spec/widgeo/territory_spec.rb
79
108
  - widgeo.gemspec
80
- homepage: https://github.com/BeatrootApp/Widgeo
109
+ homepage: https://github.com/hyperlaunch/widgeo
81
110
  licenses:
82
111
  - MIT
83
- metadata: {}
84
- post_install_message:
112
+ metadata:
113
+ rubygems_mfa_required: 'true'
114
+ post_install_message:
85
115
  rdoc_options: []
86
116
  require_paths:
87
117
  - lib
@@ -89,19 +119,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
89
119
  requirements:
90
120
  - - ">="
91
121
  - !ruby/object:Gem::Version
92
- version: '0'
122
+ version: 2.7.0
93
123
  required_rubygems_version: !ruby/object:Gem::Requirement
94
124
  requirements:
95
125
  - - ">="
96
126
  - !ruby/object:Gem::Version
97
127
  version: '0'
98
128
  requirements: []
99
- rubyforge_project:
100
- rubygems_version: 2.2.2
101
- signing_key:
129
+ rubygems_version: 3.5.16
130
+ signing_key:
102
131
  specification_version: 4
103
132
  summary: Provides easy access to the worlds territories and their continents.
104
- test_files:
105
- - spec/spec_helper.rb
106
- - spec/widgeo/continent_spec.rb
107
- - spec/widgeo/territory_spec.rb
133
+ test_files: []