widgeo 0.0.3 → 0.0.5

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: 63a37b579cad5a3a1c2e90e26e86c310e26432e20732ec4afc9cc6bf4883462c
4
+ data.tar.gz: 8548b87dab5711fca3ce31952ec1719fbb30c395130e9c16661adca9b5771ab9
5
5
  SHA512:
6
- metadata.gz: f26d6769ed5a683efb39901c9ff84f2194b8f65054c04c6cdb79d646ed65a283774523979ce2404273bdab14726954873b61544549b03cf074302acdc8cf82ea
7
- data.tar.gz: c28b788e703b6f43c9e1a0df117c8f2dfcdf0b20793154cd35bd2152d67d1064f6f58f73c26f4d695b09fe6248e06d2266db369ac74c37951f422f4e9bacdf77
6
+ metadata.gz: 1785e94284ff7a3b9d0b1cf247cc58629d574e8b2acf7cbb3c9149078755c29e320aba0495b47342aebf55ca5ea9aaaa69f1c8ff0612d5dec5bf77d14878f87d
7
+ data.tar.gz: 03dd90d254cdf24a58316aad4cd4b651e6cf834c9f2066ffd8dc0cc8f9e160a26087489ed5a4b52089b42b6357e33da226a5ab54730eaa858ee0ca9572e140b3
@@ -0,0 +1,8 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: "bundler"
4
+ directory: "/"
5
+ schedule:
6
+ interval: "weekly"
7
+ open-pull-requests-limit: 10
8
+ rebase-strategy: "auto"
@@ -0,0 +1,27 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+
13
+ steps:
14
+ - name: Checkout code
15
+ uses: actions/checkout@v4
16
+
17
+ - name: Set up Ruby
18
+ uses: ruby/setup-ruby@v1
19
+ with:
20
+ ruby-version: 3.3
21
+ bundler-cache: true
22
+
23
+ - name: Run Rubocop (lint)
24
+ run: bundle exec rubocop
25
+
26
+ - name: Run RSpec tests
27
+ run: bundle exec rspec
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,4 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in widgeo.gemspec
4
6
  gemspec
7
+
8
+ gem 'bundler', '~> 2.5', group: :development
9
+ gem 'rake', '~> 13.2', group: :development
10
+ gem 'rspec', '~> 3.13', group: :development
11
+ gem 'rubocop', '~> 1.75', group: :development
12
+ gem 'ruby-lsp', '~> 0.23.14', group: :development
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.5'
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,26 @@
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.metadata['rubygems_mfa_required'] = 'true'
27
26
  end
metadata CHANGED
@@ -1,66 +1,27 @@
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.5
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
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1.7'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1.7'
27
- - !ruby/object:Gem::Dependency
28
- name: rake
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '10.0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '10.0'
41
- - !ruby/object:Gem::Dependency
42
- name: rspec
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '3.1'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '3.1'
11
+ date: 2025-04-22 00:00:00.000000000 Z
12
+ dependencies: []
55
13
  description: Listing and filtering of continents and territories. Includes short names,
56
14
  long names and alpha codes, following the ISO 3166 standard.
57
15
  email:
58
- - chris@abstraktion.co.uk
16
+ - chris@hyperlaunch.com
59
17
  executables: []
60
18
  extensions: []
61
19
  extra_rdoc_files: []
62
20
  files:
21
+ - ".github/dependabot.yml"
22
+ - ".github/workflows/ci.yml"
63
23
  - ".gitignore"
24
+ - ".rubocop.yml"
64
25
  - Gemfile
65
26
  - LICENSE.txt
66
27
  - README.md
@@ -77,11 +38,12 @@ files:
77
38
  - spec/widgeo/continent_spec.rb
78
39
  - spec/widgeo/territory_spec.rb
79
40
  - widgeo.gemspec
80
- homepage: https://github.com/BeatrootApp/Widgeo
41
+ homepage: https://github.com/hyperlaunch/widgeo
81
42
  licenses:
82
43
  - MIT
83
- metadata: {}
84
- post_install_message:
44
+ metadata:
45
+ rubygems_mfa_required: 'true'
46
+ post_install_message:
85
47
  rdoc_options: []
86
48
  require_paths:
87
49
  - lib
@@ -89,19 +51,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
89
51
  requirements:
90
52
  - - ">="
91
53
  - !ruby/object:Gem::Version
92
- version: '0'
54
+ version: 2.7.0
93
55
  required_rubygems_version: !ruby/object:Gem::Requirement
94
56
  requirements:
95
57
  - - ">="
96
58
  - !ruby/object:Gem::Version
97
59
  version: '0'
98
60
  requirements: []
99
- rubyforge_project:
100
- rubygems_version: 2.2.2
101
- signing_key:
61
+ rubygems_version: 3.5.22
62
+ signing_key:
102
63
  specification_version: 4
103
64
  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
65
+ test_files: []